@Override protected void paintColorScale(GL2 gl, Axis1D axis, int width, int height) { if (colorTexture != null && axis instanceof TaggedAxis1D) { TaggedAxis1D taggedAxis = (TaggedAxis1D) axis; colorTexture.prepare(gl, 0); int count = updateCoordinateBuffers(taggedAxis, width, height); gl.glTexEnvf(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); gl.glPolygonMode(GL2.GL_FRONT, GL2.GL_FILL); gl.glEnable(GL2.GL_TEXTURE_1D); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glVertexPointer(2, GL2.GL_FLOAT, 0, vertexCoords.rewind()); gl.glTexCoordPointer(1, GL2.GL_FLOAT, 0, textureCoords.rewind()); try { gl.glDrawArrays(GL2.GL_QUAD_STRIP, 0, count); } finally { gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glDisable(GL2.GL_TEXTURE_1D); } } gl.glDisable(GL2.GL_TEXTURE_1D); outlineColorQuad(gl, axis, width, height); }
@SuppressWarnings("unused") private static void drawBox(GL2 gl) { gl.glDisable(GLLightingFunc.GL_LIGHTING); gl.glDisable(GL.GL_TEXTURE_2D); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3f(-0.5f, -0.5f, 0.5f); gl.glVertex3f(0.5f, -0.5f, 0.5f); gl.glVertex3f(0.5f, 0.5f, 0.5f); gl.glVertex3f(-0.5f, 0.5f, 0.5f); gl.glVertex3f(-0.5f, -0.5f, 0.5f); gl.glVertex3f(-0.5f, -0.5f, -0.5f); gl.glVertex3f(0.5f, -0.5f, -0.5f); gl.glVertex3f(0.5f, 0.5f, -0.5f); gl.glVertex3f(-0.5f, 0.5f, -0.5f); gl.glVertex3f(-0.5f, -0.5f, -0.5f); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3f(-0.5f, 0.5f, 0.5f); gl.glVertex3f(-0.5f, 0.5f, -0.5f); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3f(0.5f, 0.5f, 0.5f); gl.glVertex3f(0.5f, 0.5f, -0.5f); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3f(0.5f, -0.5f, 0.5f); gl.glVertex3f(0.5f, -0.5f, -0.5f); gl.glEnd(); gl.glEnable(GL.GL_TEXTURE_2D); gl.glEnable(GLLightingFunc.GL_LIGHTING); gl.glEnable(GLLightingFunc.GL_LIGHT0); }
public void draw() { GL2 gl = getGL2(); pushMatrix(); translate(0, 0, -2); rotate(view_rotx, 1.0, 0.0, 0.0); rotate(view_roty, 0.0, 1.0, 0.0); rotate(view_rotz, 0.0, 0.0, 1.0); translate(0, 0, 2); if (app != null) { if (is_playing) { map_previous = map; map = new DepthMap( app.w, app.h, DepthMap.fromRawDepthFile( new File(app.filename), app.frame_now - 1, app.w, app.h, false)); map.maskZ(app.z_threshold.getValue() / 100f); // map.maskRect(130,40,100,100);//head // map.maskRect(50,140,130,100);//arms map.setUVuniform(); if (app.frame_now < app.frames) { app.frame_now += 1; app.time_domain.setValue(app.frame_now); } else { app.play_button.setText("Play"); stop(); } } } if (map != null) { if (app.show_diff.isSelected() && map != null && map_previous != null) { // map.drawNormals(gl); // gl.glClear(GL2.GL_DEPTH); // gl.glEnable(GL2.GL_BLEND); computeColorMap(); gl.glDisable(GL2.GL_LIGHTING); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glColor4f(1f, 1f, 1f, 0.75f); video_frame.use(gl); map.drawTextureNormals(gl); gl.glDisable(GL2.GL_TEXTURE_2D); gl.glEnable(GL2.GL_LIGHTING); gl.glDisable(GL2.GL_BLEND); } else { gl.glColor3f(0.9f, 0.9f, 0.9f); map.drawNormals(gl); } } popMatrix(); }
@Override public void render(GL2 gl, float trajectory) { // flat = true; gl.glPushMatrix(); { gl.glTranslatef(c.x, c.y, c.z); gl.glRotatef(trajectory, 0, -1, 0); gl.glRotatef((flat) ? -90 : 0, 1, 0, 0); gl.glRotatef(rotation, 0, 0, 1); Vec3 scale = new Vec3(0.75f, 2.0f, 0); if (miniature) scale = scale.multiply(0.5f); scale = scale.multiply(0.8f); gl.glScalef(scale.x, scale.y, scale.z); gl.glTranslatef(0, 0.2f, 0); gl.glDepthMask(false); gl.glDisable(GL_LIGHTING); gl.glEnable(GL_BLEND); gl.glEnable(GL_TEXTURE_2D); gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE); whiteSpark.bind(gl); gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]); gl.glBegin(GL_QUADS); { gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-0.5f, -0.5f, 0.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-0.5f, 0.5f, 0.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(0.5f, 0.5f, 0.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(0.5f, -0.5f, 0.0f); } gl.glEnd(); gl.glDisable(GL_BLEND); gl.glEnable(GL_LIGHTING); gl.glDepthMask(true); gl.glColor3f(1, 1, 1); } gl.glPopMatrix(); }
// Where the printing happens private void glPrint(GL2 gl, int x, int y, int set, String fmt) { // If There's No Text if (fmt == null) { return; } // Did User Choose An Invalid Character Set? if (set > 1) { // If So, Select Set 1 (Italic) set = 1; } gl.glEnable(GL.GL_TEXTURE_2D); // Enable Texture Mapping gl.glLoadIdentity(); // Reset The Modelview Matrix gl.glTranslated(x, y, 0); // Position The Text (0,0 - Top Left) gl.glListBase(base - 32 + (128 * set)); // Choose The Font Set (0 or 1) gl.glScalef(1.0f, 2.0f, 1.0f); // Make The Text 2X Taller if (stringBuffer.capacity() < fmt.length()) { stringBuffer = GLBuffers.newDirectByteBuffer(fmt.length()); } stringBuffer.clear(); stringBuffer.put(fmt.getBytes()); stringBuffer.flip(); // Write the text to the screen gl.glCallLists(fmt.length(), GL.GL_UNSIGNED_BYTE, stringBuffer); gl.glDisable(GL.GL_TEXTURE_2D); // Disable Texture Mapping }
/** ***************************************************** */ public void draw(GL2 gl, GLU glu, Camera cam) { if (transform != null) transform.execute(gl); gl.glTranslatef(x, y, z); applyMaterial(gl); gl.glLineWidth(wfwidth); // Draw GLUquadric qobj = glu.gluNewQuadric(); if (facestatus) { if (wfstatus) { gl.glEnable(GL2.GL_POLYGON_OFFSET_FILL); gl.glPolygonOffset(1.0f, 1.0f); } gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); gl.glNormal3f(norm.x, norm.y, norm.z); gl.glColor4f(color.r, color.g, color.b, color.a); glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops); if (wfstatus) gl.glDisable(GL2.GL_POLYGON_OFFSET_FILL); } if (wfstatus) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); gl.glNormal3f(norm.x, norm.y, norm.z); gl.glColor4f(wfcolor.r, wfcolor.g, wfcolor.b, wfcolor.a); glu.gluDisk(qobj, radiusInner, radiusOuter, slices, loops); } }
/** * Render the arrow as a line and a _head. * * @param gl OpenGL Context */ public void render(GL2 gl) { // save Light Attributes and remove lighting to get "full" RGB colors // gl.glPushAttrib( GL2.GL_LIGHTING_BIT ); gl.glPushAttrib(GL2.GL_ENABLE_BIT); gl.glDisable(GL2.GL_LIGHTING); if (_fg_verb) { System.out.println( "Arrow pos=" + _pos.toString() + " angZ1=" + _angZ1 + " angY2=" + _angY2 + " length=" + _length); _fg_verb = false; } // save transformation matrix, then translate and scale. gl.glPushMatrix(); gl.glTranslatef(_pos.x, _pos.y, _pos.z); gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y // draw line gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w); gl.glLineWidth(1.0f); gl.glBegin(GL.GL_LINES); { gl.glVertex3f(0, 0, 0); gl.glVertex3f(_length, 0, 0); } gl.glEnd(); // draw head gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL); gl.glTranslatef(_length, 0, 0); gl.glBegin(GL.GL_TRIANGLES); { for (float[] face : _head_faces) { gl.glVertex3f(face[0], face[1], face[2]); gl.glVertex3f(face[3], face[4], face[5]); gl.glVertex3f(face[6], face[7], face[8]); } } gl.glEnd(); // restore transformation matrix gl.glPopMatrix(); // restore attributes gl.glPopAttrib(); }
public void renderSelection(GL2 g) { if ((Globals.tab == Tab.labels || Globals.tab == Tab.height)) { g.glDisable(GL2.GL_ALPHA_TEST); g.glEnable(GL2.GL_BLEND); g.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); double color = System.currentTimeMillis(); color %= 2000d; color -= 1000d; color = Math.abs(color); color /= 1000d; g.glColor4d(1, 1, 0, 0.1d + 0.2d * color); g.glBegin(GL2.GL_QUADS); g.glVertex2f(0, 0); g.glVertex2f(0, 4); g.glVertex2f(4, 4); g.glVertex2f(4, 0); g.glEnd(); g.glColor4f(1, 1, 1, 1); g.glDisable(GL2.GL_BLEND); g.glEnable(GL2.GL_ALPHA_TEST); } }
public void draw() { // Clear GL state gl.glDisable(GL_LIGHTING); gl.glDisable(GL_DEPTH); gl.glMatrixMode(GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glClearColor(0.8f, 0.2f, 0.2f, 1.0f); gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); gl.glPointSize(1.0f); // Set the viewport glu.gluOrtho2D(xMin, xMax, yMin, yMax); gl.glBegin(GL_POINTS); for (int x = (int) (xMin); x < xMax; x++) for (int y = (int) (yMin); y < yMax; y++) { gl.glColor3d(viewPort[x][y].r, viewPort[x][y].g, viewPort[x][y].b); gl.glVertex2d(x + 0.5, y + 0.5); } gl.glEnd(); // Restore state gl.glMatrixMode(GL_MODELVIEW); gl.glPopMatrix(); gl.glMatrixMode(GL_PROJECTION); gl.glPopMatrix(); gl.glEnable(GL_LIGHTING); gl.glEnable(GL_DEPTH); }
public void updateVisibleOctant(GL2 gl) { if (leavesCount > 0) { // Limits refreshLimits(); // Switch to OpenGL2 select mode int capacity = 1 * 4 * leavesCount; // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glInitNames(); gl.glPushName(0); gl.glDisable(GL2.GL_CULL_FACE); // Disable flags // Draw the nodes cube in the select buffer for (Octant n : leaves) { if (n != null) { gl.glLoadName(n.leafId); n.displayOctant(gl); n.visible = false; } } visibleLeaves = 0; int nbRecords = gl.glRenderMode(GL2.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } // Get the hits and add the nodes' objects to the array int depth = Integer.MAX_VALUE; int minDepth = -1; for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3); // -1 Because of the glPushName(0) int minZ = hitsBuffer.get(i * 4 + 1); if (minZ < depth) { depth = minZ; minDepth = hit; } Octant nodeHit = leaves[hit]; nodeHit.visible = true; visibleLeaves++; } if (minDepth != -1) { Octant closestOctant = leaves[minDepth]; Vec3f pos = new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ()); limits.setClosestPoint(pos); } } }
@Override public void draw(GL2 gl, Texture textureCiel) { GLU glu = new GLU(); GLUT glut = new GLUT(); gl.glEnable(GL_BLEND); // gl.glEnable(GL_SMOOTH); // gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SMOOTH); gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); // gl.glEnable(GL_TEXTURE_GEN_S); // gl.glEnable(GL_TEXTURE_GEN_T); // gl.glEnable(GL_TEXTURE_GEN_R); // // gl.glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); // gl.glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); // gl.glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP); float[] rgba = {1f, 1f, 1f}; gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT, rgba, 0); gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, rgba, 0); gl.glMaterialf(GL2.GL_FRONT, GL2.GL_SHININESS, 0.0f); textureCiel.enable(gl); textureCiel.bind(gl); glut.glutSolidSphere(256, 20, 20); textureCiel.disable(gl); gl.glDisable(GL_TEXTURE_GEN_S); gl.glDisable(GL_TEXTURE_GEN_T); gl.glDisable(GL_TEXTURE_GEN_R); gl.glDisable(GL_BLEND); }
protected void beginRendering(DrawContext dc, OGLStackHandler stackHandler) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().fine(message); throw new IllegalArgumentException(message); } GL2 gl = dc.getGL(); int attribMask = GL2.GL_COLOR_BUFFER_BIT // for alpha test func and ref, blend func | GL2.GL_CURRENT_BIT // for current color | GL2.GL_ENABLE_BIT // for enable/disable | GL2.GL_LINE_BIT // for line width | GL2.GL_TRANSFORM_BIT; // for matrix mode stackHandler.pushAttrib(gl, attribMask); stackHandler.pushTextureIdentity(gl); stackHandler.pushProjectionIdentity(gl); java.awt.Rectangle viewport = dc.getView().getViewport(); gl.glOrtho( viewport.x, viewport.x + viewport.width, viewport.y, viewport.y + viewport.height, -1, 1); stackHandler.pushModelviewIdentity(gl); // Enable the alpha test. gl.glEnable(GL2.GL_ALPHA_TEST); gl.glAlphaFunc(GL2.GL_GREATER, 0.0f); // Enable blending in premultiplied color mode. gl.glEnable(GL2.GL_BLEND); OGLUtil.applyBlending(gl, true); gl.glDisable(GL2.GL_CULL_FACE); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glDisable(GL2.GL_LIGHTING); gl.glDisable(GL2.GL_TEXTURE_2D); }
public void drawTextureToOffScreenTexture(int texId, int attachment) // public void drawTextureToOffScreenTextureUsingShader(Texture tex, int attachment, Program // program) { GL2 gl = getGL(); // program.bind(gl); gl.glBindTexture(GL_TEXTURE_2D, texId); // gl.glBindTexture(GL_TEXTURE_2D, tex.getTextureObject()); // gl.glDrawBuffer(attachment); gl.glBindFramebuffer(GL_FRAMEBUFFER, attachment); // think this is the new way... gl.glEnable(GL_TEXTURE_2D); // gl.glActiveTexture(GL_TEXTURE0); gl.glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); gl.glViewport(0, 0, fboWidth, fboHeight); // gl.glUniform1i(program.uniform("theTexture"), 0); // set projection to ortho gl.glMatrixMode(GL_PROJECTION); gl.glTranslatef(1f, 1f, 1f); gl.glPushMatrix(); { gl.glLoadIdentity(); RenderUtils.getGLU().gluOrtho2D(0, fboWidth, fboHeight, 0); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glPushMatrix(); { gl.glLoadIdentity(); gl.glColor4f(1f, 1f, 1f, 1f); drawSquare(gl, 0, 0, fboWidth, fboHeight); } gl.glPopMatrix(); gl.glMatrixMode(gl.GL_PROJECTION); } gl.glPopMatrix(); gl.glMatrixMode(gl.GL_MODELVIEW); gl.glDisable(GL_TEXTURE_2D); // program.unbind(gl); }
public void renderObj(GL2 gl) { gl.glPushMatrix(); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); gl.glTexParameterf(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); texture.enable(gl); texture.bind(gl); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glColor4d(1, 1, 1, transparancy); gl.glScalef(canvas.orthoCoordWidth / 2, canvas.orthoCoordWidth / 2 / canvas.aspectRatio, 1); gl.glBegin(GL2.GL_QUADS); gl.glTexCoord2f(0, 0); gl.glVertex2f(-1, -1); gl.glTexCoord2f(1, 0); gl.glVertex2f(1, -1); gl.glTexCoord2f(1, 1); gl.glVertex2f(1, 1); gl.glTexCoord2f(0, 1); gl.glVertex2f(-1, 1); gl.glEnd(); gl.glEnable(GL2.GL_DEPTH_TEST); gl.glDisable(GL2.GL_TEXTURE_2D); gl.glPopMatrix(); }
public void displayOctree(GL2 gl, GLU glu) { gl.glDisable(GL2.GL_CULL_FACE); gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); for (Octant o : leaves) { if (o != null && o.visible) { gl.glColor3f(1, 0.5f, 0.5f); o.displayOctant(gl); o.displayOctantInfo(gl, glu); } } if (!vizController.getVizConfig().isWireFrame()) { gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_FILL); } if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } }
/** * This method is a temporary helper method for draving the light for debuging purposes. Except it * to decome deprecated in the future. */ public void renderLight(GL2 gl) { gl.glDisable(GLLightingFunc.GL_LIGHTING); ShaderProgram.unuseCurrent(gl); switch (type) { case Directional: gl.glBegin(GL2.GL_LINES); gl.glColor3f(0.0f, 0.0f, 0.0f); gl.glVertex3f(0.0f, 0.0f, 0.0f); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(position.x, position.y, position.z); gl.glEnd(); break; case Point: gl.glBegin(GL2.GL_POINTS); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(position.x, position.y, position.z); gl.glEnd(); break; case Spot: Vector3f p = position, d = new Vector3f(); d.set(direction); d.scale(4); gl.glBegin(GL2.GL_LINES); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(p.x, p.y, p.z); gl.glColor3f(0.2f, 0.2f, 0.2f); gl.glVertex3f(p.x + d.x, p.y + d.y, p.z + d.z); /* Spot wireframe d.normalize(); //d. d.cross(d, new Vector3f(0.0f, 1.0f, 0.0f)); gl.glColor3f(1.0f, 1.0f, 1.0f); gl.glVertex3f(p.x, p.y, p.z); gl.glColor3f(0.4f, 0.2f, 0.2f); gl.glVertex3f(p.x+d.x, p.y+d.y, p.z+d.z); */ gl.glEnd(); } gl.glEnable(GLLightingFunc.GL_LIGHTING); }
public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); TextRenderer.createInstance(); PrimitiveBuffers.createBuffers(); AssetManager.setInstance(new DesktopAssetManager()); DesktopTextureManager textureManager = new DesktopTextureManager(); textureManager.setGL2(drawable.getGL().getGL2()); TextureManager.setInstance(textureManager); TextureManager.init(new DesktopGL2(gl)); DefaultShaders.createDefaultShaders(new DesktopGL2(gl)); GenoShaders.createShaders(new DesktopGL2(gl)); GenoTexID.createTextures(new DesktopGL2(gl)); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); }
@Override protected void draw(GL2 gl, AbstractCamera camera, Vec3 sun) { // by default, active sets visibility of entity if (!active) { return; } worldMatrix = createWorldMatrix(); if (shader != null) { shader.use(gl); shader.updateUniform(gl, "world", worldMatrix); shader.updateUniform(gl, "view", camera.view); shader.updateUniform(gl, "projection", camera.projection); if (colour != null) { shader.updateUniform(gl, "colour", colour); } shader.updateUniform(gl, "opacity", opacity); } if (opacity < 1.0f) { gl.glEnable(GL.GL_BLEND); } gl.glBegin(GL.GL_LINE_STRIP); { for (int i = 0; i < line.length; i++) { gl.glVertex3f(line[i].getX(), line[i].getY(), line[i].getZ()); } } gl.glEnd(); if (opacity < 1.0f) { gl.glDisable(GL.GL_BLEND); } }
@Override public void display(GLAutoDrawable drawable) { gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); // desenha ou nao a bounding sphere de cada objeto if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_B)) { // tecla B BoundingVolume.isVisible = !BoundingVolume.isVisible; } // habilita ou nao fog if (InputHandler.getInstance().isKeyPressed(KeyEvent.VK_F)) { // tecla F fogEnabled = !fogEnabled; if (fogEnabled) gl.glEnable(GL2.GL_FOG); else gl.glDisable(GL2.GL_FOG); } // atualiza camera camera.update(); // atualiza objetos { Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator(); while (it.hasNext()) { SceneObject so = it.next(); // animacao da porta if (so.getName().contains("door")) { if (Collision.collide( camera.getSceneObject().getBoundingSphere(), so.getBoundingSphere())) so.setAnimating(true); else so.setAnimating(false); } so.update(); } } glu.gluLookAt( FPCamera.position.x, FPCamera.position.y, FPCamera.position.z, FPCamera.position.x + FPCamera.look.x, FPCamera.position.y + FPCamera.look.y, FPCamera.position.z + FPCamera.look.z, FPCamera.up.x, FPCamera.up.y, FPCamera.up.z); if (FPCamera.changed) { // se direcao da camera mudar FPCamera.changed = false; frustum.generate(drawable); // gera o frustum Scene.getInstance().clearVisibleObjectsList(); Iterator<SceneObject> it = Scene.getInstance().getSceneObjectsIterator(); while (it.hasNext()) { SceneObject so = it.next(); if (frustum.sphereInFrustum(so.getBoundingSphere())) Scene.getInstance().addVisibleObject(so); } // System.out.println("Renderable objects: "+ Scene.getInstance().getSize()); // System.out.println(FPCamera.position); } // desenha objetos { Iterator<SceneObject> it = Scene.getInstance().getVisibleObjectsIterator(); SceneObject so; while (it.hasNext()) { so = it.next(); if (so.getName().contains("lake")) { gl.glPushAttrib(GL2.GL_ENABLE_BIT); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE); so.draw(drawable); gl.glPopAttrib(); continue; } so.draw(drawable); } } // int e = gl.glGetError(); // if(e != GL.GL_NO_ERROR) { // System.err.println("Erro: "+ gl.glGetString(e)); // } // calculo do fps ++frame; long time = System.currentTimeMillis(); elapsed = time - timebase; if (elapsed > 1000) { long fps = frame * 1000 / (time - timebase); timebase = time; frame = 0; String str = "FPS: " + fps; mainFrame.setTitle(str); } // gl.glFlush(); }
public void updateSelectedOctant(GL2 gl, GLU glu, float[] mousePosition, float[] pickRectangle) { if (visibleLeaves > 0) { // Start Picking mode int capacity = 1 * 4 * visibleLeaves; // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL2.GL_SELECT); gl.glDisable(GL2.GL_CULL_FACE); // Disable flags gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); glu.gluPickMatrix( mousePosition[0], mousePosition[1], pickRectangle[0], pickRectangle[1], drawable.getViewport()); gl.glMultMatrixf(drawable.getProjectionMatrix()); gl.glMatrixMode(GL2.GL_MODELVIEW); // Draw the nodes' cube int the select buffer List<Octant> visibleLeaves = new ArrayList<Octant>(); for (Octant n : leaves) { if (n != null && n.visible) { int i = visibleLeaves.size() + 1; visibleLeaves.add(n); gl.glLoadName(i); n.displayOctant(gl); } } // Restoring the original projection matrix gl.glMatrixMode(GL2.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glFlush(); // Returning to normal rendering mode int nbRecords = gl.glRenderMode(GL2.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL2.GL_CULL_FACE); gl.glCullFace(GL2.GL_BACK); } // Clean previous selection selectedLeaves.clear(); // Get the hits and put the node under selection in the selectionArray for (int i = 0; i < nbRecords; i++) { int hit = hitsBuffer.get(i * 4 + 3) - 1; // -1 Because of the glPushName(0) Octant nodeHit = visibleLeaves.get(hit); selectedLeaves.add(nodeHit); } } }
public void display(GLAutoDrawable drawable) { update(); GL2 gl = drawable.getGL().getGL2(); // Clear Color Buffer, Depth Buffer gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); Matrix TmpMatrix = new Matrix(); // Temporary MATRIX Structure ( NEW ) Vector TmpVector = new Vector(), TmpNormal = new Vector(); // Temporary // VECTOR // Structures // ( NEW ) gl.glLoadIdentity(); // Reset The Matrix if (outlineSmooth) { // Check To See If We Want Anti-Aliased Lines ( NEW // ) gl.glHint(GL2.GL_LINE_SMOOTH_HINT, GL2.GL_NICEST); // Use The Good // Calculations // ( NEW ) gl.glEnable(GL2.GL_LINE_SMOOTH); // Enable Anti-Aliasing ( NEW ) } else // We Don't Want Smooth Lines ( NEW ) gl.glDisable(GL2.GL_LINE_SMOOTH); // Disable Anti-Aliasing ( NEW ) gl.glTranslatef(0.0f, 0.0f, -2.0f); // Move 2 Units Away From The Screen // ( NEW ) gl.glRotatef(modelAngle, 0.0f, 1.0f, 0.0f); // Rotate The Model On It's // Y-Axis ( NEW ) gl.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, TmpMatrix.Data, 0); // Get // The // Generated // Matrix // ( // NEW // ) // Cel-Shading Code // gl.glEnable(GL2.GL_TEXTURE_1D); // Enable 1D Texturing ( NEW ) gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind Our // Texture ( NEW // ) gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color Of The Model ( NEW ) gl.glBegin(GL2.GL_TRIANGLES); // Tell OpenGL That We're Drawing // Triangles // Loop Through Each Polygon for (int i = 0; i < polyNum; i++) // Loop Through Each Vertex for (int j = 0; j < 3; j++) { // Fill Up The TmpNormal Structure With TmpNormal.X = polyData[i].Verts[j].Nor.X; // The Current Vertices' Normal Values TmpNormal.Y = polyData[i].Verts[j].Nor.Y; TmpNormal.Z = polyData[i].Verts[j].Nor.Z; // Rotate This By The Matrix TmpMatrix.rotateVector(TmpNormal, TmpVector); // Normalize The New Normal TmpVector.normalize(); // Calculate The Shade Value float TmpShade = Vector.dotProduct(TmpVector, lightAngle); // Clamp The Value to 0 If Negative ( NEW ) if (TmpShade < 0.0f) { TmpShade = 0.0f; } // Set The Texture Co-ordinate As The Shade Value gl.glTexCoord1f(TmpShade); // Send The Vertex Position gl.glVertex3f( polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z); } gl.glEnd(); // Tell OpenGL To Finish Drawing gl.glDisable(GL2.GL_TEXTURE_1D); // Disable 1D Textures ( NEW ) // Outline Code // Check To See If We Want To Draw The Outline if (outlineDraw) { // Enable Blending gl.glEnable(GL2.GL_BLEND); // Set The Blend Mode gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); // Draw Backfacing Polygons As Wireframes gl.glPolygonMode(GL2.GL_BACK, GL2.GL_LINE); // Set The Line Width gl.glLineWidth(outlineWidth); // Don't Draw Any Front-Facing Polygons gl.glCullFace(GL2.GL_FRONT); // Change The Depth Mode gl.glDepthFunc(GL2.GL_LEQUAL); // Set The Outline Color gl.glColor3fv(outlineColor, 0); // Tell OpenGL What We Want To Draw gl.glBegin(GL2.GL_TRIANGLES); // Loop Through Each Polygon for (int i = 0; i < polyNum; i++) { // Loop Through Each Vertex for (int j = 0; j < 3; j++) { // Send The Vertex Position gl.glVertex3f( polyData[i].Verts[j].Pos.X, polyData[i].Verts[j].Pos.Y, polyData[i].Verts[j].Pos.Z); } } gl.glEnd(); // Tell OpenGL We've Finished // Reset The Depth-Testing Mode gl.glDepthFunc(GL2.GL_LESS); // Reset The Face To Be Culled gl.glCullFace(GL2.GL_BACK); // Reset Back-Facing Polygon Drawing Mode gl.glPolygonMode(GL2.GL_BACK, GL2.GL_FILL); // Disable Blending gl.glDisable(GL2.GL_BLEND); } // Check To See If Rotation Is Enabled if (modelRotate) { // Update Angle Based On The Clock modelAngle += .2f; } }
public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // Storage for the 96 Shader Values ( NEW ) FloatBuffer shaderData = GLBuffers.newDirectFloatBuffer(96); // Start Of User Initialization // Really Nice perspective calculations Light Grey Background gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST); gl.glClearColor(0.7f, 0.7f, 0.7f, 0.0f); // Depth Buffer Setup gl.glClearDepth(1.0f); // Enable Depth Testing gl.glEnable(GL2.GL_DEPTH_TEST); // The Type Of Depth Test To Do gl.glDepthFunc(GL2.GL_LESS); // Enables Smooth Color Shading ( NEW ) gl.glShadeModel(GL2.GL_SMOOTH); // Initially Disable Line Smoothing ( NEW ) gl.glDisable(GL2.GL_LINE_SMOOTH); // Enable OpenGL Face Culling ( NEW ) gl.glEnable(GL2.GL_CULL_FACE); // Disable OpenGL Lighting ( NEW ) gl.glDisable(GL2.GL_LIGHTING); StringBuffer readShaderData = new StringBuffer(); try { InputStream inputStream = ResourceRetriever.getResourceAsStream("demos/data/models/Shader.txt"); int info; while ((info = inputStream.read()) != -1) readShaderData.append((char) info); inputStream.close(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } StringTokenizer tokenizer = new StringTokenizer(readShaderData.toString()); // Loop Though The 32 Greyscale Values while (tokenizer.hasMoreTokens()) { float value = Float.parseFloat(tokenizer.nextToken()); shaderData.put(value); shaderData.put(value); shaderData.put(value); } shaderData.flip(); gl.glGenTextures(1, shaderTexture, 0); // Get A Free Texture ID ( NEW ) gl.glBindTexture(GL2.GL_TEXTURE_1D, shaderTexture[0]); // Bind This // Texture. From // Now On It // Will Be 1D // For Crying Out Loud Don't Let OpenGL Use Bi/Trilinear Filtering! gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); gl.glTexParameteri(GL2.GL_TEXTURE_1D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); gl.glTexImage1D( GL2.GL_TEXTURE_1D, 0, GL2.GL_RGB, 32, 0, GL2.GL_RGB, GL2.GL_FLOAT, shaderData); // Upload // Set The X Direction lightAngle.X = 0.0f; // Set The Y Direction lightAngle.Y = 0.0f; // Set The Z Direction lightAngle.Z = 1.0f; lightAngle.normalize(); try { // Return The Value Of ReadMesh readMesh(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void draw(IDelegateView view, DrawContext dc, DrawableSceneController sc) { GL2 gl = dc.getGL().getGL2(); init(gl); if (distortionShader.isCreationFailed()) { view.draw(dc, sc); return; } Rectangle oldViewport = view.getViewport(); hmd.beginFrameTiming(++frameCount); { Posef[] eyePoses = hmd.getEyePoses(frameCount, eyeOffsets); // RiftLogger.logPose(eyePoses); renderEyes = true; frameBuffer.bind(gl); { sc.clearFrame(dc); for (int i = 0; i < ovrEye_Count; i++) { int eye = hmd.EyeRenderOrder[i]; Posef pose = eyePoses[eye]; this.eyePoses[eye].Orientation = pose.Orientation; this.eyePoses[eye].Position = pose.Position; this.eye = eye; gl.glViewport( eyeRenderViewport[eye].Pos.x, eyeRenderViewport[eye].Pos.y, eyeRenderViewport[eye].Size.w, eyeRenderViewport[eye].Size.h); sc.applyView(dc); sc.draw(dc); } } frameBuffer.unbind(gl); renderEyes = false; OGLStackHandler oglsh = new OGLStackHandler(); oglsh.pushAttrib(gl, GL2.GL_ENABLE_BIT); oglsh.pushClientAttrib(gl, GL2.GL_CLIENT_VERTEX_ARRAY_BIT); try { gl.glViewport(0, 0, hmd.Resolution.w, hmd.Resolution.h); gl.glDisable(GL2.GL_DEPTH_TEST); gl.glEnable(GL2.GL_TEXTURE_2D); gl.glActiveTexture(GL2.GL_TEXTURE0); gl.glBindTexture(GL2.GL_TEXTURE_2D, frameBuffer.getTexture().getId()); for (int eyeNum = 0; eyeNum < ovrEye_Count; eyeNum++) { OvrMatrix4f[] timeWarpMatricesRowMajor = new OvrMatrix4f[2]; hmd.getEyeTimewarpMatrices(eyeNum, eyePoses[eyeNum], timeWarpMatricesRowMajor); distortionShader.use( gl, uvScaleOffset[eyeNum][0].x, -uvScaleOffset[eyeNum][0].y, uvScaleOffset[eyeNum][1].x, 1 - uvScaleOffset[eyeNum][1].y, timeWarpMatricesRowMajor[0].M, timeWarpMatricesRowMajor[1].M); gl.glClientActiveTexture(GL2.GL_TEXTURE0); gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glEnableClientState(GL2.GL_COLOR_ARRAY); gl.glBindBuffer( GL2.GL_ARRAY_BUFFER, distortionObjects[eyeNum][DistortionObjects.vbo.ordinal()]); { int stride = 10 * 4; gl.glVertexPointer(4, GL2.GL_FLOAT, stride, 0); gl.glTexCoordPointer(2, GL2.GL_FLOAT, stride, 4 * 4); gl.glColorPointer(4, GL2.GL_FLOAT, stride, 6 * 4); gl.glBindBuffer( GL2.GL_ELEMENT_ARRAY_BUFFER, distortionObjects[eyeNum][DistortionObjects.ibo.ordinal()]); { gl.glDrawElements(GL2.GL_TRIANGLES, indicesCount, GL2.GL_UNSIGNED_INT, 0); } gl.glBindBuffer(GL2.GL_ELEMENT_ARRAY_BUFFER, 0); } gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0); distortionShader.unuse(gl); } } finally { oglsh.pop(gl); } } hmd.endFrameTiming(); // apply the old viewport, and ensure that the view is updated for the next picking round gl.glViewport(oldViewport.x, oldViewport.y, oldViewport.width, oldViewport.height); sc.applyView(dc); view.firePropertyChange( AVKey.VIEW, null, view); // make the view draw repeatedly for oculus rotation }
private void toggleLightOff(GL2 gl) { lightEnabled = gl.glIsEnabled(GL2.GL_LIGHTING); if (lightEnabled) { gl.glDisable(GL2.GL_LIGHTING); } }
public void drawTrees(GL2 gl, Texture[] textures) { for (int i = 0; i < nbArbres; i++) { RandomCoordonnees ran = listeCoord.get(i); // On dessine que les arbres au dessus du niveau de la mer if (tableauNiveaux[ran.getX()][ran.getY()] >= GameConstants.NIVEAU_EAU) { int x = ran.getX() - (tableauNiveaux.length / 2); int z = ran.getY() - (tableauNiveaux[0].length / 2); // Arbres textures textures[indicesTypeArbres[i]].enable(gl); textures[indicesTypeArbres[i]].bind(gl); // Transparence des PNG : Assombrit l'image !!! gl.glEnable(GL_BLEND); gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); gl.glBegin(GL_QUADS); /* * Ordre des coins * 10 * 00 * 01 * 11 * * */ // Dessin des deux faces avec textures gl.glTexCoord2d(1.0, 0.0); gl.glVertex3f( (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f), tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre, z * GameConstants.LARGEUR_CARRE); gl.glTexCoord2d(0.0, 0.0); gl.glVertex3f( (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f), tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre, z * GameConstants.LARGEUR_CARRE); gl.glTexCoord2d(0.0, 1.0); gl.glVertex3f( (x * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f), tableauNiveaux[ran.getX()][ran.getY()], z * GameConstants.LARGEUR_CARRE); gl.glTexCoord2d(1.0, 1.0); gl.glVertex3f( (x * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f), tableauNiveaux[ran.getX()][ran.getY()], z * GameConstants.LARGEUR_CARRE); gl.glTexCoord2d(1.0, 0.0); gl.glVertex3f( x * GameConstants.LARGEUR_CARRE, tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre, (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f)); gl.glTexCoord2d(0.0, 0.0); gl.glVertex3f( x * GameConstants.LARGEUR_CARRE, tableauNiveaux[ran.getX()][ran.getY()] + hauteurArbre, (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f)); gl.glTexCoord2d(0.0, 1.0); gl.glVertex3f( x * GameConstants.LARGEUR_CARRE, tableauNiveaux[ran.getX()][ran.getY()], (z * GameConstants.LARGEUR_CARRE) - (largeurArbre / 2.0f)); gl.glTexCoord2d(1.0, 1.0); gl.glVertex3f( x * GameConstants.LARGEUR_CARRE, tableauNiveaux[ran.getX()][ran.getY()], (z * GameConstants.LARGEUR_CARRE) + (largeurArbre / 2.0f)); gl.glEnd(); textures[indicesTypeArbres[i]].disable(gl); // gl.glDisable(GL_TEXTURE_2D); gl.glDisable(GL_BLEND); } } }
public void render(GL2 gl2) { int i; boolean draw_finger_star = false; boolean draw_base_star = false; boolean draw_shoulder_to_elbow = false; boolean draw_shoulder_star = false; boolean draw_elbow_star = false; boolean draw_wrist_star = false; boolean draw_stl = true; // RebuildShoulders(motion_now); gl2.glPushMatrix(); gl2.glTranslated(position.x, position.y, position.z); if (draw_stl) { // base gl2.glPushMatrix(); gl2.glColor3f(0, 0, 1); gl2.glTranslatef(0, 0, BASE_TO_SHOULDER_Z + 0.6f); gl2.glRotatef(90, 0, 0, 1); gl2.glRotatef(90, 1, 0, 0); modelBase.render(gl2); gl2.glPopMatrix(); // arms for (i = 0; i < 3; ++i) { gl2.glColor3f(1, 0, 1); gl2.glPushMatrix(); gl2.glTranslatef( motion_now.arms[i * 2 + 0].shoulder.x, motion_now.arms[i * 2 + 0].shoulder.y, motion_now.arms[i * 2 + 0].shoulder.z); gl2.glRotatef(120.0f * i, 0, 0, 1); gl2.glRotatef(90, 0, 1, 0); gl2.glRotatef(180 - motion_now.arms[i * 2 + 0].angle, 0, 0, 1); modelArm.render(gl2); gl2.glPopMatrix(); gl2.glColor3f(1, 1, 0); gl2.glPushMatrix(); gl2.glTranslatef( motion_now.arms[i * 2 + 1].shoulder.x, motion_now.arms[i * 2 + 1].shoulder.y, motion_now.arms[i * 2 + 1].shoulder.z); gl2.glRotatef(120.0f * i, 0, 0, 1); gl2.glRotatef(90, 0, 1, 0); gl2.glRotatef(+motion_now.arms[i * 2 + 1].angle, 0, 0, 1); modelArm.render(gl2); gl2.glPopMatrix(); } // top gl2.glPushMatrix(); gl2.glColor3f(0, 1, 0); gl2.glTranslatef(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z); gl2.glRotatef(motion_now.iku, 1, 0, 0); gl2.glRotatef(motion_now.ikv, 0, 1, 0); gl2.glRotatef(motion_now.ikw, 0, 0, 1); gl2.glRotatef(90, 0, 0, 1); gl2.glRotatef(180, 1, 0, 0); modelTop.render(gl2); gl2.glPopMatrix(); } // draw the forearms Cylinder tube = new Cylinder(); gl2.glColor3f(0.8f, 0.8f, 0.8f); tube.setRadius(0.15f); for (i = 0; i < 6; ++i) { // gl2.glBegin(GL2.GL_LINES); // gl2.glColor3f(1,0,0); // gl2.glVertex3f(motion_now.arms[i].wrist.x,motion_now.arms[i].wrist.y,motion_now.arms[i].wrist.z); // gl2.glColor3f(0,1,0); // gl2.glVertex3f(motion_now.arms[i].elbow.x,motion_now.arms[i].elbow.y,motion_now.arms[i].elbow.z); // gl2.glEnd(); tube.SetP1(motion_now.arms[i].wrist); tube.SetP2(motion_now.arms[i].elbow); PrimitiveSolids.drawCylinder(gl2, tube); } gl2.glDisable(GL2.GL_LIGHTING); // debug info gl2.glPushMatrix(); for (i = 0; i < 6; ++i) { gl2.glColor3f(1, 1, 1); if (draw_shoulder_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].shoulder, 5); if (draw_elbow_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].elbow, 3); if (draw_wrist_star) PrimitiveSolids.drawStar(gl2, motion_now.arms[i].wrist, 1); if (draw_shoulder_to_elbow) { gl2.glBegin(GL2.GL_LINES); gl2.glColor3f(0, 1, 0); gl2.glVertex3f( motion_now.arms[i].elbow.x, motion_now.arms[i].elbow.y, motion_now.arms[i].elbow.z); gl2.glColor3f(0, 0, 1); gl2.glVertex3f( motion_now.arms[i].shoulder.x, motion_now.arms[i].shoulder.y, motion_now.arms[i].shoulder.z); gl2.glEnd(); } } gl2.glPopMatrix(); if (draw_finger_star) { // draw finger orientation float s = 2; gl2.glBegin(GL2.GL_LINES); gl2.glColor3f(1, 1, 1); gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z); gl2.glVertex3f( motion_now.finger_tip.x + motion_now.finger_forward.x * s, motion_now.finger_tip.y + motion_now.finger_forward.y * s, motion_now.finger_tip.z + motion_now.finger_forward.z * s); gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z); gl2.glVertex3f( motion_now.finger_tip.x + motion_now.finger_up.x * s, motion_now.finger_tip.y + motion_now.finger_up.y * s, motion_now.finger_tip.z + motion_now.finger_up.z * s); gl2.glVertex3f(motion_now.finger_tip.x, motion_now.finger_tip.y, motion_now.finger_tip.z); gl2.glVertex3f( motion_now.finger_tip.x + motion_now.finger_left.x * s, motion_now.finger_tip.y + motion_now.finger_left.y * s, motion_now.finger_tip.z + motion_now.finger_left.z * s); gl2.glEnd(); } if (draw_base_star) { // draw finger orientation float s = 2; gl2.glDisable(GL2.GL_DEPTH_TEST); gl2.glBegin(GL2.GL_LINES); gl2.glColor3f(1, 0, 0); gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z); gl2.glVertex3f( motion_now.base.x + motion_now.base_forward.x * s, motion_now.base.y + motion_now.base_forward.y * s, motion_now.base.z + motion_now.base_forward.z * s); gl2.glColor3f(0, 1, 0); gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z); gl2.glVertex3f( motion_now.base.x + motion_now.base_up.x * s, motion_now.base.y + motion_now.base_up.y * s, motion_now.base.z + motion_now.base_up.z * s); gl2.glColor3f(0, 0, 1); gl2.glVertex3f(motion_now.base.x, motion_now.base.y, motion_now.base.z); gl2.glVertex3f( motion_now.base.x + motion_now.finger_left.x * s, motion_now.base.y + motion_now.finger_left.y * s, motion_now.base.z + motion_now.finger_left.z * s); gl2.glEnd(); gl2.glEnable(GL2.GL_DEPTH_TEST); } gl2.glEnable(GL2.GL_LIGHTING); gl2.glPopMatrix(); }
public void draw(GL2 gl, GLU glu, GLDrawState ds) { final Color4f highColor = new Color4f(0.0f, 1.0f, 0.0f, 1.0f); final Color4f lowColor = new Color4f(1.0f, 1.0f, 1.0f, 1.0f); Color4f[][] trueCols = new Color4f[mapHeight][mapWidth]; // InternalTerrainTile tiles[][] = ds.getGameMap().getTerrainMatrix(); // Update colors for (int j = 0; j < mapHeight; j++) { for (int i = 0; i < mapWidth; i++) { // float fluxAmount = getMapHeight(i, j)/64.f; // System.out.println(flux[j/DENSITY][i/DENSITY] + " " + fluxAmount); // float fluxAmount = (float)tiles[i/DENSITY][j/DENSITY].getFlux(); Color4f tintColor = new Color4f(); Color4f trueColor = new Color4f(); tintColor.interpolate(lowColor, highColor, 0); // System.out.println(actualHeight/maxHeight); trueColor.interpolate(cols[j][i], tintColor, 1.0f); trueColor.w = cols[j][i].w; trueCols[j][i] = trueColor; // If void, see through to the background. /*if(tiles[i/DENSITY][j/DENSITY] == TerrainType.VOID){ trueCols[j][i].w = 0.0f; }*/ } } // System.out.println(map.getTerrainMatrix()[0][0].getFlux() + " " + MAX_FLUX_PER_TILE + " " + // trueCols[0][0].x); int k = 0; for (int j = 0; j < mapHeight; j++) { for (int i = 0; i < mapWidth; i++) { colors[k] = trueCols[j][i].x; colors[k + 1] = trueCols[j][i].y; colors[k + 2] = trueCols[j][i].z; colors[k + 3] = trueCols[j][i].w; float norm = (float) Math.sqrt( trueCols[j][i].x * trueCols[j][i].x + trueCols[j][i].y * trueCols[j][i].y + trueCols[j][i].z * trueCols[j][i].z); float val = (norm < 0.3f) ? 0.0f : 0.9f; colorNorm[k] = val; colorNorm[k + 1] = val; colorNorm[k + 2] = val; colorNorm[k + 3] = 1.0f; k += 4; } } if (tex == null && texturePath != null) { tex = GLGameRenderer.textureCache.getResource(texturePath, texturePath).tex; texturePath = null; } gl.glPushMatrix(); // gl.glTranslatef(1.5f, 0.0f, 1.5f); if (tex != null) { System.out.println("Using texture"); gl.glEnable(GL2.GL_TEXTURE_2D); tex.bind(gl); gl.glBegin(GL2.GL_TRIANGLE_STRIP); for (int i = 0; i < indices.length; i++) { gl.glTexCoord2f(texCoords[indices[i] * 2], texCoords[indices[i] * 2 + 1]); gl.glColor4f( colorNorm[indices[i] * 4], colorNorm[indices[i] * 4 + 1], colorNorm[indices[i] * 4 + 2], colorNorm[indices[i] * 4 + 3]); gl.glNormal3f( normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]); gl.glVertex3f( vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]); } gl.glEnd(); } else { gl.glEnable(gl.GL_BLEND); gl.glBegin(GL2.GL_TRIANGLE_STRIP); for (int i = 0; i < indices.length; i++) { gl.glColor4f( colors[indices[i] * 4], colors[indices[i] * 4 + 1], colors[indices[i] * 4 + 2], colors[indices[i] * 4 + 3]); gl.glNormal3f( normals[indices[i] * 3], normals[indices[i] * 3 + 1], normals[indices[i] * 3 + 2]); gl.glVertex3f( vertices[indices[i] * 3], vertices[indices[i] * 3 + 1], vertices[indices[i] * 3 + 2]); } gl.glEnd(); gl.glDisable(gl.GL_BLEND); } gl.glPopMatrix(); boolean showGrid = RenderConfiguration.showGridlines(); if (showGrid) { gl.glColor4f(0.5f, 0.5f, 0.5f, 1.0f); gl.glNormal3f(0.0f, 1.0f, 0.0f); gl.glLineWidth(1.0f); // do the horizontal gridlines /* gl.glBegin(GL2.GL_LINES); for (int j = 1; j < map.getHeight(); ++j) { gl.glVertex3f(0.0f, 0.0f, j); gl.glVertex3f(map.getWidth(), 0.0f, j); } gl.glEnd(); */ gl.glBegin(GL2.GL_LINE_STRIP); for (int j = 0; j < mapHeight; j++) { if ((j + 1) % DENSITY != 0) { continue; } if ((j + 1) % (DENSITY * 2) == 0) { for (int i = 0; i < mapWidth; i++) { Vector3f p; Vector3f pOne; Vector3f pTwo; pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j < mapHeight - 1 && i > 0) { pTwo = points[j + 1][i - 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j < mapHeight - 1) { pTwo = points[j + 1][i]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); } } else { for (int i = mapWidth - 1; i >= 0; i--) { Vector3f p; Vector3f pOne; Vector3f pTwo; pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j < mapHeight - 1) { pTwo = points[j + 1][i]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j < mapHeight - 1 && i > 0) { pTwo = points[j + 1][i - 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); } } } gl.glEnd(); // do the vertical gridlines /* gl.glBegin(GL2.GL_LINES); for (int j = 1; j < map.getWidth(); ++j) { gl.glVertex3f(j, 0.0f, 0.0f); gl.glVertex3f(j, 0.0f, map.getHeight()); } gl.glEnd(); */ gl.glBegin(GL2.GL_LINE_STRIP); for (int i = 0; i < mapWidth; i++) { if ((i + 1) % DENSITY != 0) { continue; } if ((i + 1) % (DENSITY * 2) == 0) { for (int j = 0; j < mapHeight; j++) { Vector3f p; Vector3f pOne; Vector3f pTwo; pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j > 0 && i < mapWidth - 1) { pTwo = points[j - 1][i + 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (i < mapWidth - 1) { pTwo = points[j][i + 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); } } else { for (int j = mapHeight - 1; j >= 0; j--) { Vector3f p; Vector3f pOne; Vector3f pTwo; pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (i < mapWidth - 1) { pTwo = points[j][i + 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); pOne = points[j][i]; p = new Vector3f(0.0f, 0.0f, 0.0f); p.add(pOne); if (j > 0 && i < mapWidth - 1) { pTwo = points[j - 1][i + 1]; p.add(pTwo); p.scale(.5f); } gl.glVertex3f(p.x, p.y + 0.01f, p.z); } } } gl.glEnd(); } }
public void draw(GL2 gl, Camera camera, Perspective3D perspective3d) { Photo photo = this.photo; gl.glDisable(GL2.GL_DEPTH_TEST); gl.glColor4f( (float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) photo.getTransparent()); // Enable Alpha Blending (disable alpha testing) gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA); gl.glEnable(GL2.GL_BLEND); gl.glDisable(GL2.GL_LIGHTING); gl.glEnable(GL2.GL_TEXTURE_2D); // XXX String textureName = photo.getPath(); TextureCoords tc = new TextureCoords(0, 0, 1, 1); if (textureName != null) { Texture texture = this.textureCacheService.getTexture(gl, textureName); // // switch to texture mode and push a new matrix on the stack // gl.glMatrixMode(GL2.GL_TEXTURE); // gl.glPushMatrix(); // // // check to see if the texture needs flipping // if (texture.getMustFlipVertically()) { // gl.glScaled(1, -1, 1); // gl.glTranslated(0, -1, 0); // } // // // switch to modelview matrix and push a new matrix on the stack // gl.glMatrixMode(GL2.GL_MODELVIEW); // gl.glPushMatrix(); // // // This is required to repeat textures // gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_REPEAT); // gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_REPEAT); // enable, bind texture.enable(gl); texture.bind(gl); tc = texture.getImageTexCoords(); } gl.glBegin(GL2.GL_POLYGON); // gl.glColor3f((float)123/256, (float)111/256, (float)100/255); // gl.glColor3f((float) 255/255, (float)255/255, (float)255/255); LatLon ll = new LatLon(photo.getLat(), photo.getLon()); Projection proj = Main.getProjection(); EastNorth eastNorth = proj.latlon2eastNorth(ll); double x = perspective3d.calcX(eastNorth.east()); double y = photo.getHeight(); double z = -perspective3d.calcY(eastNorth.north()); Vector3d angle = photo.getRotate(); double distance = 500d; double width = distance * Math.sin(photo.getAngleWitht() / 2d); double height = distance * Math.sin(photo.getAngleHeigth() / 2d); Vector3d p1 = new Vector3d(distance, -height, -width); Vector3d p2 = new Vector3d(distance, -height, width); Vector3d p3 = new Vector3d(distance, height, width); Vector3d p4 = new Vector3d(distance, height, -width); p1 = transform(angle, p1); p2 = transform(angle, p2); p3 = transform(angle, p3); p4 = transform(angle, p4); Point3d c = camera.getPoint(); // gl.glColor4f((float) 255/255, (float)255/255, (float)255/255, (float) 128/255); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_BLEND); gl.glTexCoord2d(tc.left(), tc.bottom()); gl.glVertex3d(p1.x + x, p1.y + y, p1.z + z); gl.glTexCoord2d(tc.right(), tc.bottom()); gl.glVertex3d(p2.x + x, p2.y + y, p2.z + z); gl.glTexCoord2d(tc.right(), tc.top()); gl.glVertex3d(p3.x + x, p3.y + y, p3.z + z); gl.glTexCoord2d(tc.left(), tc.top()); gl.glVertex3d(p4.x + x, p4.y + y, p4.z + z); gl.glEnd(); gl.glColor3f((float) 0 / 255, (float) 0 / 255, (float) 255 / 255); gl.glPushMatrix(); gl.glTranslated(x, 0.1, z); gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_MODULATE); DrawUtil.drawDotY(gl, 0.5, 12); gl.glPopMatrix(); if (textureName != null) { Texture texture = this.textureCacheService.getTexture(gl, textureName); Texture t = this.textureCacheService.getTexture(gl, textureName); // this.textures.get(mesh.materialID);// .get(mesh.materialID); if (t != null) { t.disable(gl); } gl.glMatrixMode(GL2.GL_TEXTURE); gl.glPopMatrix(); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glPopMatrix(); } gl.glDisable(GL2.GL_TEXTURE_2D); gl.glColor4f((float) 255 / 255, (float) 255 / 255, (float) 255 / 255, (float) 255 / 255); gl.glDisable(GL2.GL_BLEND); gl.glEnable(GL2.GL_DEPTH_TEST); }
public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); int cnt = 0; // Local Counter Variable gl.glColor3f(1.0f, 0.5f, 0.5f); // Set Color To Bright Red glPrint(gl, 50, 16, 1, "Renderer"); // Display Renderer glPrint(gl, 80, 48, 1, "Vendor"); // Display Vendor Name glPrint(gl, 66, 80, 1, "Version"); // Display Version gl.glColor3f(1.0f, 0.7f, 0.4f); // Set Color To Orange // Display Renderer glPrint(gl, 200, 16, 1, gl.glGetString(GL.GL_RENDERER)); glPrint(gl, 200, 48, 1, gl.glGetString(GL.GL_VENDOR)); // Display Vendor // Name glPrint(gl, 200, 80, 1, gl.glGetString(GL.GL_VERSION)); // Display // Version gl.glColor3f(0.5f, 0.5f, 1.0f); // Set Color To Bright Blue glPrint(gl, 192, 432, 1, "NeHe Productions"); // Write NeHe Productions // At The Bottom Of The // Screen gl.glLoadIdentity(); // Reset The ModelView Matrix gl.glColor3f(1.0f, 1.0f, 1.0f); // Set The Color To White gl.glBegin(GL.GL_LINE_STRIP); // Start Drawing Line Strips (Something // New) gl.glVertex2d(639, 417); // Top Right Of Bottom Box gl.glVertex2d(0, 417); // Top Left Of Bottom Box gl.glVertex2d(0, 480); // Lower Left Of Bottom Box gl.glVertex2d(639, 480); // Lower Right Of Bottom Box gl.glVertex2d(639, 128); // Up To Bottom Right Of Top Box gl.glEnd(); // Done First Line Strip gl.glBegin(GL.GL_LINE_STRIP); // Start Drawing Another Line Strip gl.glVertex2d(0, 128); // Bottom Left Of Top Box gl.glVertex2d(639, 128); // Bottom Right Of Top Box gl.glVertex2d(639, 1); // Top Right Of Top Box gl.glVertex2d(0, 1); // Top Left Of Top Box gl.glVertex2d(0, 417); // Down To Top Left Of Bottom Box gl.glEnd(); // Done Second Line Strip gl.glScissor( 1, (int) (0.135416f * sheight), swidth - 2, (int) (0.597916f * sheight)); // Define Scissor Region gl.glEnable(GL.GL_SCISSOR_TEST); // Enable Scissor Testing String text = gl.glGetString(GL.GL_EXTENSIONS); // Allocate Memory For // Our Extension String StringTokenizer tokenizer = new StringTokenizer(text); while (tokenizer.hasMoreTokens()) { // While The Token Isn't NULL cnt++; // Increase The Counter if (cnt > maxtokens) { // Is 'maxtokens' Less Than 'cnt' maxtokens = cnt; // If So, Set 'maxtokens' Equal To 'cnt' } gl.glColor3f(0.5f, 1.0f, 0.5f); // Set Color To Bright Green glPrint(gl, 0, 96 + (cnt * 32) - scroll, 0, "" + cnt); // Print // Current // Extension // Number gl.glColor3f(1.0f, 1.0f, 0.5f); // Set Color To Yellow // Print The Current Token (Parsed Extension Name) glPrint(gl, 50, 96 + (cnt * 32) - scroll, 0, tokenizer.nextToken()); } gl.glDisable(GL.GL_SCISSOR_TEST); // Disable Scissor Testing gl.glFlush(); // Flush The Rendering Pipeline }
public void draw(GL2 gl) { if (particles.size() == 0) return; switch (blendMode) { case 0: // '\0' gl.glDisable(3042); gl.glDisable(3008); break; case 1: // '\001' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(768, 1); break; case 2: // '\002' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(770, 1); break; case 3: // '\003' gl.glDisable(3042); gl.glEnable(3008); break; case 4: // '\004' gl.glEnable(3042); gl.glDisable(3008); gl.glBlendFunc(770, 1); break; } gl.glBindTexture(3553, model.mMaterials[texture].mTextureId); gl.glPushMatrix(); if (particleType == 0 || particleType == 2) { if ((flags & 0x1000) == 0) { Vec3 view = new Vec3(viewer.getCamera().getPosition()); view.normalize(); Vec3 right = Vec3.cross(view, new Vec3(0.0F, 0.0F, 1.0F)).normalize(); Vec3 up = Vec3.cross(right, view).normalize(); int tcStart = 0; if (flags == 0x40019) tcStart++; gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 cPos = new Vec3(); Vec3 ofs = new Vec3(); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile < texCoords.size()) { gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(right, up, ofs); cPos.set(p.pos); Vec3.sub(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[tcStart % 4].x, tc[tcStart % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.sub(right, up, ofs); Vec3.add(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 1) % 4].x, tc[(tcStart + 1) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(right, up, ofs); Vec3.add(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 2) % 4].x, tc[(tcStart + 2) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.sub(right, up, ofs); Vec3.sub(cPos, ofs.scale(p.size), pos); gl.glTexCoord2f(tc[(tcStart + 3) % 4].x, tc[(tcStart + 3) % 4].y); gl.glVertex3f(pos.x, pos.y, pos.z); } } gl.glEnd(); } else { gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 ofs = new Vec3(); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile < texCoords.size()) { gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(p.pos, Vec3.scale(p.corners[0], p.size, ofs), pos); gl.glTexCoord2f(tc[0].x, tc[0].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[1], p.size, ofs), pos); gl.glTexCoord2f(tc[1].x, tc[1].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[2], p.size, ofs), pos); gl.glTexCoord2f(tc[2].x, tc[2].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(p.corners[3], p.size, ofs), pos); gl.glTexCoord2f(tc[3].x, tc[3].y); gl.glVertex3f(pos.x, pos.y, pos.z); } } gl.glEnd(); } } else if (particleType == 1) { gl.glBegin(7); int count = particles.size(); Vec3 pos = new Vec3(); Vec3 ofs = new Vec3(); float f = 1.0F; Vec3 bv0 = new Vec3(-f, f, 0.0F); Vec3 bv1 = new Vec3(f, f, 0.0F); for (int i = 0; i < count; i++) { Particle p = (Particle) particles.get(i); if (p.tile >= texCoords.size() - 1) break; gl.glColor4f(p.color.x, p.color.y, p.color.z, p.color.w); Point2f tc[] = (Point2f[]) texCoords.get(p.tile); Vec3.add(p.pos, Vec3.scale(bv0, p.size, ofs), pos); gl.glTexCoord2f(tc[0].x, tc[0].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.pos, Vec3.scale(bv1, p.size, ofs), pos); gl.glTexCoord2f(tc[1].x, tc[1].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.origin, Vec3.scale(bv1, p.size, ofs), pos); gl.glTexCoord2f(tc[2].x, tc[2].y); gl.glVertex3f(pos.x, pos.y, pos.z); Vec3.add(p.origin, Vec3.scale(bv0, p.size, ofs), pos); gl.glTexCoord2f(tc[3].x, tc[3].y); gl.glVertex3f(pos.x, pos.y, pos.z); } gl.glEnd(); } gl.glPopMatrix(); }