why does this look like a rectangle?


import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;

public class Game {
      //variables
      static boolean finished = false;
      
      // set up the window
      static {
            try {
                  Window.create("HELLO WORLD",50,50,640,480,32,0,8,0); // create a window
            } catch (Exception e) { e.printStackTrace(); System.exit(0); }
      }
      
      public static void main(String argv[]) {
            try {
                  {
                        Keyboard.create(); // create the keyboard, must be after creation of the window, so keyboard can focus on the window
                        GL.glClearColor(0.0f,0.0f,0.0f,0.0f); // set clearing color,
                        GL.glMatrixMode(GL.GL_PROJECTION); // init viewing values
                        GL.glLoadIdentity(); // reset matrix
                        GL.glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,0.0f); // coordinate system 
                  }
            
                  while (!finished) {
                        render(); // and check for events
                        Window.update(); // update window state in order to handle close requests, moves and paints
                        Window.paint(); // paints the window, swaps buffers
                }
                Window.destroy();
                Keyboard.destroy();
          }
          catch (Exception exp) { exp.printStackTrace(); }
      }
      
      public static void render() {
            // handled events
            if (Window.isCloseRequested()) { // is the close button clicked
                  finished = true; // if yes break out of the rendering loop and exit
                  return;
            }
            Keyboard.poll(); // poll keyboard
            if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // is escape key pressed
                  finished = true; // if yes break out of the rendering loop and exit
                  return;
            }
            
            GL.glClear(GL.GL_COLOR_BUFFER_BIT); // clear the screen (color buffer)
            GL.glColor3f(0.0f,1.0f,0.0f); // color that the square will be
            GL.glBegin(GL.GL_POLYGON); // begin the square
            {
                  GL.glVertex3f(0.25f,0.25f,0.0f); // pt 1
                  GL.glVertex3f(0.75f,0.25f,0.0f); // pt 2
                  GL.glVertex3f(0.75f,0.75f,0.0f); // pt 3
                  GL.glVertex3f(0.25f,0.75f,0.0f); // pt 4
            }
            GL.glEnd(); // end the square
      }
}


this is my first lwjgl prog… i understand mostly how everything there works, which is why all it does it make a square. but when i run the program it looks like a rectangle? why is that?

thanks.

Try to give your square a little breathing room in the Z dimension. You need to replace

GL.glOrtho(0.0f,1.0f,0.0f,1.0f,0.0f,0.0f);

with something like
GL.glOrtho(0.0f,1.0f,0.0f,1.0f,-10.0f,10.0f);

If it helps, your clipping planes had cut your square into a rectangle.

  • elias

ok il try the ortho thing…

whats a clipping pane? ( i know what it is… but not lwjgl wise)

how do i adjust that?

thanks.

The coordinates used in the polygon drawing is relative the frustum specified by glOrtho. Which again is relative to the screen size itself.

So in short, (0.25, 0, 0.75) becomes (0.25640, 0, 0.75480). If you wan’t it to be square you should make ortho match the aspect ratio of the screen. I suggest: “GL.glOrtho(0.0f,640.0f, 0.0f,480.0f,-10.0f,10.0f);”. This way you can specifie the coordinates in screen space.

hi

ic what u mean. i thought it might have something to do with how the screen was setup, because i changed those values and the shape changed.

thank you for that explanation :smiley: