public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { GL2 gl = drawable.getGL().getGL2(); // gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); if (w <= (h * 3)) gl.glOrtho( -6.0, 6.0, -2.0 * ((float) h * 3) / (float) w, 2.0 * ((float) h * 3) / (float) w, 0.0, 10.0); else gl.glOrtho( -6.0 * (float) w / ((float) h * 3), // 6.0 * (float) w / ((float) h * 3), -2.0, 2.0, 0.0, 10.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { GL2 gl = gLDrawable.getGL().getGL2(); final float aspect = (float) width / (float) height; gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); final float fh = 0.5f; final float fw = fh * aspect; gl.glFrustumf(-fw, fw, -fh, fh, 1.0f, 1000.0f); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); }
@Override public void display(GLAutoDrawable gLDrawable) { final GL2 gl = gLDrawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glClear(GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); // rotate about the three axes gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f); gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f); gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f); // Draw A Quad gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left // Done Drawing The Quad gl.glEnd(); // increasing rotation for the next iteration rotateT += 0.2f; }
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { GL2 gl = drawable.getGL().getGL2(); // gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); if (w <= h) gl.glOrtho(-2.5, 2.5, -2.5 * (float) h / (float) w, 2.5 * (float) h / (float) w, -10.0, 10.0); else gl.glOrtho(-2.5 * (float) w / (float) h, 2.5 * (float) w / (float) h, -2.5, 2.5, -10.0, 10.0); gl.glMatrixMode(GL2.GL_MODELVIEW); }