@Override public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) { GL2 gl2 = arg0.getGL().getGL2(); gl2.glMatrixMode(GL2.GL_PROJECTION); gl2.glLoadIdentity(); // coordinate system origin at lower left with width and height same as the window GLU glu = new GLU(); glu.gluOrtho2D(0.0f, getWidth(), 0.0f, getHeight()); gl2.glMatrixMode(GL2.GL_MODELVIEW); gl2.glLoadIdentity(); gl2.glViewport(0, 0, getWidth(), getHeight()); controller.updateExtents(arg3 / 2, arg4 / 2); } }
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height0) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context int height = height0; if (height == 0) { height = 1; // prevent divide by zero } float aspect = (float) width / height; // 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(GLMatrixFunc.GL_PROJECTION); // choose projection matrix gl.glLoadIdentity(); // reset projection matrix glu.gluPerspective(45.0, aspect, 0.1, 100.0); // fovy, aspect, zNear, // zFar // Enable the model-view transform gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); // reset }
/** * Apply the camera to a GL context. * * @param gl GL context. */ public void apply(GL2 gl) { // 3D projection gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); // Perspective. glu.gluPerspective(35, ratio, 1, 1000); glu.gluLookAt(distance * sinZ, distance * -cosZ, height, // pos 0, 0, .5, // center 0, 0, 1 // up ); // Change back to model view matrix. gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); // Store the matrixes for reference. gl.glGetIntegerv(GL.GL_VIEWPORT, viewp, 0); gl.glGetDoublev(GLMatrixFunc.GL_MODELVIEW_MATRIX, modelview, 0); gl.glGetDoublev(GLMatrixFunc.GL_PROJECTION_MATRIX, projection, 0); }
@Override public void applyInternalTransform( DrawContext dc, boolean textureIdentityActive ) { GL2 gl = GLContext.getCurrent( ).getGL( ).getGL2( ); if ( !textureIdentityActive ) { gl.glMatrixMode( GL2.GL_TEXTURE ); gl.glLoadIdentity( ); } gl.glScaled( scaleX, scaleY, 1 ); }
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // clear // color // and depth // buffers gl.glLoadIdentity(); // reset the model-view matrix // ----- Your OpenGL rendering code here (Render a white triangle for // testing) ----- gl.glTranslatef(0.0f, 0.0f, -6.0f); // translate into the screen gl.glColor3f(r, g, b); gl.glBegin(GL.GL_TRIANGLES); // draw using triangles long delay = System.currentTimeMillis() - time; double angle = speed * delay * Math.PI / 2000; float c = (float) Math.cos(angle); float s = (float) Math.sin(angle); gl.glVertex3f(c, s, 0.0f); gl.glVertex3f(-s, c, 0.0f); gl.glVertex3f(-c, -s, 0.0f); gl.glEnd(); } @Override
/** * {@inheritDoc} * * @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable, * int, int, int, int) */ @Override public void reshape( final GLAutoDrawable drawable, final int arg1, final int arg2, final int arg3, final int arg4 ) { final GL2 gl = drawable.getGL().getGL2(); final float w = this.window.getDrawableSurface().getWidth(); final float h = this.window.getDrawableSurface().getHeight(); gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION ); gl.glLoadIdentity(); this.glu.gluPerspective( 50, (w / h), 0.01, 10 ); }
@Override public void init( final GLAutoDrawable drawable ) { final GL2 gl = drawable.getGL().getGL2(); gl.setSwapInterval( 1 ); gl.glEnable( GL.GL_DEPTH_TEST ); gl.glDepthFunc( GL.GL_LEQUAL ); gl.glShadeModel( GLLightingFunc.GL_SMOOTH ); gl.glHint( GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST ); // gl.glEnable( GL.GL_BLEND ); // gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA ); gl.glEnable( GL2GL3.GL_POLYGON_SMOOTH ); final float w = this.window.getDrawableSurface().getWidth(); final float h = this.window.getDrawableSurface().getHeight(); // Set the projection matrix (only done once - just here) gl.glMatrixMode( GLMatrixFunc.GL_PROJECTION ); gl.glLoadIdentity(); this.glu.gluPerspective( 50, (w / h), 0.01, 10 ); // Set the initial model matrix gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW ); gl.glLoadIdentity(); gl.glViewport( 0, 0, (int) w, (int) h ); /* viewport size in pixels */ }
/** * Main render method * * @param gl GL context */ public final void render(GL2 gl) { gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1, +1); gl.glColor4f(0f, 0f, 0f, .5f); // Fade background: gl.glBegin(GL2.GL_QUADS); gl.glVertex2f(0f, 0f); gl.glVertex2f(width, 0f); gl.glVertex2f(width, height); gl.glVertex2f(0f, height); gl.glEnd(); renderContents(gl); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); }
gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); glu.gluOrtho2D(0, width, 0, height); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); gl.glLoadIdentity();
gl.glDisable(GL.GL_DEPTH_TEST); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0f, 1f, 0f, StyleLibrary.SCALE, -1, 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity();
gl2.glLoadIdentity(); gl2.glLoadIdentity(); gl2.glOrtho(0, 0, view_width_, view_height_, 0.1, 100.0);
public static void applyTextureTransforms(final Texture texture, final int unit, final TextureStateRecord record, final ContextCapabilities caps) { final GL gl = GLContext.getCurrentGL(); final boolean needsReset = !record.units[unit].identityMatrix; // Should we apply the transform? final boolean doTrans = !texture.getTextureMatrix().isIdentity(); // Now do them. final JoglRendererRecord matRecord = (JoglRendererRecord) ContextManager.getCurrentContext() .getRendererRecord(); if (doTrans) { checkAndSetUnit(unit, record, caps); JoglRendererUtil.switchMode(matRecord, GL.GL_TEXTURE); record.tmp_matrixBuffer.rewind(); texture.getTextureMatrix().toDoubleBuffer(record.tmp_matrixBuffer, true); record.tmp_matrixBuffer.rewind(); gl.getGL2().glLoadMatrixd(record.tmp_matrixBuffer); record.units[unit].identityMatrix = false; } else if (needsReset) { checkAndSetUnit(unit, record, caps); JoglRendererUtil.switchMode(matRecord, GL.GL_TEXTURE); gl.getGL2().glLoadIdentity(); record.units[unit].identityMatrix = true; } // Switch back to the modelview matrix for further operations JoglRendererUtil.switchMode(matRecord, GLMatrixFunc.GL_MODELVIEW); }
@Override public void display(GLAutoDrawable glad) { GL2 gl = (GL2)glad.getGL(); gl.glBlendFunc(GL_SRC_ALPHA, blends[iBlend]); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); new GLU().gluOrtho2D(-width / 2 - 1, width / 2 + 1, -height/2 - 1, height/2 + 1); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glBindBuffer(GL_ARRAY_BUFFER, vbo[0]); if (useOpenGLContext) { queue.finish(); } else { //interleavedColorAndPositionsMem.map(queue, CLMem.MapFlags.Read); interleavedColorAndPositionsMem.read(queue, interleavedColorAndPositionsTemp, true); gl.glBufferSubData(GL_ARRAY_BUFFER, 0, (int)interleavedColorAndPositionsTemp.getValidBytes(), interleavedColorAndPositionsTemp.getByteBuffer()); //interleavedColorAndPositionsMem.unmap(queue, interleavedColorAndPositionsTemp); } gl.glClear(GL_COLOR_BUFFER_BIT); gl.glColor3f(1.0f, 1.0f, 1.0f); //gl.glEnableClientState(GL_VERTEX_ARRAY); //gl.glEnableClientState(GL_COLOR_ARRAY); //gl.glColorPointer(4, GL_UNSIGNED_BYTE, elementSize, gl.glInterleavedArrays(GL2.GL_C4UB_V2F, elementSize, 0); gl.glDrawArrays(GL_POINTS, 0, particlesCount); gl.glBindBuffer(GL_ARRAY_BUFFER, 0); if (!paused) updateKernelArgs(); }
stack.pushClientAttrib( gl, ( int ) GL2.GL_ALL_CLIENT_ATTRIB_BITS ); stack.pushTexture( gl ); gl.glLoadIdentity( ); stack.pushModelview( gl ); stack.pushProjection( gl );