Java Code Examples for com.jogamp.opengl.GL2#glTranslatef()
The following examples show how to use
com.jogamp.opengl.GL2#glTranslatef() .
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: CubeTexture.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); // Reset The View gl.glTranslatef(0f, 0f, -5.0f); gl.glRotatef(xrot, 1.0f, 1.0f, 1.0f); gl.glRotatef(yrot, 0.0f, 1.0f, 0.0f); gl.glRotatef(zrot, 0.0f, 0.0f, 1.0f); //drawImage(gl); this.drawBoxGridsTicksLabels(gl); drawImage(gl); gl.glFlush(); //change the speeds here xrot += .1f; yrot += .1f; zrot += .1f; }
Example 2
Source File: ArrowHead.java From depan with Apache License 2.0 | 6 votes |
/** * Draws an arrowhead on the given <code>GL</code> instantiation. The actual * shape depends on the Arrowhead object that is being drawn. * * @param gl Graphics object that will draw this object. */ @Override public void draw(GL2 gl) { gl.glPushMatrix(); float[] translate = GLScene.P(translateX, translateY); gl.glTranslatef(translate[0], translate[1], translate[2]); gl.glScalef(scaleX, scaleY, scaleZ); gl.glRotated(rotation * 180 / Math.PI, 0, 0, 1); gl.glBegin(GL2.GL_LINE_STRIP); GLPanel.V(gl, controlPoints[0].x, controlPoints[0].y); GLPanel.V(gl, controlPoints[1].x, controlPoints[1].y); GLPanel.V(gl, controlPoints[2].x, controlPoints[2].y); // check if there exists 4 points before drawing the 4th point if (controlPoints.length == 4) { GLPanel.V(gl, controlPoints[3].x, controlPoints[3].y); } GLPanel.V(gl, controlPoints[0].x, controlPoints[0].y); gl.glEnd(); gl.glPopMatrix(); }
Example 3
Source File: ArrowHead.java From depan with Apache License 2.0 | 6 votes |
/** * Draws and fills an arrowhead on the given <code>GL</code> instantiation. * The actual shape depends on the Arrowhead object that is being drawn. * * @param gl Graphics object that will draw this object. */ @Override public void fill(GL2 gl) { // points must be use with the correct order (2-3-0-1) to use triangle fan. gl.glPushMatrix(); float[] translate = GLScene.P(translateX, translateY); gl.glTranslatef(translate[0], translate[1], translate[2]); gl.glScalef(scaleX, scaleY, scaleZ); gl.glRotated(rotation * 180 / Math.PI, 0, 0, 1); gl.glBegin(GL2.GL_TRIANGLE_FAN); GLPanel.V(gl, controlPoints[2].x, controlPoints[2].y); // check if there exists 4 points before drawing the 4th point if (controlPoints.length == 4) { GLPanel.V(gl, controlPoints[3].x, controlPoints[3].y); } GLPanel.V(gl, controlPoints[0].x, controlPoints[0].y); GLPanel.V(gl, controlPoints[1].x, controlPoints[1].y); gl.glEnd(); gl.glPopMatrix(); }
Example 4
Source File: JPaddle.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0f, 0f, -2.0f); gl.glRotatef(rotation, 1f, 0f, 0f); gl.glColor3f(1f, 0f, 0f); gl.glBegin(GL2.GL_POLYGON); gl.glVertex3d(-0.5, 0.3, 0.8); gl.glVertex3d(0.5, 0.3, 0.8); gl.glVertex3d(0.8, 0.7, 0.8); gl.glVertex3d(-0.8, 0.7, 0.8); gl.glEnd(); int paddles = 40; for (int i = 0; i < paddles; i++) { gl.glRotated(360.0 / paddles, 1, 0, 0); gl.glBegin(GL2.GL_POLYGON); gl.glVertex3d(-0.5, 0.3, 0.8); gl.glVertex3d(0.5, 0.3, 0.8); gl.glVertex3d(0.8, 0.7, 0.8); gl.glVertex3d(-0.8, 0.7, 0.8); gl.glEnd(); } rotation -= 0.2f; }
Example 5
Source File: CubeSample2.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glLoadIdentity(); // 視点位置と視線方向 // glu.gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); // 図形の回転 gl.glTranslatef(0.5f, 0.5f, 0.5f); gl.glRotatef(r, 0.0f, 1.0f, 0.0f); gl.glTranslatef(-0.5f, -0.5f, -0.5f); // 図形の描画 gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glBegin(GL_LINES); for (int i = 0; i < 12; i++) { gl.glVertex3fv(vertex[edge[i][0]], 0); gl.glVertex3fv(vertex[edge[i][1]], 0); } gl.glEnd(); //一周回ったら回転角を 0 に戻す if (r++ >= 360.0f) r = 0; System.out.println("anim:" + animator.isAnimating() + ", r:" + r); if(willAnimatorPause) { animator.pause(); System.out.println("animoator paused:"); willAnimatorPause = false; } drawable.swapBuffers(); }
Example 6
Source File: J3DBasic.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glTranslatef(0f, 0f, -3f); gl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, 0); gl.glVertex3f(0f, 1f, 0); gl.glEnd(); //3D gl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, -2f); gl.glVertex3f(0f, 1f, -2f); gl.glEnd(); //top gl.glBegin(GL2.GL_LINES); gl.glVertex3f(-1f, 0f, 0); gl.glVertex3f(-1f, 0f, -2f); gl.glEnd(); //bottom gl.glBegin(GL2.GL_LINES); gl.glVertex3f(0f, 1f, 0); gl.glVertex3f(0f, 1f, -2f); gl.glEnd(); }
Example 7
Source File: Arrowheads.java From depan with Apache License 2.0 | 5 votes |
/** * Draws a triangular open arrow head on the given <code>GL</code> * instantiation. * * @param gl Graphics object that will draw this object. */ @Override public void draw(GL2 gl) { gl.glPushMatrix(); float[] translate = GLScene.P(translateX, translateY); gl.glTranslatef(translate[0], translate[1], translate[2]); gl.glScalef(scaleX, scaleY, scaleZ); gl.glRotated(rotation * 180 / Math.PI, 0, 0, 1); gl.glBegin(GL2.GL_LINE_STRIP); GLPanel.V(gl, controlPoints[1].x, controlPoints[1].y); GLPanel.V(gl, controlPoints[0].x, controlPoints[0].y); GLPanel.V(gl, controlPoints[2].x, controlPoints[2].y); gl.glEnd(); gl.glPopMatrix(); }
Example 8
Source File: DrawingPlugin.java From depan with Apache License 2.0 | 5 votes |
/** * Render a texture to the given position. * * @param texture Texture to draw * @param centerX X coordinate for the center of the texture * @param centerY Y coordinate for the center of the texture */ private void renderTexture(Texture texture, double centerX, double centerY) { TextureCoords tc = texture.getImageTexCoords(); float tx1 = tc.left(); float ty1 = tc.top(); float tx2 = tc.right(); float ty2 = tc.bottom(); float halfWidth = quarterValue(texture.getWidth()); float halfHeight = quarterValue(texture.getHeight()); GL2 gl = scene.gl; texture.bind(gl); texture.enable(gl); Color foreground = scene.getForegroundColor(); gl.glColor4f(foreground.getRed() / 255f, foreground.getGreen() / 255f, foreground.getBlue() / 255f, foreground.getAlpha() / 255f); gl.glPushMatrix(); float[] translate = GLScene.P((float) centerX, (float) centerY); gl.glTranslatef(translate[0], translate[1], translate[2]); gl.glBegin(GL2.GL_QUADS); // divided by 2 to get nicer textures // divided by 4 when we center it : 1/2 on each side of x axis for instance. gl.glTexCoord2f(tx1, ty1); GLScene.V(gl, -halfWidth, halfHeight); gl.glTexCoord2f(tx2, ty1); GLScene.V(gl, halfWidth, halfHeight); gl.glTexCoord2f(tx2, ty2); GLScene.V(gl, halfWidth, -halfHeight); gl.glTexCoord2f(tx1, ty2); GLScene.V(gl, -halfWidth, -halfHeight); gl.glEnd(); gl.glPopMatrix(); texture.disable(gl); }
Example 9
Source File: AWTShape.java From depan with Apache License 2.0 | 5 votes |
@Override public void draw(GL2 gl) { gl.glPushMatrix(); gl.glTranslatef(translateX, translateY, translateZ); gl.glScalef(scaleX, scaleY, scaleZ); draw(gl, shape); gl.glPopMatrix(); }
Example 10
Source File: AWTShape.java From depan with Apache License 2.0 | 5 votes |
@Override public void fill(GL2 gl) { gl.glPushMatrix(); gl.glTranslatef(translateX, translateY, translateZ); gl.glScalef(scaleX, scaleY, scaleZ); fill(gl, shape); gl.glPopMatrix(); }
Example 11
Source File: JCuboid.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0f, 0f, -5.0f); gl.glRotatef(rotation, 1.0f, 1.0f, 1.0f); gl.glBegin(GL2.GL_QUADS); gl.glColor3f(1f, 0f, 0f); //red color //Top gl.glVertex3f(-1f, 0.8f, 0.5f); gl.glVertex3f(-0.5f, 0.8f, 0.5f); gl.glVertex3f(-1f, 0.5f, 0.5f); gl.glVertex3f(-0.5f, 0.5f, 0.5f); //Bottom gl.glVertex3f(-1f, 0.8f, 0.9f); gl.glVertex3f(-1f, 0.5f, 0.9f); gl.glVertex3f(-0.5f, 0.5f, 0.9f); gl.glVertex3f(-0.5f, 0.8f, 0.9f); //Front gl.glVertex3f(-0.5f, 0.8f, 0.5f); gl.glVertex3f(-1f, 0.8f, 0.5f); gl.glVertex3f(-1f, 0.8f, 0.9f); gl.glVertex3f(-0.5f, 0.8f, 0.9f); //Back gl.glVertex3f(-0.5f, 0.5f, 0.5f); gl.glVertex3f(-1f, 0.5f, 0.5f); gl.glVertex3f(-1f, 0.5f, 0.9f); gl.glVertex3f(-0.5f, 0.5f, 0.9f); //Left gl.glVertex3f(-0.5f, 0.8f, 0.9f); gl.glVertex3f(-0.5f, 0.8f, 0.5f); gl.glVertex3f(-0.5f, 0.5f, 0.9f); gl.glVertex3f(-0.5f, 0.5f, 0.5f); //Right gl.glVertex3f(-1f, 0.8f, 0.9f); gl.glVertex3f(-1f, 0.8f, 0.5f); gl.glVertex3f(-1f, 0.5f, 0.5f); gl.glVertex3f(-1f, 0.5f, 0.9f); gl.glEnd(); gl.glFlush(); rotation -= 0.15f; }
Example 12
Source File: J3DCube.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0f, 0f, -2.0f); gl.glRotatef(rotation, 1.0f, 1.0f, 1.0f); gl.glBegin(GL2.GL_QUADS); gl.glColor3f(0f, 0f, 1f); //Blue color //Top Quadrilateral gl.glVertex3f(0.5f, 0.5f, -0.5f); //Upper Right gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Left gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Bottom Left gl.glVertex3f(0.5f, 0.5f, 0.5f); // Bottom Right //Below Quadrilateral gl.glColor3f(1f, 0f, 0f); //Red color gl.glVertex3f(0.5f, -0.5f, 0.5f); // Upper Right gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Upper Left gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Left gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Right //Front Quadrilateral gl.glColor3f(0f, 1f, 0f); //Green color gl.glVertex3f(0.5f, 0.5f, 0.5f); // Upper Right gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Upper Left gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Left gl.glVertex3f(0.5f, -0.5f, 0.5f); // Bottom Right //Back Quadrilateral gl.glColor3f(1f, 1f, 0f); //Yellow gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Left gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Right gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Right gl.glVertex3f(0.5f, 0.5f, -0.5f); // Upper Left //Left Quadrilateral gl.glColor3f(1f, 0f, 1f); //Purple gl.glVertex3f(-0.5f, 0.5f, 0.5f); // Upper Right gl.glVertex3f(-0.5f, 0.5f, -0.5f); // Upper Left gl.glVertex3f(-0.5f, -0.5f, -0.5f); // Bottom Left gl.glVertex3f(-0.5f, -0.5f, 0.5f); // Bottom Right //Right Quadrilateral gl.glColor3f(0f, 1f, 1f); //Cyan gl.glVertex3f(0.5f, 0.5f, -0.5f); // Upper Right gl.glVertex3f(0.5f, 0.5f, 0.5f); // Upper Left gl.glVertex3f(0.5f, -0.5f, 0.5f); // Bottom Left gl.glVertex3f(0.5f, -0.5f, -0.5f); // Bottom Right gl.glEnd(); gl.glFlush(); rotation += 0.6f; }
Example 13
Source File: J3DTriangle.java From MeteoInfo with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void display(GLAutoDrawable drawable) { final GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); // Move triangle gl.glTranslatef(-0.5f, 0.0f, -6.0f); gl.glRotatef(rotation, 0.0f, 1.0f, 0.0f); gl.glBegin(GL2.GL_TRIANGLES); // Front gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow gl.glVertex3f(1.5f, 2f, 0.0f); // Top Of Triangle gl.glColor3f(0.0f, 1.5f, 0.0f); // Green gl.glVertex3f(-1.5f, -1.5f, 1.5f); // Left Of Triangle gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple gl.glVertex3f(1.5f, -1.5f, 1.5f); // Right Of Triangle // Right gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple gl.glVertex3f(1.5f, -1.5f, 1.5f); // Left Of Triangle gl.glColor3f(0.0f, 1.0f, 0.0f); // Green gl.glVertex3f(1.5f, -1.5f, -1.5f); // Right Of Triangle // Back gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle gl.glColor3f(0.0f, 1.0f, 0.0f); // Green gl.glVertex3f(1.5f, -1.5f, -1.5f); // Left Of Triangle gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple gl.glVertex3f(-1.5f, -1.5f, -1.5f); // Right Of Triangle //left gl.glColor3f(1.0f, 1.0f, 0.0f); // Yellow gl.glVertex3f(1.5f, 2.0f, 0.0f); // Top Of Triangle gl.glColor3f(1.0f, 0.0f, 1.0f); // Purple gl.glVertex3f(-1.5f, -1.5f, -1.5f); // Left Of Triangle gl.glColor3f(0.0f, 1.0f, 0.0f); // Green gl.glVertex3f(-1.5f, -1.5f, 1.5f); // Right Of Triangle gl.glEnd(); gl.glFlush(); rotation += 0.6f; }
Example 14
Source File: JCudaDriverVolumeRendererJOGL.java From jcuda-samples with MIT License | 4 votes |
@Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // Use OpenGL to build view matrix float modelView[] = new float[16]; gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glRotatef(-simpleInteraction.getRotationDegX(), 1.0f, 0.0f, 0.0f); gl.glRotatef(-simpleInteraction.getRotationDegY(), 0.0f, 1.0f, 0.0f); gl.glTranslatef( -simpleInteraction.getTranslationX(), -simpleInteraction.getTranslationY(), -simpleInteraction.getTranslationZ()); gl.glGetFloatv(GL2.GL_MODELVIEW_MATRIX, modelView, 0); gl.glPopMatrix(); // Build the inverted view matrix invViewMatrix[0] = modelView[0]; invViewMatrix[1] = modelView[4]; invViewMatrix[2] = modelView[8]; invViewMatrix[3] = modelView[12]; invViewMatrix[4] = modelView[1]; invViewMatrix[5] = modelView[5]; invViewMatrix[6] = modelView[9]; invViewMatrix[7] = modelView[13]; invViewMatrix[8] = modelView[2]; invViewMatrix[9] = modelView[6]; invViewMatrix[10] = modelView[10]; invViewMatrix[11] = modelView[14]; // Copy the inverted view matrix to the global variable that // was obtained from the module. The inverted view matrix // will be used by the kernel during rendering. cuMemcpyHtoD(c_invViewMatrix, Pointer.to(invViewMatrix), invViewMatrix.length * Sizeof.FLOAT); // Render and fill the PBO with pixel data render(); // Draw the image from the PBO gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glDisable(GL.GL_DEPTH_TEST); gl.glRasterPos2i(0, 0); gl.glBindBuffer(GL2.GL_PIXEL_UNPACK_BUFFER, pbo); gl.glDrawPixels(width, height, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, 0); gl.glBindBuffer(GL2.GL_PIXEL_UNPACK_BUFFER, 0); // Update FPS information in main frame title step++; long currentTime = System.nanoTime(); if (prevTimeNS == -1) { prevTimeNS = currentTime; } long diff = currentTime - prevTimeNS; if (diff > 1e9) { double fps = (diff / 1e9) * step; String t = "JCuda 3D texture volume rendering sample - "; t += String.format("%.2f", fps)+" FPS"; frame.setTitle(t); prevTimeNS = currentTime; step = 0; } }