public int[] getViewPort() { int viewport[] = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewport, 0); return viewport; }
@Override public void glGetIntegerv(int pname, int[] params, int params_offset) { gl.glGetIntegerv(pname, params, params_offset); }
@Override public void glGetIntegerv(int pname, IntBuffer params) { gl.glGetIntegerv(pname, params); }
double wcoordFar[] = new double[4]; gl2.glGetIntegerv(GL.GL_VIEWPORT, viewPort, 0); gl2.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelViewMatrix, 0); gl2.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projectionMatrix, 0);
public static void glGetIntegerv( int pname, IntBuffer data) { gl().glGetIntegerv( pname, data); }
public static void glGetIntegerv( int pname, int[] data, int data_offset) { gl().glGetIntegerv( pname, data, data_offset); }
private static void beginBitmap(final GL2 gl, final int[] swapbytes, final int[] lsbfirst, final int[] rowlength, final int[] skiprows, final int[] skippixels, final int[] alignment) { gl.glGetIntegerv(GL2GL3.GL_UNPACK_SWAP_BYTES, swapbytes, 0); gl.glGetIntegerv(GL2GL3.GL_UNPACK_LSB_FIRST, lsbfirst, 0); gl.glGetIntegerv(GL2ES2.GL_UNPACK_ROW_LENGTH, rowlength, 0); gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_ROWS, skiprows, 0); gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_PIXELS, skippixels, 0); gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, alignment, 0); /* Little endian machines (DEC Alpha for example) could benefit from setting GL_UNPACK_LSB_FIRST to GL_TRUE instead of GL_FALSE, but this would require changing the generated bitmaps too. */ gl.glPixelStorei(GL2GL3.GL_UNPACK_SWAP_BYTES, GL.GL_FALSE); gl.glPixelStorei(GL2GL3.GL_UNPACK_LSB_FIRST, GL.GL_FALSE); gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, 0); gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, 0); gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, 0); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1); }
private boolean getPropertiesFromCurrentContext(JoglContext ctx, GL2 gl) { // FIXME: this is a heavily abridged set of the stuff in Canvas3D.c; // probably need to pull much more in int[] tmp = new int[1]; gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_UNITS, tmp, 0); ctx.setMaxTexCoordSets(tmp[0]); if (VirtualUniverse.mc.transparentOffScreen) { ctx.setAlphaClearValue(0.0f); } else { ctx.setAlphaClearValue(1.0f); } if (gl.isExtensionAvailable("GL_ARB_vertex_shader")) { gl.glGetIntegerv(GL2.GL_MAX_TEXTURE_COORDS_ARB, tmp, 0); ctx.setMaxTexCoordSets(tmp[0]); } return true; }
public Ray getCameraRay(int mx, int my, Ray rayOut) { FloatBuffer projection = BufferUtils.createFloatBuffer(16); FloatBuffer modelview = BufferUtils.createFloatBuffer(16); IntBuffer viewport = BufferUtils.createIntBuffer(16); gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projection); gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelview); gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport); FloatBuffer positionNear = BufferUtils.createFloatBuffer(3); FloatBuffer positionFar = BufferUtils.createFloatBuffer(3); glu.gluUnProject(mx, viewport.get(3) - my, 0f, modelview, projection, viewport, positionNear); glu.gluUnProject(mx, viewport.get(3) - my, 1f, modelview, projection, viewport, positionFar); rayOut.origin.set(positionNear.get(0), positionNear.get(1), positionNear.get(2)); rayOut.direction.set(positionFar.get(0)-rayOut.origin.x, positionFar.get(1)-rayOut.origin.y, positionFar.get(2)-rayOut.origin.z); return rayOut; }
public void get3DPointFrom2D(float mx, float my, float zPlane, Vector3 out) { FloatBuffer projection = BufferUtils.createFloatBuffer(16); FloatBuffer modelview = BufferUtils.createFloatBuffer(16); IntBuffer viewport = BufferUtils.createIntBuffer(16); gl.glGetFloatv(GL2.GL_PROJECTION_MATRIX, projection); gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelview); gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport); FloatBuffer positionNear = BufferUtils.createFloatBuffer(3); FloatBuffer positionFar = BufferUtils.createFloatBuffer(3); glu.gluUnProject(mx, viewport.get(3) - my, 0f, modelview, projection, viewport, positionNear); glu.gluUnProject(mx, viewport.get(3) - my, 1f, modelview, projection, viewport, positionFar); Vector3 v1 = new Vector3(positionNear.get(0), positionNear.get(1), positionNear.get(2)); Vector3 v2 = new Vector3(positionFar.get(0), positionFar.get(1), positionFar.get(2)); float t = (v1.y - zPlane) / (v1.y - v2.y); // so here are the desired (x, y) coordinates float fX = v1.x + (v2.x - v1.x) * t; float fZ = v1.z + (v2.z - v1.z) * t; out.x = fX; out.y = zPlane; out.z = fZ; }
protected void setupGLView() { int[] viewportDimensions = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewportDimensions, 0); int width = viewportDimensions[2]; int height = viewportDimensions[3]; // setup projection gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1, 1); // the MODELVIEW matrix will get adjusted later gl.glMatrixMode(GL.GL_TEXTURE); gl.glLoadIdentity(); }
@Override public void init(GLAutoDrawable drawable) { // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); GL2 gl = drawable.getGL().getGL2(); System.err.println("INIT GL IS: " + gl.getClass().getName()); // Enable VSync gl.setSwapInterval(1); // Setup the drawing area and shading mode gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0); gl.glClearColor(0.17f, 0.65f, 0.92f, 0.0f); // sky blue color gl.glEnable(GL.GL_DEPTH_TEST); int[] depth_bits = new int[1]; gl.glGetIntegerv(GL.GL_DEPTH_BITS, depth_bits, 0); gl.glShadeModel(GLLightingFunc.GL_SMOOTH); // try setting this to // GL_FLAT and see what // happens. addLight(gl); axisLabels.init(); float[] grayCol = { 0.8f, 0.8f, 0.8f, 1.0f }; gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, grayCol, 0); }
gl.glGetIntegerv(GL.GL_VIEWPORT, viewportview, 0); glu.gluProject((float) point.x, (float) point.y, (float) point.z, modelview, 0, projectionview, 0, viewportview, 0, objectPos, 0);
@Override public void init(GLAutoDrawable drawable) { // Use debug pipeline // drawable.setGL(new DebugGL(drawable.getGL())); GL2 gl = drawable.getGL().getGL2(); System.err.println("INIT GL IS: " + gl.getClass().getName()); // Enable VSync gl.setSwapInterval(1); // Setup the drawing area and shading mode gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); gl.glClearDepth(1.0); gl.glClearColor(0.17f, 0.65f, 0.92f, 0.0f); // sky blue color gl.glEnable(GL.GL_DEPTH_TEST); int[] depth_bits = new int[1]; gl.glGetIntegerv(GL.GL_DEPTH_BITS, depth_bits, 0); gl.glShadeModel(GLLightingFunc.GL_SMOOTH); // try setting this to // GL_FLAT and see what // happens. addLight(gl); float[] grayCol = { 0.8f, 0.8f, 0.8f, 1.0f }; // float[] blueCol = {0.0f, 0.0f, 0.8f, 1.0f}; gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, grayCol, 0); axisLabels.init(); }
public void setFrustrum(GL2 gl) { GLU glu = new GLU(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(viewBounds.minX, viewBounds.maxX, viewBounds.minY, viewBounds.maxY); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); // update matrices for mouse position calculation gl.glGetDoublev( GL2.GL_MODELVIEW_MATRIX, modelview,0); gl.glGetDoublev( GL2.GL_PROJECTION_MATRIX, projection,0); gl.glGetIntegerv( GL2.GL_VIEWPORT, viewport,0 ); }
gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);//Update viewport buffer
@Override protected void render3DScene(GL2 gl, GLU glu) { if (vizController.getVizConfig().isShowFPS()) { gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport); glu.gluOrtho2D(0, viewport.get(2), viewport.get(3), 0); gl.glDepthFunc(GL2.GL_ALWAYS); gl.glColor3i(192, 192, 192); gl.glRasterPos2f(10, 15); String fpsRound = String.valueOf((int) fps); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_10, fpsRound); gl.glDepthFunc(GL2.GL_LESS); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); } }
protected void setupGLView() { int[] viewportDimensions = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, viewportDimensions, 0); int width = viewportDimensions[2]; int height = viewportDimensions[3]; // setup projection gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, width, 0, height, -1, 1); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); gl.glLoadIdentity(); // do the transform from Graphics2D coords to openGL coords gl.glTranslatef(0, height, 0); gl.glScalef(1, -1, 1); gl.glMatrixMode(GL.GL_TEXTURE); gl.glLoadIdentity(); }
@Override protected void render3DScene(GL2 gl, GLU glu) { if (vizController.getVizConfig().isShowFPS()) { gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport); glu.gluOrtho2D(0, viewport.get(2), viewport.get(3), 0); gl.glDepthFunc(GL2.GL_ALWAYS); gl.glColor3i(192, 192, 192); gl.glRasterPos2f(10, 15 + (getGlobalScale() > 1f ? 8 : 0)); String fpsRound = String.valueOf((int) fps); if (getGlobalScale() > 1f) { glut.glutBitmapString(GLUT.BITMAP_HELVETICA_18, fpsRound); } else { glut.glutBitmapString(GLUT.BITMAP_HELVETICA_10, fpsRound); } gl.glDepthFunc(GL2.GL_LESS); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); } }
GL2 gl = (GL2) glAutoDrawable.getGL(); int[] viewport = new int[4]; gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport, 0); float height = this.size * h / viewport[3]; float width = this.size * w / viewport[2];