// in pixels. @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { System.out.println(x + " " + y + " " + width + " " + height); GL2 gl = drawable.getGL().getGL2(); // calculate the aspect ratio of window double aspect = 1.0 * width / height; // in OpenGL terms, we are changing the 'projection' // this will be explained later gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Use the GLU library to compute the new projection GLU glu = new GLU(); // We are wider than high! if (aspect >= 1) { System.out.println("Showing world " + (-aspect) + " to " + (aspect) + " -1 to 1"); glu.gluOrtho2D(-aspect, aspect, -1.0, 1.0); // left, right, top, bottom } else { System.out.println("Showing world from -1 to 1 " + (-1.0 / aspect) + " to " + (1.0 / aspect)); glu.gluOrtho2D(-1, 1, -1.0 / aspect, 1.0 / aspect); // left, right, top, bottom } }
// private void pickSquares(GL gl, int button, int state, int x, int y) private void pickSquares(GL2 gl) { int selectBuf[] = new int[BUFSIZE]; IntBuffer selectBuffer = IntBuffer.wrap(selectBuf); int hits; int viewport[] = new int[4]; // if (button != GLUT_LEFT_BUTTON || state != GLUT_DOWN) return; gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0); gl.glSelectBuffer(BUFSIZE, selectBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); /* create 5x5 pixel picking region near cursor location */ glu.gluPickMatrix( (double) pickPoint.x, (double) (viewport[3] - pickPoint.y), 5.0, 5.0, viewport, 0); glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0); drawSquares(gl, GL2.GL_SELECT); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glFlush(); hits = gl.glRenderMode(GL2.GL_RENDER); selectBuffer.get(selectBuf); processHits(hits, selectBuf); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); gl.glMatrixMode(GL2ES1.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0, 1, 0, 1); gl.glMatrixMode(GL2ES1.GL_MODELVIEW); gl.glLoadIdentity(); }
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(); glu.gluOrtho2D(0.0, 3.0, 0.0, 3.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
public void setOrthographicView(int w, int h) { gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0, w, 0.0, h); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public static void setup(GL2ES1 gl, int width, int height) { gl.glMatrixMode(GL2ES1.GL_PROJECTION); gl.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window GLU glu = new GLUgl2es1(); glu.gluOrtho2D(0.0f, width, 0.0f, height); gl.glMatrixMode(GL2ES1.GL_MODELVIEW); gl.glLoadIdentity(); gl.glViewport(0, 0, width, height); }
/** * Call-back handler for window re-size event. Also called when the drawable is first set to * visible. */ public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context graphicsManager.setGraphics(gl); // Set the view port (display area) to cover the entire window gl.glViewport(0, 0, width, height); // Setup perspective projection, with aspect ratio matches viewport gl.glMatrixMode(GL_PROJECTION); // choose projection matrix gl.glLoadIdentity(); // reset projection matrix glu.gluOrtho2D(0, realWidth, 0, realHeight); // Enable the model-view transform gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); // reset }
@Override public void init(GLAutoDrawable glAutoDrawable) { gl = glAutoDrawable.getGL().getGL2(); glu = new GLU(); glut = new GLUT(); gl.glClearColor(0.549f, 0.675f, 0.227f, 0.0f); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(left, right, bottom, top); gl.glViewport((int) bottom, (int) left, (int) top, (int) right); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glColor3f(.357f, .184f, .478f); maxFrames = 50 * ifsFiles.size() + 1000; base = gl.glGenLists(maxFrames); currentDrawList = base; ifsfile = "CS371/assignments/assignment02/tri.ifs"; loadifs(); }
public void draw() { // Clear GL state gl.glDisable(GL_LIGHTING); gl.glDisable(GL_DEPTH); gl.glMatrixMode(GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f); gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); gl.glPointSize(1.0f); // Set the viewport glu.gluOrtho2D(xMin, xMax, yMin, yMax); gl.glBegin(GL_POINTS); for (int x = (int) (xMin); x < xMax; x++) for (int y = (int) (yMin); y < yMax; y++) { gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b); gl.glVertex2d(x + 0.5, y + 0.5); } gl.glEnd(); // Restore state gl.glMatrixMode(GL_MODELVIEW); gl.glPopMatrix(); gl.glMatrixMode(GL_PROJECTION); gl.glPopMatrix(); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_DEPTH); }
public void display(GLAutoDrawable glDrawable) { GL gl = glDrawable.getGL(); // Store old matrices gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight()); // Store enabled state and disable lighting, texture mapping and the depth buffer gl.glPushAttrib(GL.GL_ENABLE_BIT); gl.glDisable(GL.GL_BLEND); gl.glDisable(GL.GL_LIGHTING); gl.glDisable(GL.GL_TEXTURE_2D); gl.glDisable(GL.GL_DEPTH_TEST); // Retrieve the current viewport and switch to orthographic mode IntBuffer viewPort = BufferUtil.newIntBuffer(4); gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort); glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0); // Render the text gl.glColor3f(1, 1, 1); int x = OFFSET; int maxx = 0; int y = OFFSET + CHAR_HEIGHT; if (keyboardEntries.size() > 0) { gl.glRasterPos2i(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS); maxx = Math.max( maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS)); y += OFFSET; x += INDENT; for (int i = 0; i < keyboardEntries.size(); i++) { gl.glRasterPos2f(x, y); String text = (String) keyboardEntries.get(i); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text); maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text)); y += OFFSET; } } if (mouseEntries.size() > 0) { x = maxx + OFFSET; y = OFFSET + CHAR_HEIGHT; gl.glRasterPos2i(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS); y += OFFSET; x += INDENT; for (int i = 0; i < mouseEntries.size(); i++) { gl.glRasterPos2f(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i)); y += OFFSET; } } // Restore enabled state gl.glPopAttrib(); // Restore old matrices gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); }