Java Code Examples for com.jogamp.opengl.GL2#glPopMatrix()
The following examples show how to use
com.jogamp.opengl.GL2#glPopMatrix() .
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: 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: 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 5
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 6
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 7
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 drawMatrix2(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,1,0); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m00,m.m10,m.m20); // 1,1,0 = yellow gl2.glColor3f(0,1,1); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m01,m.m11,m.m21); // 0,1,1 = teal gl2.glColor3f(1,0,1); gl2.glVertex3f(0,0,0); gl2.glVertex3d(m.m02,m.m12,m.m22); // 1,0,1 = magenta gl2.glEnd(); gl2.glPopMatrix(); if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING); if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST); }
Example 8
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 9
Source File: Robot_Cartesian.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(); MatrixHelper.applyMatrix(gl2, this.getPose()); material.render(gl2); live.render(gl2); gl2.glPopMatrix(); super.render(gl2); }
Example 10
Source File: Spidee.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
public void render(GL2 gl2) { super.render(gl2); gl2.glPushName(getPickName()); gl2.glPushMatrix(); Vector3d p = getPosition(); gl2.glTranslated(p.x, p.y, p.z); Draw_Head(gl2); Draw_Legs(gl2); Draw_Body(gl2); gl2.glPopMatrix(); gl2.glPopName(); }
Example 11
Source File: DragBallEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
/** * Render the white and grey circles around the exterior, always facing the camera. * @param gl2 */ private void renderOutsideCircle(GL2 gl2) { final double whiteRadius=1.05; final double greyRadius=1.0; final int quality=40; RobotOverlord ro = (RobotOverlord)getRoot(); PoseEntity camera = ro.viewport.getAttachedTo(); ro.viewport.renderChosenProjection(gl2); Matrix4d lookAt = camera.getPoseWorld(); lookAt.setTranslation(MatrixHelper.getPosition(subject.getPoseWorld())); gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, lookAt); gl2.glScaled(ballSize.get(),ballSize.get(),ballSize.get()); //white circle on the xy plane of the camera pose, as the subject position gl2.glColor4d(1,1,1,0.7); PrimitiveSolids.drawCircleXY(gl2, whiteRadius, quality); //grey circle on the xy plane of the camera pose, as the subject position gl2.glColor4d(0.5,0.5,0.5,0.7); PrimitiveSolids.drawCircleXY(gl2, greyRadius, quality); gl2.glPopMatrix(); }
Example 12
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 13
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 14
Source File: ModelEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 5 votes |
public void renderModel(GL2 gl2) { gl2.glPushMatrix(); MatrixHelper.applyMatrix(gl2, pose); if( model==null ) { // draw placeholder PrimitiveSolids.drawBox(gl2, 1, 1, 1); PrimitiveSolids.drawStar(gl2,15.0); } else { material.render(gl2); model.render(gl2); } gl2.glPopMatrix(); }
Example 15
Source File: SkyBoxEntity.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
public void render(GL2 gl2,CameraEntity camera) { //gl2.glDisable(GL2.GL_DEPTH_TEST); gl2.glDisable(GL2.GL_LIGHTING); gl2.glDisable(GL2.GL_COLOR_MATERIAL); gl2.glEnable(GL2.GL_TEXTURE_2D); gl2.glPushMatrix(); gl2.glColor3f(1, 1, 1); Vector3d p = camera.getPosition(); gl2.glTranslated(-p.x,-p.y,-p.z); skyboxtextureXPos.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,1); gl2.glVertex3d(10, 10, 10); gl2.glTexCoord2d(1,1); gl2.glVertex3d(10, -10, 10); gl2.glTexCoord2d(1,0); gl2.glVertex3d(10, -10, -10); gl2.glTexCoord2d(0,0); gl2.glVertex3d(10, 10, -10); gl2.glEnd(); skyboxtextureXNeg.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,1); gl2.glVertex3d(-10, -10, 10); gl2.glTexCoord2d(1,1); gl2.glVertex3d(-10, 10, 10); gl2.glTexCoord2d(1,0); gl2.glVertex3d(-10, 10, -10); gl2.glTexCoord2d(0,0); gl2.glVertex3d(-10, -10, -10); gl2.glEnd(); skyboxtextureYPos.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,1); gl2.glVertex3d(-10, 10, 10); gl2.glTexCoord2d(1,1); gl2.glVertex3d(10, 10, 10); gl2.glTexCoord2d(1,0); gl2.glVertex3d(10, 10, -10); gl2.glTexCoord2d(0,0); gl2.glVertex3d(-10, 10, -10); gl2.glEnd(); skyboxtextureYNeg.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,1); gl2.glVertex3d(10, -10, 10); gl2.glTexCoord2d(1,1); gl2.glVertex3d(-10, -10, 10); gl2.glTexCoord2d(1,0); gl2.glVertex3d(-10, -10, -10); gl2.glTexCoord2d(0,0); gl2.glVertex3d(10, -10, -10); gl2.glEnd(); skyboxtextureZPos.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,0); gl2.glVertex3d(-10, 10, 10); gl2.glTexCoord2d(1,0); gl2.glVertex3d( 10, 10, 10); gl2.glTexCoord2d(1,1); gl2.glVertex3d( 10,-10, 10); gl2.glTexCoord2d(0,1); gl2.glVertex3d(-10,-10, 10); gl2.glEnd(); skyboxtextureZNeg.render(gl2); gl2.glBegin(GL2.GL_TRIANGLE_FAN); gl2.glTexCoord2d(0,0); gl2.glVertex3d(-10,-10, -10); gl2.glTexCoord2d(1,0); gl2.glVertex3d( 10,-10, -10); gl2.glTexCoord2d(1,1); gl2.glVertex3d( 10, 10, -10); gl2.glTexCoord2d(0,1); gl2.glVertex3d(-10, 10, -10); gl2.glEnd(); gl2.glPopMatrix(); gl2.glEnable(GL2.GL_DEPTH_TEST); }
Example 16
Source File: PrimitiveSolids.java From Robot-Overlord-App with GNU General Public License v2.0 | 4 votes |
/** * draw a sphere with a given radius. * TODO expose quality parameters? * TODO generate a sphere once as a model, return that. * See https://www.gamedev.net/forums/topic/537269-procedural-sphere-creation/4469427/ * @param gl2 * @param radius */ static public void drawSphere(GL2 gl2,double radius) { int width = 32; int height = 16; double theta, phi; int i, j, t; int nvec = (height-2)* width + 2; int ntri = (height-2)*(width-1)*2; FloatBuffer vertices = FloatBuffer.allocate(nvec * 3); IntBuffer indexes = IntBuffer.allocate(ntri * 3); float [] dat = vertices.array(); int [] idx = indexes.array(); for( t=0, j=1; j<height-1; j++ ) { for(i=0; i<width; i++ ) { theta = (double)(j)/(double)(height-1) * Math.PI; phi = (double)(i)/(double)(width-1 ) * Math.PI*2; dat[t++] = (float)( Math.sin(theta) * Math.cos(phi)); dat[t++] = (float)( Math.cos(theta)); dat[t++] = (float)(-Math.sin(theta) * Math.sin(phi)); } } dat[t++]= 0; dat[t++]= 1; dat[t++]= 0; dat[t++]= 0; dat[t++]=-1; dat[t++]= 0; for( t=0, j=0; j<height-3; j++ ) { for( i=0; i<width-1; i++ ) { idx[t++] = (j )*width + i ; idx[t++] = (j+1)*width + i+1; idx[t++] = (j )*width + i+1; idx[t++] = (j )*width + i ; idx[t++] = (j+1)*width + i ; idx[t++] = (j+1)*width + i+1; } } for( i=0; i<width-1; i++ ) { idx[t++] = (height-2)*width; idx[t++] = i; idx[t++] = i+1; idx[t++] = (height-2)*width+1; idx[t++] = (height-3)*width + i+1; idx[t++] = (height-3)*width + i; } int NUM_BUFFERS=1; int[] VBO = new int[NUM_BUFFERS]; gl2.glGenBuffers(NUM_BUFFERS, VBO, 0); gl2.glBindBuffer(GL2.GL_ARRAY_BUFFER, VBO[0]); // Write out vertex buffer to the currently bound VBO. int s=(Float.SIZE/8); // bits per float / bits per byte = bytes per float gl2.glBufferData(GL2.GL_ARRAY_BUFFER, dat.length*s, vertices, GL2.GL_STATIC_DRAW); gl2.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl2.glVertexPointer(3,GL2.GL_FLOAT,0,0); gl2.glEnableClientState(GL2.GL_NORMAL_ARRAY); gl2.glNormalPointer(GL2.GL_FLOAT,0,0); gl2.glPushMatrix(); gl2.glScaled(radius,radius,radius); gl2.glDrawElements(GL2.GL_TRIANGLES, ntri*3, GL2.GL_UNSIGNED_INT, indexes ); gl2.glPopMatrix(); gl2.glDisableClientState(GL2.GL_NORMAL_ARRAY); gl2.glDisableClientState(GL2.GL_VERTEX_ARRAY); gl2.glDeleteBuffers(NUM_BUFFERS, VBO, 0); }
Example 17
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 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; } }