Why is this not a square? Lwjgl

I have a LWJGL base window and am trying to draw a square using the glBegin(GL_QUADS) method. Square square = new Square(25, 25, 25) , this is what I call my square class by drawing a square ... but it's a rectangle. When I call it, I pass all 25 as parameters. the first two are the origin, and the last 25 are the length of the side, as shown below. What am I doing wrong to create a rectangle?

 public Square(float x,float y,float sl) { GL11.glColor3f(0.5F, 0.0F, 0.7F); glBegin(GL11.GL_QUADS); glVertex2f(x, y); glVertex2f(x, y+sl); glVertex2f(x+sl, y+sl); glVertex2f(x+sl, y); glEnd(); } 

Code of my view

  glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Resets any previous projection matrices glOrtho(0, 640, 0, 480, 1, -1); glMatrixMode(GL_MODELVIEW); 
+7
java square lwjgl
source share
1 answer

Using glOrtho(0, 640, 0, 480, 1, -1); Creates a non-square viewport. This means that the processed output will more than likely be skewed if your window is not the same size as your viewport (or at least the same aspect ratio).

Consider the following comparison:

spelling comparison

If your viewport is the same size as your window, it should remain square. I use JOGL , but in my resize function, I resize my viewport as the new size of my window.

Viewport as window size

 glcanvas.addGLEventListener(new GLEventListener() { @Override public void reshape(GLAutoDrawable glautodrawable, int x, int y, int width, int height) { GL2 gl = glautodrawable.getGL().getGL2(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Resets any previous projection matrices gl.glOrtho(0, width, 0, height, 1, -1); gl.glMatrixMode(GL2.GL_MODELVIEW); } ... Other methods } 
+8
source share

All Articles