Display modes and resetting ortho

Started by Sardtok, May 07, 2006, 12:13:09

Previous topic - Next topic

Sardtok

Hey,
I tried to set up my method for switching display modes, but after changing display modes my sprites don't get sized up/down according to the mode.
I called initGL again after doing so, which runs a glOrtho on the projection matrix, but it still just seems to add space at the top and right side.
I fixed this by destroying the current display and creating a new one running initGL on that, then called a reloadTextures method I made in my texture loader,
and this works fine.
I was just wondering if there was an easier way around this, in case I ever get to making larger programs that contain lots of textures and possibly display lists and such.

I'm new to OpenGL and haven't coded much in a few years, so development is going ahead slowly, as I'm reading about how to do things both on NeHe and from the wiki tutorials here.
igg -- Take me off for great justice?

Sardtok

Ok, I found the solution to this, so if any other OpenGL noobs need to know here's how to do this:

GL11.glMatrixMode(GL11.GL_PROJECTION);  // Select The Projection Matrix
GL11.glLoadIdentity();                  // Reset The Projection Matrix

GL11.glViewport(0,0,Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); // Sets the viewport to get proper ortho display

GL11.glOrtho(0, 1024, 768, 0, -1.0, 1.0);   // Sets the screen to Ortho mode, top left being 0,0 bottom right 1024,768

GL11.glMatrixMode(GL11.GL_MODELVIEW);   // Select The Modelview Matrix


The thing I was missing from the code was the setting the Viewport prior to setting the ortho, and thus its right and top was the same points n pixels in the window...
As you can probably tell, I'm coding the game for 1024x768 display, but allowing the user to use any mode they like.
This thing worked wonder for the speed of my display change...
Not that reloading textures took very long, but destroying and creating the display took up to 5 seonds at the most I think (I think that's what the profiler reported anyway - maybe it was 5000 microseconds, but it sure seemed like it took more than a few milliseconds)...
Now it takes a lot less (when I can get the profiler attached again I'll do a new check to see what the speed is now)...

Well, learning OpenGL by trying things until you get it to work is fun, but can get you into some annoying problems, should probably get a book, but the game's not that big anyway... ;)
igg -- Take me off for great justice?