Search code examples
javaopenglrenderinglwjgl

LWJGL Quad rendering issues - an object that is meant to be a square is coming out as a rectangle


My problem is that I am rendering a quad with opengl. This code:

public void render() {
    System.out.println("Test");
    GL11.glPushMatrix();
    GL11.glTranslated(300,300,0);


    GL11.glColor3f(1f, 1f,1f);
    GL11.glRotatef(0, 0, 0, 1);
    GL11.glScalef(64, 64, 0);
    GL11.glBegin(GL11.GL_QUADS);
        GL11.glVertex2i(0, 0);
        GL11.glVertex2i(1, 0);
        GL11.glVertex2i(1,1);
        GL11.glVertex2i(0, 1);
    GL11.glEnd();

    GL11.glPopMatrix();
}

This should appear as a nice clean square as the size is 64x64, although it appears like this.

Whats odd about this I have drawn correctly an image behind it which is fine. I have stopped drawing this image/quad and it still causes the same problem. I cannot see any problem with the code above.

If this snippet of code comes in handy this is my OpenGl initialization code:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 720, 0, 1280, 1, -1);
    glMatrixMode(GL_MODELVIEW);

Just now I tested it in another lwjgl configuration and it had no effect.


Solution

  • That is aspect ratio problem.You should take care of this in your glOrtho() method.Here is what you need.Also check this and this one.More web search would do the trick without asking it here ;)

    Also,try gluOrtho instead.See this answer.