Java Code Examples for javax.media.opengl.GL2#glViewport()
The following examples show how to use
javax.media.opengl.GL2#glViewport() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Rhombus.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { // TODO Auto-generated method stub final GL2 gl = drawable.getGL().getGL2(); if (height <= 0) height = 1; final float h = (float) width / (float) height; gl.glViewport(3, 6, width, height); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); }
Example 2
Source File: JoglPanel.java From jbox2d with BSD 2-Clause "Simplified" License | 6 votes |
@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); }
Example 3
Source File: CefRenderer.java From pandomium with Apache License 2.0 | 5 votes |
@SuppressWarnings("static-access") protected void render(GL2 gl2) { if (use_draw_pixels_ || view_width_ == 0 || view_height_ == 0) { return; } assert (initialized_context_ != null); final float[] vertex_data = { //tu, tv, x, y, z 0.0f, 1.0f, -1.0f, -1.0f, 0.0f, 1.0f, 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f }; FloatBuffer vertices = FloatBuffer.wrap(vertex_data); gl2.glClear(gl2.GL_COLOR_BUFFER_BIT | gl2.GL_DEPTH_BUFFER_BIT); gl2.glMatrixMode(gl2.GL_MODELVIEW); gl2.glLoadIdentity(); // Match GL units to screen coordinates. gl2.glViewport(0, 0, view_width_, view_height_); gl2.glMatrixMode(gl2.GL_PROJECTION); gl2.glLoadIdentity(); // Draw the background gradient. gl2.glPushAttrib(gl2.GL_ALL_ATTRIB_BITS); gl2.glBegin(gl2.GL_QUADS); gl2.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); // red gl2.glVertex2f(-1.0f, -1.0f); gl2.glVertex2f(1.0f, -1.0f); gl2.glColor4f(0.0f, 0.0f, 1.0f, 1.0f); // blue gl2.glVertex2f(1.0f, 1.0f); gl2.glVertex2f(-1.0f, 1.0f); gl2.glEnd(); gl2.glPopAttrib(); // Rotate the view based on the mouse spin. if (spin_x_ != 0) { gl2.glRotatef(-spin_x_, 1.0f, 0.0f, 0.0f); } if (spin_y_ != 0) { gl2.glRotatef(-spin_y_, 0.0f, 1.0f, 0.0f); } if (transparent_) { // Alpha blending style. Texture values have premultiplied alpha. gl2.glBlendFunc(gl2.GL_ONE, gl2.GL_ONE_MINUS_SRC_ALPHA); // Enable alpha blending. gl2.glEnable(gl2.GL_BLEND); } // Enable 2D textures. gl2.glEnable(gl2.GL_TEXTURE_2D); // Draw the facets with the texture. assert (texture_id_[0] != 0); gl2.glBindTexture(gl2.GL_TEXTURE_2D, texture_id_[0]); gl2.glInterleavedArrays(gl2.GL_T2F_V3F, 0, vertices); gl2.glDrawArrays(gl2.GL_QUADS, 0, 4); // Disable 2D textures. gl2.glDisable(gl2.GL_TEXTURE_2D); if (transparent_) { // Disable alpha blending. gl2.glDisable(gl2.GL_BLEND); } }