Java Code Examples for com.jogamp.opengl.GL2#glPushMatrix()
The following examples show how to use
com.jogamp.opengl.GL2#glPushMatrix() .
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: OpenGLGFXCMD.java From sagetv with Apache License 2.0 | 6 votes |
void drawString(String text, int x, int y, java.awt.Color color, GL2 gl, com.jogamp.opengl.util.awt.TextRenderer tr) { //System.out.println("drawString "+ text + " x: "+x+" y: "+y); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); //System.out.println("glOrtho(0,"+ c.getWidth() + ","+c.getHeight()+",0,-1.0,1.0)"); gl.glOrtho(0,c.getWidth(),0,c.getHeight(),-1.0,1.0); tr.begin3DRendering(); tr.setColor(color); tr.draw3D(text, x, c.getHeight()-y, 0, 1); tr.end3DRendering(); gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW); }
Example 2
Source File: PoseEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
/** * Render this physicalEntity into the view * @param gl2 */ public void render(GL2 gl2) { gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); // helpful info if(showBoundingBox.get()) cuboid.render(gl2); if(showLocalOrigin.get()) PrimitiveSolids.drawStar(gl2,10); if(showLineage.get()) renderLineage(gl2); // draw children relative to parent for(Entity e : children ) { if(e instanceof PoseEntity) { ((PoseEntity)e).render(gl2); } } gl2.glPopMatrix(); }
Example 3
Source File: Skycam.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
@Override public void render(GL2 gl2) { gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); Vector3d s = size.get(); Vector3d pos = getPosition(); Point3d bottom = new Point3d(pos.x-s.x/2,pos.y-s.y/2,pos.z); Point3d top = new Point3d(pos.x+s.x/2,pos.y+s.y/2,pos.z+s.z); PrimitiveSolids.drawBoxWireframe(gl2, bottom,top); Vector3d ep = ee.getPosition(); gl2.glBegin(GL2.GL_LINES); gl2.glVertex3d(ep.x,ep.y,ep.z); gl2.glVertex3d(bottom.x,bottom.y,top.z); gl2.glVertex3d(ep.x,ep.y,ep.z); gl2.glVertex3d(bottom.x,top .y,top.z); gl2.glVertex3d(ep.x,ep.y,ep.z); gl2.glVertex3d(top .x,top .y,top.z); gl2.glVertex3d(ep.x,ep.y,ep.z); gl2.glVertex3d(top .x,bottom.y,top.z); gl2.glEnd(); gl2.glPopMatrix(); super.render(gl2); }
Example 4
Source File: Cuboid.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
public void render(GL2 gl2) { gl2.glPushMatrix(); //MatrixHelper.applyMatrix(gl2, poseWorld); IntBuffer depthFunc = IntBuffer.allocate(1); gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc); gl2.glDepthFunc(GL2.GL_ALWAYS); boolean isLit = gl2.glIsEnabled(GL2.GL_LIGHTING); gl2.glDisable(GL2.GL_LIGHTING); gl2.glColor3d(255,255,255); PrimitiveSolids.drawBoxWireframe(gl2, getBoundsBottom(),getBoundsTop()); if (isLit) gl2.glEnable(GL2.GL_LIGHTING); gl2.glDepthFunc(depthFunc.get()); gl2.glPopMatrix(); }
Example 5
Source File: Robot_GMF_M100.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
@Override public void render(GL2 gl2) { gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, this.getPose()); // Draw models float r=1; float g=217f/255f; float b=33f/255f; MaterialEntity mat = new MaterialEntity(); mat.setDiffuseColor(r,g,b,1); mat.render(gl2); live.render(gl2); gl2.glPopMatrix(); super.render(gl2); }
Example 6
Source File: MatrixHelper.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
/** * See drawMatrix(gl2,p,u,v,w,1) * @param gl2 * @param m * @param scale */ public static void drawMatrix(GL2 gl2,Matrix4d m,double scale) { boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST); gl2.glDisable(GL2.GL_DEPTH_TEST); boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING); gl2.glDisable(GL2.GL_LIGHTING); gl2.glPushMatrix(); gl2.glTranslated(m.m03,m.m13,m.m23); gl2.glScaled(scale, scale, scale); gl2.glBegin(GL2.GL_LINES); gl2.glColor3f(1,0,0); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m00,m.m10,m.m20); // 1,0,0 = red gl2.glColor3f(0,1,0); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m01,m.m11,m.m21); // 0,1,0 = green gl2.glColor3f(0,0,1); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m02,m.m12,m.m22); // 0,0,1 = blue gl2.glEnd(); gl2.glPopMatrix(); if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING); if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST); }
Example 7
Source File: Robot_Mantis.java From Robot-Overlord-App with GNU General Public License v2.0 | 6 votes |
@Override public void render(GL2 gl2) { if( isFirstTime ) { isFirstTime=false; setupModels(live); } gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); MaterialEntity material = new MaterialEntity(); float r=0.5f; float g=0.5f; float b=0.5f; material.setDiffuseColor(r,g,b,1); material.render(gl2); live.render(gl2); gl2.glPopMatrix(); super.render(gl2); }
Example 8
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 9
Source File: Sixi2LinearGripper.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
@Override public void render(GL2 gl2) { gl2.glPushMatrix(); gl2.glRotatef(180-45,0,0,1); super.render(gl2); gl2.glPopMatrix(); }
Example 10
Source File: Sixi2Live.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
public void renderCartesianForce(GL2 gl2) { double len = Math.sqrt( cartesianForceDetected[0]*cartesianForceDetected[0]+ cartesianForceDetected[1]*cartesianForceDetected[1]+ cartesianForceDetected[2]*cartesianForceDetected[2]); if(len<1) return; //System.out.println(len); int previousState = OpenGLHelper.drawAtopEverythingStart(gl2); boolean lightWasOn = OpenGLHelper.disableLightingStart(gl2); gl2.glLineWidth(4); double scale=1; gl2.glPushMatrix(); Matrix4d m4 = endEffector.getPoseWorld(); gl2.glTranslated(m4.m03, m4.m13, m4.m23); gl2.glBegin(GL2.GL_LINES); gl2.glColor3d(0, 0.6, 1); gl2.glVertex3d(0,0,0); gl2.glVertex3d( cartesianForceDetected[0]*scale, cartesianForceDetected[1]*scale, cartesianForceDetected[2]*scale); gl2.glColor3d(1.0, 0.5, 0.5); PrimitiveSolids.drawCircleYZ(gl2, cartesianForceDetected[3]*scale, 20); gl2.glColor3d(0.5, 1.0, 0.5); PrimitiveSolids.drawCircleXZ(gl2, cartesianForceDetected[4]*scale, 20); gl2.glColor3d(0.5, 0.5, 1.0); PrimitiveSolids.drawCircleXY(gl2, cartesianForceDetected[5]*scale, 20); gl2.glPopMatrix(); gl2.glLineWidth(1); OpenGLHelper.disableLightingEnd(gl2, lightWasOn); OpenGLHelper.drawAtopEverythingEnd(gl2, previousState); }
Example 11
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 12
Source File: Robot_UArm.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
@Override public void render(GL2 gl2) { if( isFirstTime ) { isFirstTime=false; setupModels(live); } live.links.get(2).setRangeMin(20); live.links.get(2).setRangeMax(165); // TODO calculate me in the solver? live.links.get(3).setAlpha( 90 -live.links.get(1).getAlpha() -live.links.get(2).getAlpha() ); live.refreshPose(); gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); // Draw models MaterialEntity mat = new MaterialEntity(); mat.setDiffuseColor( 0.75f*247.0f/255.0f, 0.75f*233.0f/255.0f, 0.75f*215.0f/255.0f, 1); mat.render(gl2); live.render(gl2); gl2.glPopMatrix(); super.render(gl2); }
Example 13
Source File: GridEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
@Override public void render(GL2 gl2) { gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); gl2.glDisable(GL2.GL_TEXTURE_2D); gl2.glDisable(GL2.GL_LIGHTING); gl2.glColor4d(color.getR(), color.getG(), color.getB(), color.getA()); PrimitiveSolids.drawGrid(gl2,width.get(),height.get(),1); gl2.glPopMatrix(); }
Example 14
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 15
Source File: Robot_Thor.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
@Override public void render(GL2 gl2) { if( isFirstTime ) { isFirstTime=false; setupModels(live); } gl2.glPushMatrix(); material.render(gl2); MatrixHelper.applyMatrix(gl2, pose); live.render(gl2); gl2.glPopMatrix(); super.render(gl2); }
Example 16
Source File: ViewportEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
public void showPickingTest(GL2 gl2) { renderChosenProjection(gl2); gl2.glPushMatrix(); Ray r = rayPick(); double cx=cursorX; double cy=cursorY; int w = canvasWidth; int h = canvasHeight; setCursor(0,0); Ray tl = rayPick(); setCursor(w,0); Ray tr = rayPick(); setCursor(0,h); Ray bl = rayPick(); setCursor(w,h); Ray br = rayPick(); cursorX=cx; cursorY=cy; double scale=20; tl.direction.scale(scale); tr.direction.scale(scale); bl.direction.scale(scale); br.direction.scale(scale); r.direction .scale(scale); Vector3d tl2 = new Vector3d(tl.direction); Vector3d tr2 = new Vector3d(tr.direction); Vector3d bl2 = new Vector3d(bl.direction); Vector3d br2 = new Vector3d(br.direction); Vector3d r2 = new Vector3d(r.direction ); tl2.add(tl.start); tr2.add(tr.start); bl2.add(bl.start); br2.add(br.start); r2.add(r.start); gl2.glDisable(GL2.GL_TEXTURE_2D); gl2.glDisable(GL2.GL_LIGHTING); gl2.glColor3d(1, 0, 0); gl2.glBegin(GL2.GL_LINES); gl2.glVertex3d(tl.start.x, tl.start.y, tl.start.z); gl2.glVertex3d(tl2.x, tl2.y, tl2.z); gl2.glVertex3d(tr.start.x, tr.start.y, tr.start.z); gl2.glVertex3d(tr2.x, tr2.y, tr2.z); gl2.glVertex3d(bl.start.x, bl.start.y, bl.start.z); gl2.glVertex3d(bl2.x, bl2.y, bl2.z); gl2.glVertex3d(br.start.x, br.start.y, br.start.z); gl2.glVertex3d(br2.x, br2.y, br2.z); gl2.glColor3d(1, 1, 1); gl2.glVertex3d(r.start.x, r.start.y, r.start.z); gl2.glVertex3d(r2.x,r2.y,r2.z); gl2.glEnd(); gl2.glColor3d(0, 1, 0); gl2.glBegin(GL2.GL_LINE_LOOP); gl2.glVertex3d(tl2.x, tl2.y, tl2.z); gl2.glVertex3d(tr2.x, tr2.y, tr2.z); gl2.glVertex3d(br2.x, br2.y, br2.z); gl2.glVertex3d(bl2.x, bl2.y, bl2.z); gl2.glEnd(); gl2.glColor3d(0, 0, 1); gl2.glBegin(GL2.GL_LINE_LOOP); gl2.glVertex3d(tl.start.x, tl.start.y, tl.start.z); gl2.glVertex3d(tr.start.x, tr.start.y, tr.start.z); gl2.glVertex3d(br.start.x, br.start.y, br.start.z); gl2.glVertex3d(bl.start.x, bl.start.y, bl.start.z); gl2.glEnd(); PrimitiveSolids.drawStar(gl2,r2,5); gl2.glPopMatrix(); }
Example 17
Source File: PrimitiveSolids.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
/** * draw box based on depth,width, and height with the origin in the bottom center. * @param gl2 * @param depth * @param width * @param height */ static public void drawBox(GL2 gl2,double depth,double width,double height) { width/=2; depth/=2; gl2.glPushMatrix(); gl2.glBegin(GL2.GL_QUADS); // bottom gl2.glNormal3f( 0, 0,-1); gl2.glVertex3d(-width, depth,0); gl2.glVertex3d( width, depth,0); gl2.glVertex3d( width,-depth,0); gl2.glVertex3d(-width,-depth,0); // top gl2.glNormal3f( 0, 0, 1); gl2.glVertex3d( width, depth,height); gl2.glVertex3d(-width, depth,height); gl2.glVertex3d(-width,-depth,height); gl2.glVertex3d( width,-depth,height); // side gl2.glNormal3f( 0, 1, 0); gl2.glVertex3d(-width, depth,height); gl2.glVertex3d( width, depth,height); gl2.glVertex3d( width, depth,0); gl2.glVertex3d(-width, depth,0); gl2.glNormal3f( 0,-1, 0); gl2.glVertex3d( width,-depth,height); gl2.glVertex3d(-width,-depth,height); gl2.glVertex3d(-width,-depth,0); gl2.glVertex3d( width,-depth,0); gl2.glNormal3f( 1, 0, 0); gl2.glVertex3d( width, depth,0); gl2.glVertex3d( width, depth,height); gl2.glVertex3d( width,-depth,height); gl2.glVertex3d( width,-depth,0); gl2.glNormal3f(-1, 0, 0); gl2.glVertex3d(-width,-depth,height); gl2.glVertex3d(-width, depth,height); gl2.glVertex3d(-width, depth,0); gl2.glVertex3d(-width,-depth,0); gl2.glEnd(); gl2.glPopMatrix(); }
Example 18
Source File: DrawingPlugin.java From depan with Apache License 2.0 | 4 votes |
/** * Draw a node. */ @Override public boolean apply(NodeRenderingProperty property) { if (!property.isVisible) { return false; } GL2 gl = scene.gl; gl.glPushMatrix(); gl.glPushName(property.shapeId); // move property.shape.setTranslation(property.positionX * GLConstants.FACTOR, property.positionY * GLConstants.FACTOR, 0f); // scale property.shape.setScale(property.size, property.size * property.ratio, property.size); // fill the shape if (property.isFilled) { gl.glColor4f(property.fillColor.getRed() / 255f, property.fillColor.getGreen() / 255f, property.fillColor.getBlue() / 255f, property.fillColor.getAlpha() / 255f); property.shape.fill(gl); } // draw the border if (property.strokeWidth > 0.0f) { gl.glLineWidth(property.strokeWidth); gl.glColor4f(property.strokeColor.getRed() / 255f, property.strokeColor.getGreen() / 255f, property.strokeColor.getBlue() / 255f, property.strokeColor.getAlpha() / 255f); property.shape.draw(gl); } Rectangle2D bounds = property.shape.getDrawingBounds(); updateDrawingBounds(bounds); // we don't want the label to be clickable, // so we just pop the name before drawing it. gl.glPopName(); // draw the label if (property.isTextVisible) { paintLabel(property); } // draw a little "+" on the top right corner of the node if it has // nodes collapsed under. if (property.hasCollapsedNodeUnder) { double centerX = property.positionX+property.size/2; double centerY = property.positionY+property.size/2; double halfWidth = 0.7; double halfHeight = 4; gl.glBegin(GL2.GL_QUADS); gl.glColor4f(1f, 1f, 1f, 0.5f); // vertical line gl.glVertex2d(centerX - halfWidth, centerY + halfHeight); gl.glVertex2d(centerX + halfWidth, centerY + halfHeight); gl.glVertex2d(centerX + halfWidth, centerY - halfHeight); gl.glVertex2d(centerX - halfWidth, centerY - halfHeight); // left part of horizontal line gl.glVertex2d(centerX - halfHeight, centerY + halfWidth); gl.glVertex2d(centerX - halfWidth, centerY + halfWidth); gl.glVertex2d(centerX - halfWidth, centerY - halfWidth); gl.glVertex2d(centerX - halfHeight, centerY - halfWidth); // right part. gl.glVertex2d(centerX + halfWidth, centerY + halfWidth); gl.glVertex2d(centerX + halfHeight, centerY + halfWidth); gl.glVertex2d(centerX + halfHeight, centerY - halfWidth); gl.glVertex2d(centerX + halfWidth, centerY - halfWidth); gl.glVertex3d(0, 0, 0); gl.glEnd(); } gl.glPopMatrix(); return true; }
Example 19
Source File: DragBallEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
@Override public void render(GL2 gl2) { if(subject==null) return; gl2.glDisable(GL2.GL_TEXTURE_2D); RobotOverlord ro = (RobotOverlord)getRoot(); ro.viewport.renderChosenProjection(gl2); gl2.glPushMatrix(); /*if(isBallHit) { Vector3d dp = this.getPosition(); ViewportEntity cameraView = ro.viewport; Ray ray = cameraView.rayPick(); Vector3d dr = ray.getPoint(100); gl2.glBegin(GL2.GL_LINES); gl2.glColor3d(1, 1, 1); gl2.glVertex3d(ray.start.x, ray.start.y, ray.start.z); gl2.glVertex3d(dr.x, dr.y, dr.z); gl2.glVertex3d(dp.x,dp.y,dp.z); gl2.glVertex3d(pickPointOnBall.x, pickPointOnBall.y, pickPointOnBall.z); gl2.glEnd(); PrimitiveSolids.drawStar(gl2, dp,10); PrimitiveSolids.drawStar(gl2, pickPointOnBall,10); }//*/ IntBuffer depthFunc = IntBuffer.allocate(1); gl2.glGetIntegerv(GL2.GL_DEPTH_FUNC, depthFunc); gl2.glDepthFunc(GL2.GL_ALWAYS); //boolean isDepth=gl2.glIsEnabled(GL2.GL_DEPTH_TEST); //gl2.glDisable(GL2.GL_DEPTH_TEST); boolean isLit = gl2.glIsEnabled(GL2.GL_LIGHTING); gl2.glDisable(GL2.GL_LIGHTING); IntBuffer lineWidth = IntBuffer.allocate(1); gl2.glGetIntegerv(GL2.GL_LINE_WIDTH, lineWidth); gl2.glLineWidth(2); gl2.glPushMatrix(); renderOutsideCircle(gl2); MatrixHelper.applyMatrix(gl2, FOR); gl2.glScaled(ballSize.get(),ballSize.get(),ballSize.get()); if(isRotateMode()) { renderRotation(gl2); } else { renderTranslation(gl2); } gl2.glPopMatrix(); // set previous line width gl2.glLineWidth(lineWidth.get()); if (isLit) gl2.glEnable(GL2.GL_LIGHTING); //if(isDepth) gl2.glEnable(GL2.GL_DEPTH_TEST); gl2.glDepthFunc(depthFunc.get()); gl2.glPopMatrix(); }
Example 20
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; } }