PDA

View Full Version : Un-screwing screwed coordinates



_aVoX_
11-17-2012, 07:20 AM
Hello everybody!

I am currently developing a 2D OpenGL application using Java and an AWTGLCanvas from LWJGL embedded in a window. Everything seems to work perfectly except from the coordinates. While OpenGL coordinates normally look like this:
http://image-upload.de/get/y8eYYs/7489715261.jpg
The x axis seems to be mirrored, i.e.
http://image-upload.de/get/mAmXZr/5a51a8eb66.jpg

Now my question obviously is: Why?

The relevant code so far looks like this:


// Note: initGL is called by LWJGL when the canvas is created.
@Override
protected void initGL() {
GL11.glViewport(0, 0, getWidth(), getHeight());
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluOrtho2D(0, getWidth(), getHeight(), 0);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glLoadIdentity();
}

@Override
protected void paintGL() {
if (renewViewport) {
initGL();
renewViewport = false;
}

GL11.glLoadIdentity();

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);

// Note zoomAmount is within [1, 100] at all times, so negative scaling can't be the cause.
GL11.glScalef(zoomAmount, zoomAmount, 1);
GL11.glTranslatef(cameraPosition.x, cameraPosition.y, 0);

drawThis();
drawThat();

super.paintGL();
}


Thanks in advance.