Why isn't this a square? LWJGL

后端 未结 2 935
自闭症患者
自闭症患者 2021-01-12 09:54

I have a basic LWJGL window set up and I am trying to draw a square using the glBegin(GL_QUADS) method. Square square = new Square(25, 25, 25), is

2条回答
  •  独厮守ぢ
    2021-01-12 10:38

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

    Consider the following comparison:

    If your viewport is the same size as your window, then it should remain square. I'm using JOGL, but in my resize function, I reshape my viewport to be the new size of my window.

    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
    
    }
    

提交回复
热议问题