Search code examples
opengllwjglnifty-gui

How do I get Nifty GUI to use my coordinate system?


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?


Solution

  • 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.