1

For various reasons, I like having openGL to use coordinates other than pixels, which is easily set via:

Display.setDisplayMode(new DisplayMode(800, 600));
GLU.gluOrtho2D(0f,32f,0f,24f);

However, now that I've begun trying to integrate Nifty GUI into my application, this corrdinate scale is causing problems. Namely, Nifty seems to think openGL is using pixels as units, and thus renders everything gigantic. Is there anyway to fix this?

zergylord
  • 4,368
  • 5
  • 38
  • 60

2 Answers2

2

Why not just do things the way NiftyGUI wants (pixel coordinates), but only while NiftyGUI is being rendered. This means:

gl.glMatrixMode(gl.GL_PROJECTION_MATRIX);
GLU.gluOrtho2D(0f,32f,0f,24f);
//Render my stuff
gl.glMatrixMode(gl.GL_PROJECTION_MATRIX);
gl.glLoadIdentity();
GLU.gluOrtho2D(0f,width,0f,height);
//Render with NiftyGUI.
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • That works, but then I encounter a different problem: I move the 'camera' around via glTranslate. The call to glLoadIdentity() makes it so this movement is never registered. I've tried surrounds the nifty gui rendering with push/pop matrix but this just breaks everything :-( – zergylord Nov 15 '12 at 22:15
  • @zergylord: That's a different question, so you should ask it with the "Ask a question" button. But if you do, be advised that you should provide appropriate source code to see what your matrix transform stuff is doing. – Nicol Bolas Nov 15 '12 at 22:17
1

You made the classic OpenGL newbie mistake: One time state setting.

OpenGL is not initialized. You re-set every state as you go and as you need it. Do in your case it's completely in order to set the projection matrix to a pixel mapping ortho projection whenever needed and to something else when using Nifty.

datenwolf
  • 159,371
  • 13
  • 185
  • 298