public void displayInit(Point pickPoint) { gl.glShadeModel(GL.GL_SMOOTH); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); if (pickPoint != null) { int[] vp = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0); GLU glu = new GLU(); int px = (int) pickPoint.getX(); int py = (int) (vp[3] - pickPoint.getY()); glu.gluPickMatrix(px, py, 1e-2, 1e-2, vp, 0); } gl.glOrtho(0, bounds.getWidth(), 0, bounds.getHeight(), .1, depth); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(0, 0, depth - 0.1, 0, 0, 0, 0, 1, 0); gl.glInitNames(); gl.glPushName(-1); }
public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) { GL gl = gLDrawable.getGL(); float h = (float) width / (float) height; gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-h, h, -1, 1, 1, 600); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -6f); }
public void setOrthographicView(int w, int h) { gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluOrtho2D(0.0, w, 0.0, h); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { _gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); _gl.glViewport(0, 0, width, height); // 視体積の設定 _gl.glMatrixMode(GL.GL_PROJECTION); _gl.glLoadIdentity(); // 見る位置 _gl.glMatrixMode(GL.GL_MODELVIEW); _gl.glLoadIdentity(); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); GLU glu = new GLU(); if (height <= 0) { height = 1; } final float h = (float) width / (float) height; gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, h, 1.0, 20.0); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
/** * レンダリング環境のセットアップ * * @param gcon */ public void begin(GraphicContext gcon) { GraphicContextJogl gc = (GraphicContextJogl) gcon; GL gl = gc.getGL(); if ((state_ & CLEAR) == CLEAR) { gl.glClearColor(r_, g_, b_, 1.0f); // カラープレーン初期値 gl.glClearDepth(1.0); // デプスバッファの初期値 gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); } gl.glEnable(GL.GL_DEPTH_TEST); // デプスバッファをイネーブル gl.glDepthFunc(GL.GL_LESS); // デプスバッファの計算法指定 gl.glDepthMask(true); // デプスバッファをリードライト gl.glEnable(GL.GL_LIGHTING); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); float right = (float) (near_ * Math.tan(fovx_ / 2)); float left = -right; float top = right * aspect_; float bottom = -top; gl.glFrustum(left, right, bottom, top, near_, far_); buildViewMatrix(); gc.setViewMatrix(viewMatrix_); }
public final void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); this.applyCameraAdjustment(gl); long t = System.currentTimeMillis(); long dt = t - tprec; tprec = t; mdx.update(dt); renderReference(gl, ORIGIN, X_AXIS.clone(), Y_AXIS.clone(), Z_AXIS.clone()); renderReferences(gl); gl.glColor3f(1.0f, 1.0f, 1.0f); int[] temp = selector.getGeoOn(); if (temp != null) { for (int i = 0; i < temp.length; ++i) this.renderNonBlending(mdx.getGeoset(temp[i]), gl); for (int i = 0; i < temp.length; ++i) this.renderBlending(mdx.getGeoset(temp[i]), gl); } }
public void updateSelectedOctant(GL gl, GLU glu, float[] mousePosition, float[] pickRectangle) { // Start Picking mode int capacity = 1 * 4 * visibleLeaves.size(); // Each object take in maximium : 4 * name stack depth IntBuffer hitsBuffer = BufferUtil.newIntBuffer(capacity); gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer); gl.glRenderMode(GL.GL_SELECT); gl.glDisable(GL.GL_CULL_FACE); // Disable flags gl.glInitNames(); gl.glPushName(0); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); glu.gluPickMatrix( mousePosition[0], mousePosition[1], pickRectangle[0], pickRectangle[1], drawable.getViewport()); gl.glMultMatrixd(drawable.getProjectionMatrix()); gl.glMatrixMode(GL.GL_MODELVIEW); // Draw the nodes' cube int the select buffer int hitName = 1; for (int i = 0; i < visibleLeaves.size(); i++) { Octant node = visibleLeaves.get(i); gl.glLoadName(hitName); node.displayOctant(gl); hitName++; } // Restoring the original projection matrix gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glFlush(); // Returning to normal rendering mode int nbRecords = gl.glRenderMode(GL.GL_RENDER); if (vizController.getVizModel().isCulling()) { gl.glEnable(GL.GL_CULL_FACE); gl.glCullFace(GL.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); } }
// Method for handling window resizing public void projection(GL gl, int width, int height) { gl.glViewport(0, 0, width, height); double aspect = (double) width / height; double l, r, b, t, n; // Move near plane closer, but also shrink frustum so that // field-of-view stays the same -- this way not much stuff // gets clipped double zoom = 10; // Preserve aspect ratio if (aspect > 1) { r = aspect / zoom; t = 1 / zoom; } else { r = 1 / zoom; t = 1 / (zoom * aspect); } // Window has (0,0) in center l = -r; b = -t; // Set near plane location // (making this smaller reduces the field-of-view) n = 2; // Set the world projection gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(l, r, b, t, n / zoom, 500); gl.glMatrixMode(GL.GL_MODELVIEW); }
/** OpenGL drawing function */ @Override public void display(GLAutoDrawable auto_drawable) { // get the GL context final GL gl = auto_drawable.getGL(); // clear the buffers gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // load the identity matrix gl.glLoadIdentity(); // translations so we can see drawing gl.glTranslatef(0, 0, -0.7f); if (LoadTexturePosted == true) { if (LoadGuessModelPosted == null) System.err.println("ERROR: LoadGuessModelPosted is null!"); current_Texture = AnimalTexture.findAnimalTexture(Animal_Tex_Array, LoadGuessModelPosted.getAnimalName()); LoadTexturePosted = false; } // if the current texture is null, load the question texture if (current_Texture == null) question_Texture.bind(); else current_Texture.bind(); // draw the cube gl.glPushMatrix(); gl.glRotatef(yrotate, 0.0f, 1.0f, 0.0f); drawOpenCube(gl); gl.glPopMatrix(); // increase rotation yrotate += 0.05; }
/** OpenGL reshape function Perspective and view calls go here */ @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { final GL gl = drawable.getGL(); final GLU glu = new GLU(); gl.setSwapInterval(1); gl.glViewport(0, 0, width, height); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(45.0f, (double) width / (double) height, 0.1f, 1000.0f); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); }
public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) { GL gl = drawable.getGL(); gl.glViewport(0, 0, w, h); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, w, 0, h, -1.0, 1.0); gl.glMatrixMode(GL.GL_MODELVIEW); }
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { GL gl = drawable.getGL(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); // JOptionPane.showMessageDialog(App.getInstance().getMainWindow(), width + "x" + height); // //TEST gl.glViewport(0, 0, width, height); gl.glOrtho(0, width, height, 0, 0, 128); // notify view controller.resize(); }
public void draw(GL gl, double xpos, double ypos, double rot) { if (gl != null) { gl.glLoadIdentity(); gl.glTranslated(xpos, ypos, 0); gl.glRotated(rot + rotoffset, 0, 0, 1); for (Line l : lines) { l.draw(gl, 0, 0); } // gl.glFlush(); } }
public final void reshape( final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) { Debug.print(); final GL gl = drawable.getGL(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum( -1.0f, 1.0f, -1.0f, 1.0f, this.camera.getNearZClipping(), this.camera.getFarZClipping()); gl.glViewport(x, y, width, height); }
public void display(GL gl, float time, int screenWidth, int screenHeight) { // TODO: most of this only needs to be done once per frame, not per button. if (!visible) { return; } gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); if (flipx) { gl.glTranslatef(1.0f, 0.0f, 0.0f); gl.glScalef(-1.0f, 1.0f, 1.0f); } if (flipy) { gl.glTranslatef(0.0f, 1.0f, 0.0f); gl.glScalef(1.0f, -1.0f, 1.0f); } gl.glScalef(1.0f / screenWidth, 1.0f / screenHeight, 1.0f); if (isSelected() || (mDown && mOver)) { gl.glColor3f(0.6f, 0.6f, 0.8f); } else { gl.glColor3f(0.8f, 0.8f, 0.8f); } gl.glActiveTexture(GL.GL_TEXTURE0); marble.enable(); marble.bind(); gl.glMatrixMode(GL.GL_TEXTURE); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glBegin(GL.GL_POLYGON); for (int n = 0; n < buttonShape.npoints; n++) { gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2); gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -0.5f); } gl.glEnd(); tex.enable(); tex.bind(); gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); gl.glBegin(GL.GL_POLYGON); for (int n = 0; n < buttonShape.npoints; n++) { gl.glTexCoord2f(n / 2, (n + n / 2 + 1) % 2); gl.glVertex3f(buttonShape.xpoints[n], buttonShape.ypoints[n], -1.0f); } gl.glEnd(); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); }
void glSpiral(final GL gl, Node aref, HashSet<Node> cluster) { int i = 0; float r = 0; float matrix[] = new float[16]; for (Node bref : cluster) { if (bref != null) { i++; r = spiral_rad(aref, i); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glTranslatef(aref.pos.x, aref.pos.y, aref.pos.z); gl.glRotatef(spiral_angle(aref, i), 0, 0, 1); gl.glTranslatef(-r, 0, 0); gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0); bref.pos.setXYZ(matrix[12], matrix[13], matrix[14]); gl.glPopMatrix(); } } }
public void applyInternalTransform(DrawContext dc) { if (dc == null) { String message = Logging.getMessage("nullValue.DrawContextIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } Texture texture = this.getTexture(dc); if (texture == null) texture = this.requestTexture(dc); if (texture == null) return; if (texture.getMustFlipVertically()) { GL gl = GLContext.getCurrent().getGL(); gl.glMatrixMode(GL.GL_TEXTURE); gl.glLoadIdentity(); gl.glScaled(1, -1, 1); gl.glTranslated(0, -1, 0); } }
private void clusterCircle(final GL gl, float xRot, float yRot, Node aref) { aref.spiralcluster = false; int jcount = 0; float matrix[] = new float[16]; float rad = aref.cluster.size(); float clusterDist = calcClusterDistance(aref); for (Node bref : aref.cluster) { if (bref != null) { gl.glPushMatrix(); gl.glLoadIdentity(); gl.glTranslatef(aref.pos.x, aref.pos.y, aref.pos.z); // gl.glRotatef(xRot, 0, 1, 0); // gl.glRotatef(yRot, 1, 0, 0); gl.glRotatef(90 + 360 * jcount / rad, 0, 0, 1); gl.glTranslatef(-clusterDist, 0, 0); gl.glGetFloatv(GL.GL_MODELVIEW_MATRIX, matrix, 0); bref.pos.setXYZ(matrix[12], matrix[13], matrix[14]); gl.glPopMatrix(); jcount++; } } }
public void prerenderToTexture(GL gl) { int texSize = 256; final int[] tmp = new int[1]; gl.glGenTextures(1, tmp, 0); textureID = tmp[0]; gl.glBindTexture(GL_TEXTURE_2D, textureID); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); gl.glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, texSize, texSize, 0, GL_BGRA, GL_UNSIGNED_BYTE, null); final int[] fbo = new int[1]; gl.glGenFramebuffersEXT(1, IntBuffer.wrap(fbo)); gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[0]); gl.glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, textureID, 0); gl.glDrawBuffers(1, IntBuffer.wrap(new int[] {GL_COLOR_ATTACHMENT0_EXT})); final int[] rba = new int[1]; gl.glGenRenderbuffersEXT(1, IntBuffer.wrap(rba)); gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, rba[0]); gl.glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, texSize, texSize); gl.glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, rba[0]); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glPushAttrib(GL_VIEWPORT_BIT); gl.glViewport(0, 0, texSize, texSize); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glOrtho(0, texSize, 0, texSize, 0, 10); gl.glMatrixMode(GL.GL_MODELVIEW); Set<MapElement> map = State.getInstance().getMapInfo().queryElements(detailLevel, bounds, true); gl.glDisable(GL_TEXTURE_2D); gl.glColor3f(1, 1, 1); for (MapElement element : map) { if (element instanceof Street) { drawLine( gl, ((Street) element).getDrawingSize() / (float) Projection.getZoomFactor(detailLevel), ((Street) element).getNodes()); } } gl.glColor3f(0.3f, 0.3f, 0.3f); for (MapElement element : map) { if ((element instanceof Area) && (((Area) element).getWayInfo().isBuilding())) { gl.glBegin(GL_POLYGON); for (Node node : ((Area) element).getNodes()) { Coordinates pos = getLocalCoordinates(node.getPos()); gl.glVertex3f(pos.getLongitude(), pos.getLatitude(), 0f); } gl.glEnd(); } } gl.glEnable(GL_TEXTURE_2D); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopAttrib(); gl.glPopMatrix(); gl.glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); gl.glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); gl.glDeleteFramebuffersEXT(1, fbo, 0); gl.glDeleteRenderbuffersEXT(1, rba, 0); }
void redraw(GL gl) { GOut g = new GOut(gl, getContext(), MainFrame.getInnerSize()); synchronized (ui) { ui.update(); } if (Config.render_enable) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, getWidth(), 0, getHeight(), -1, 1); TexRT.renderall(g); if (curf != null) curf.tick("texrt"); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); gl.glOrtho(0, getWidth(), getHeight(), 0, -1, 1); gl.glClearColor(0, 0, 0, 1); gl.glClear(GL.GL_COLOR_BUFFER_BIT); if (curf != null) curf.tick("cls"); synchronized (ui) { ui.draw(g); } if (curf != null) curf.tick("draw"); if (Config.dbtext) { g.atext("FPS: " + fps, new Coord(10, 545), 0, 1); g.atext("Texhit: " + dth, new Coord(10, 530), 0, 1); g.atext("Texmiss: " + dtm, new Coord(10, 515), 0, 1); Runtime rt = Runtime.getRuntime(); long free = rt.freeMemory(), total = rt.totalMemory(); g.atext( String.format( "Mem: %,011d/%,011d/%,011d/%,011d", free, total - free, total, rt.maxMemory()), new Coord(10, 500), 0, 1); g.atext( String.format("LCache: %d/%d", Layered.cache.size(), Layered.cache.cached()), new Coord(10, 485), 0, 1); g.atext( String.format("RT-current: %d", TexRT.current.get(gl).size()), new Coord(10, 470), 0, 1); if (Resource.qdepth() > 0) g.atext( String.format("RQ depth: %d (%d)", Resource.qdepth(), Resource.numloaded()), new Coord(10, 455), 0, 1); } Object tooltip = ui.root.tooltip(mousepos, true); Tex tt = null; if (tooltip != null) { if (tooltip instanceof Text) { tt = ((Text) tooltip).tex(); } else if (tooltip instanceof Tex) { tt = (Tex) tooltip; } else if (tooltip instanceof String) { if (((String) tooltip).length() > 0) tt = (Text.render((String) tooltip)).tex(); } } if (tt != null) { Coord sz = tt.sz(); Coord pos = mousepos.add(sz.inv()); if (pos.x < 0) pos.x = 0; if (pos.y < 0) pos.y = 0; g.chcolor(244, 247, 21, 192); g.rect(pos.add(-3, -3), sz.add(6, 6)); g.chcolor(35, 35, 35, 192); g.frect(pos.add(-2, -2), sz.add(4, 4)); g.chcolor(); g.image(tt, pos); } } Resource curs = ui.root.getcurs(mousepos); if (!curs.loading) { if (cursmode == "awt") { if (curs != lastcursor) { try { setCursor(makeawtcurs(curs.layer(Resource.imgc).img, curs.layer(Resource.negc).cc)); ark.bot.cursor_name = curs.name; ark.bot.cursor_name = ark.bot.cursor_name.replace("gfx/hud/curs/", ""); lastcursor = curs; } catch (Exception e) { cursmode = "tex"; } } } else if (cursmode == "tex") { Coord dc = mousepos.add(curs.layer(Resource.negc).cc.inv()); g.image(curs.layer(Resource.imgc), dc); } } }
/** Here we actually draw the scene. */ public void display(GLAutoDrawable drawable) { super.display(drawable); System.out.println("GLScene - display"); GL gl = drawable.getGL(); try { // Update velocities and positions of all text float deltaT = 0.1f; Point2f tmp = new Point2f(); for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); // Randomize things a little bit at run time if (random.nextInt(1000) == 0) { info.angularVelocity = INIT_ANG_VEL_MAG * (randomAngle() - 180); info.velocity = randomVelocity(INIT_VEL_MAG, INIT_VEL_MAG); } // Now update angles and positions info.angle += info.angularVelocity * deltaT; tmp.set(info.velocity); tmp.scale(deltaT); info.position.add(tmp); // Update color info.curTime += deltaT; if (info.curTime > 2 * Math.PI) { info.curTime -= 2 * Math.PI; } int rgb = Color.HSBtoRGB(info.h, (float) (0.5 * (1 + Math.sin(info.curTime)) * info.s), info.v); info.r = ((rgb >> 16) & 0xFF) / 255.0f; info.g = ((rgb >> 8) & 0xFF) / 255.0f; info.b = (rgb & 0xFF) / 255.0f; // Wrap angles and positions if (info.angle < 0) { info.angle += 360; } else if (info.angle > 360) { info.angle -= 360; } // Use maxTextWidth to avoid popping in/out at edges // Would be better to do oriented bounding rectangle computation if (info.position.x < -maxTextWidth) { info.position.x = info.position.x + glComposite.getCanvas().getWidth() + 2 * maxTextWidth; } else if (info.position.x > glComposite.getCanvas().getWidth() + maxTextWidth) { info.position.x = info.position.x - glComposite.getCanvas().getWidth() - 2 * maxTextWidth; } if (info.position.y < -maxTextWidth) { info.position.y = info.position.y + glComposite.getCanvas().getHeight() + 2 * maxTextWidth; } else if (info.position.y > glComposite.getCanvas().getHeight() + maxTextWidth) { info.position.y = info.position.y - glComposite.getCanvas().getHeight() - 2 * maxTextWidth; } } gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glComposite .getGLU() .gluOrtho2D( 0, glComposite.getCanvas().getWidth(), 0, glComposite.getCanvas().getHeight()); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); // Draw the background texture backgroundTexture.enable(); backgroundTexture.bind(); TextureCoords coords = backgroundTexture.getImageTexCoords(); int w = glComposite.getCanvas().getWidth(); int h = glComposite.getCanvas().getHeight(); float fw = w / 100.0f; float fh = h / 100.0f; gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(fw * coords.left(), fh * coords.bottom()); gl.glVertex3f(0, 0, 0); gl.glTexCoord2f(fw * coords.right(), fh * coords.bottom()); gl.glVertex3f(w, 0, 0); gl.glTexCoord2f(fw * coords.right(), fh * coords.top()); gl.glVertex3f(w, h, 0); gl.glTexCoord2f(fw * coords.left(), fh * coords.top()); gl.glVertex3f(0, h, 0); gl.glEnd(); backgroundTexture.disable(); // Render all text renderer.beginRendering(w, h); // Note we're doing some slightly fancy stuff to position the text. // We tell the text renderer to render the text at the origin, and // manipulate the modelview matrix to put the text where we want. gl.glMatrixMode(GL.GL_MODELVIEW); // First render drop shadows renderer.setColor(0, 0, 0, 0.5f); for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); gl.glLoadIdentity(); gl.glTranslatef( info.position.x + dropShadowDistance, info.position.y - dropShadowDistance, 0); gl.glRotatef(info.angle, 0, 0, 1); renderer.draw(info.text, 0, 0); renderer.flush(); } // Now render the actual text for (Iterator<TextInfo> iter = textInfo.iterator(); iter.hasNext(); ) { TextInfo info = (TextInfo) iter.next(); gl.glLoadIdentity(); gl.glTranslatef(info.position.x, info.position.y, 0); gl.glRotatef(info.angle, 0, 0, 1); renderer.setColor(info.r, info.g, info.b, 1); renderer.draw(info.text, 0, 0); renderer.flush(); } renderer.endRendering(); } catch (Exception e) { e.printStackTrace(); } }
public void display(GLAutoDrawable gLDrawable) { key = Input.keysPressed(); double dt = (System.currentTimeMillis() - dt_timer) / 1000.0; dt_timer = System.currentTimeMillis(); // Start 3d Rendering GL gl = gLDrawable.getGL(); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); GLU glu = new GLU(); // Code to adjust camera if (input.getKey(KeyEvent.VK_UP)) z -= .5 * dt; if (input.getKey(KeyEvent.VK_DOWN)) z += .5 * dt; if (input.getKey(KeyEvent.VK_LEFT)) y -= .5 * dt; if (input.getKey(KeyEvent.VK_RIGHT)) y += .5 * dt; if (input.getKey(KeyEvent.VK_SPACE)) System.out.println(y + " " + z); glu.gluLookAt(0, y, z, 0, 0, -3, 0, 1, 0); // orangeNote.drawBar(gLDrawable, zTest); // redNote.draw(gLDrawable, -3f, -4f, zTest); // yellowNote.draw(gLDrawable, -1.5f, -4f, zTest); // blueNote.draw(gLDrawable, 0f, -4f, zTest); // greenNote.draw(gLDrawable, 1.5f, -4f, zTest); zTest += 0.005f; if (zTest > -2f) zTest = -10f; gl.glPushMatrix(); gl.glEnable(GL.GL_BLEND); // gl.glRotatef(70,1,-2,1); gl.glBegin(GL.GL_QUADS); // Draw the Board // x goes basically from -1 to 1(camera changed tho) // y stays same // board length is -z gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); // R,G,B,A gl.glVertex3f(-3f, -4f, 0f); // x,y,z gl.glColor4f(40 / 256f, 100 / 256f, 150 / 256f, 1f); gl.glVertex3f(3f, -4f, 0f); gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f); gl.glVertex3f(3f, -4f, -10f); gl.glColor4f(60 / 256f, 150 / 256f, 200 / 256f, 0f); gl.glVertex3f(-3f, -4f, -10f); // All y values on top of the Board must have at least // 0.0001f added for some reason // Bottom bar - Orange gl.glColor4f(255 / 256f, 165 / 256f, 0 / 256f, 1f); gl.glVertex3f(-3f, -4f + .0001f, -2.15f); // close left gl.glVertex3f(3f, -4f + .0001f, -2.15f); // close right gl.glVertex3f(3f, -4f + .0001f, -2.85f); // far right gl.glVertex3f(-3f, -4f + .0001f, -2.85f); // far left // RedNote gl.glColor4f(1f, 0f, 0f, 1f); gl.glVertex3f(-3f, -4f + .001f, -2.25f); gl.glVertex3f(-1.5f, -4f + .001f, -2.25f); gl.glVertex3f(-1.5f, -4f + .001f, -2.75f); gl.glVertex3f(-3f, -4f + .001f, -2.75f); // YellowNote gl.glColor4f(1f, 1f, 0f, 1f); gl.glVertex3f(-1.5f, -4f + .001f, -2.25f); gl.glVertex3f(0f, -4f + .001f, -2.25f); gl.glVertex3f(0f, -4f + .001f, -2.75f); gl.glVertex3f(-1.5f, -4f + .001f, -2.75f); // BlueNote gl.glColor4f(0f, 0f, 1f, 1f); gl.glVertex3f(0f, -4f + .001f, -2.25f); gl.glVertex3f(1.5f, -4f + .001f, -2.25f); gl.glVertex3f(1.5f, -4f + .001f, -2.75f); gl.glVertex3f(0f, -4f + .001f, -2.75f); // GreenNote gl.glColor4f(0f, 1f, 0f, 1f); gl.glVertex3f(1.5f, -4f + .001f, -2.25f); gl.glVertex3f(3f, -4f + .001f, -2.25f); gl.glVertex3f(3f, -4f + .001f, -2.75f); gl.glVertex3f(1.5f, -4f + .001f, -2.75f); // End Bottom Bar this.renderNotes(gLDrawable, dt); ///////////////////////////////////// gl.glEnd(); gl.glDisable(GL.GL_BLEND); gl.glPopMatrix(); try { Thread.sleep(1); } catch (Exception e) { } }
protected void drawIcon(DrawContext dc) { if (this.getIconFilePath() == null) return; GL gl = dc.getGL(); OGLStackHandler ogsh = new OGLStackHandler(); try { // Initialize texture if necessary Texture iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath()); if (iconTexture == null) { this.initializeTexture(dc); iconTexture = dc.getTextureCache().getTexture(this.getIconFilePath()); if (iconTexture == null) { String msg = Logging.getMessage("generic.ImageReadFailed"); Logging.logger().finer(msg); return; } } gl.glDisable(GL.GL_DEPTH_TEST); double width = this.getScaledIconWidth(); double height = this.getScaledIconHeight(); // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight) // into the GL projection matrix. java.awt.Rectangle viewport = dc.getView().getViewport(); ogsh.pushProjectionIdentity(gl); double maxwh = width > height ? width : height; gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh); // Translate and scale ogsh.pushModelviewIdentity(gl); double scale = this.computeScale(viewport); Vec4 locationSW = this.computeLocation(viewport, scale); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); // Scale to 0..1 space gl.glScaled(scale, scale, 1); gl.glScaled(width, height, 1d); if (!dc.isPickingMode()) { gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); // Draw background color behind the map gl.glColor4ub( (byte) this.backColor.getRed(), (byte) this.backColor.getGreen(), (byte) this.backColor.getBlue(), (byte) (this.backColor.getAlpha() * this.getOpacity())); dc.drawUnitQuad(); // Draw world map icon gl.glColor4d(1d, 1d, 1d, this.getOpacity()); gl.glEnable(GL.GL_TEXTURE_2D); iconTexture.bind(); TextureCoords texCoords = iconTexture.getImageTexCoords(); dc.drawUnitQuad(texCoords); gl.glBindTexture(GL.GL_TEXTURE_2D, 0); gl.glDisable(GL.GL_TEXTURE_2D); // Draw crosshair for current location gl.glLoadIdentity(); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); // Scale to width x height space gl.glScaled(scale, scale, 1); // Set color float[] colorRGB = this.color.getRGBColorComponents(null); gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity()); // Draw crosshair Position groundPos = this.computeGroundPosition(dc, dc.getView()); if (groundPos != null) { int x = (int) (width * (groundPos.getLongitude().degrees + 180) / 360); int y = (int) (height * (groundPos.getLatitude().degrees + 90) / 180); int w = 10; // cross branch length // Draw gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(x - w, y, 0); gl.glVertex3d(x + w + 1, y, 0); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(x, y - w, 0); gl.glVertex3d(x, y + w + 1, 0); gl.glEnd(); } // Draw view footprint in map icon space if (this.showFootprint) { this.footPrintPositions = this.computeViewFootPrint(dc, 32); if (this.footPrintPositions != null) { gl.glBegin(GL.GL_LINE_STRIP); LatLon p1 = this.footPrintPositions.get(0); for (LatLon p2 : this.footPrintPositions) { int x = (int) (width * (p2.getLongitude().degrees + 180) / 360); int y = (int) (height * (p2.getLatitude().degrees + 90) / 180); // Draw if (LatLon.locationsCrossDateline(p1, p2)) { int y1 = (int) (height * (p1.getLatitude().degrees + 90) / 180); gl.glVertex3d(x < width / 2 ? width : 0, (y1 + y) / 2, 0); gl.glEnd(); gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(x < width / 2 ? 0 : width, (y1 + y) / 2, 0); } gl.glVertex3d(x, y, 0); p1 = p2; } gl.glEnd(); } } // Draw 1px border around and inside the map gl.glBegin(GL.GL_LINE_STRIP); gl.glVertex3d(0, 0, 0); gl.glVertex3d(width, 0, 0); gl.glVertex3d(width, height - 1, 0); gl.glVertex3d(0, height - 1, 0); gl.glVertex3d(0, 0, 0); gl.glEnd(); } else { // Picking this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); // Where in the world are we picking ? Position pickPosition = computePickPosition( dc, locationSW, new Dimension((int) (width * scale), (int) (height * scale))); Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); this.pickSupport.addPickableObject(colorCode, this, pickPosition, false); gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); dc.drawUnitQuad(); this.pickSupport.endPicking(dc); this.pickSupport.resolvePick(dc, dc.getPickPoint(), this); } } finally { dc.restoreDefaultDepthTesting(); dc.restoreDefaultCurrentColor(); if (dc.isPickingMode()) dc.restoreDefaultBlending(); ogsh.pop(gl); } }
/** * Draws the five sides of the hemicube into the provided drawable * * @param drawable * @param which * @param near * @param far * @param bCollect */ public void drawHemiCube( GLAutoDrawable drawable, int which, double near, double far, boolean bCollect) { // TODO - PART 1 - DRAW HEMICUBE! GL gl = drawable.getGL(); GLU glu = new GLU(); /* Return the face based on which parameter */ int[] vertices = scene.getObject().getFace(which); /* Find the center of the face */ /* Center of the face is the average of the three vertices */ /* Using returned list of vertex indices, find the vertices * corresponding to a particular face */ Vertex v1 = scene.getObject().vertexList.get(vertices[0]); Vertex v2 = scene.getObject().vertexList.get(vertices[1]); Vertex v3 = scene.getObject().vertexList.get(vertices[2]); /* Locate center of face */ /* Average of three vertices */ Point3d centerPoint = new Point3d(); centerPoint = new Point3d(v1.p); centerPoint.add(v2.p); centerPoint.add(v3.p); centerPoint.scale(0.33333); /* Set up camera frame */ /* --- Surface normal --- */ /* Declare points of vertex for face */ Point3d p1 = new Point3d(v1.p); Point3d p2 = new Point3d(v2.p); Point3d p3 = new Point3d(v3.p); /* Declare vector u as p2-p1 */ Point3d uVec = new Point3d(p2); uVec.sub(p1); Vector3d u = new Vector3d(uVec); /* Declare vector v as p3-p1 */ Point3d vVec = new Point3d(p3); vVec.sub(p1); Vector3d v = new Vector3d(vVec); /* Make normal vector */ Vector3d norm = new Vector3d(); norm.cross(u, v); /* --- Vectors Orthonormal to Normal --- */ Point3d vec1pt = new Point3d(p1); vec1pt.sub(p2); Vector3d vec1 = new Vector3d(vec1pt); vec1.cross(vec1, norm); // Cross surface normal with vec1 to get orthogonal vector Vector3d vec2 = new Vector3d(); vec2.cross( norm, vec1); // Cross product of surface normal with new vector vec1 to get 2nd orthogonal vector /* Make unit vectors */ norm.normalize(); vec1.normalize(); vec2.normalize(); /* Set up the five different frustums, and stitch together using viewPort */ /* Viewport to set up the view of the scene */ /* ----- FRONT FACE ----- */ gl.glPushMatrix(); gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight() / 3); /* Set up frustums for this face */ gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + norm.x, centerPoint.y + norm.y, centerPoint.z + norm.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- BOTTOM FACE ----- */ gl.glPushMatrix(); gl.glViewport(0, drawable.getHeight() / 3, drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, 0, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + (-vec1.x), centerPoint.y + (-vec1.y), centerPoint.z + (-vec1.z), centerPoint.x + norm.x, centerPoint.y + norm.y, centerPoint.z + norm.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- TOP FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(-near, near, -near, 0, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z, centerPoint.x - norm.x, centerPoint.y - norm.y, centerPoint.z - norm.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- LEFT FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + 2 * (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(0, near, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + vec2.x, centerPoint.y + vec2.y, centerPoint.z + vec2.z, centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ----- RIGHT FACE ----- */ gl.glPushMatrix(); gl.glViewport( 0, (drawable.getHeight() / 3) + 3 * (drawable.getHeight() / 6), drawable.getWidth(), drawable.getHeight() / 6); gl.glMatrixMode(gl.GL_PROJECTION); gl.glLoadIdentity(); gl.glFrustum(near, 0, -near, near, near, far); /* Position camera at center of specified patch (which) */ gl.glMatrixMode(gl.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt( centerPoint.x, centerPoint.y, centerPoint.z, centerPoint.x + (-vec2.x), centerPoint.y + (-vec2.y), centerPoint.z + (-vec2.z), centerPoint.x + vec1.x, centerPoint.y + vec1.y, centerPoint.z + vec1.z); /* Draw the frustum to screen */ draw(drawable, scene.drawStyle.IDENT); gl.glPopMatrix(); /* ---- End Frustums ---- */ // if collecting the form factors, then read back and process the data if (bCollect) { gl.glFlush(); gl.glFinish(); gl.glReadPixels( 0, 0, divisions * 2, divisions * 6, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelDataBuffer); collectData(which); } }
@Override public void render(final DrawContext dc) { // _lastDC = dc; runFrameWorkers(); final GTexture texture = getTexture(); if ((texture == null) || !texture.hasGLTexture()) { return; } final GL gl = dc.getGL(); gl.glPushAttrib( GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_TRANSFORM_BIT | GL.GL_VIEWPORT_BIT | GL.GL_CURRENT_BIT); gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glDisable(GL.GL_DEPTH_TEST); // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight) // into the GL projection matrix. final Rectangle viewport = dc.getView().getViewport(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); final double maxwh = Math.max(_textureWidth, _textureHeight); gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); // Translate and scale final float scale = computeScale(viewport); final Vec4 locationSW = computeLocation(viewport, scale); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); // Scale to 0..1 space gl.glScalef(scale, scale, 1f); gl.glScaled(_textureWidth, _textureHeight, 1d); _lastScreenBounds = calculateScreenBounds(viewport, locationSW, scale); texture.enable(); texture.bind(); gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE); gl.glColor4f(1, 1, 1, calculateOpacity()); dc.drawUnitQuad(texture.getImageTexCoords()); texture.disable(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); gl.glPopAttrib(); }
// Rendering public void draw(DrawContext dc) { GL gl = dc.getGL(); boolean attribsPushed = false; boolean modelviewPushed = false; boolean projectionPushed = false; try { gl.glPushAttrib( GL.GL_DEPTH_BUFFER_BIT | GL.GL_COLOR_BUFFER_BIT | GL.GL_ENABLE_BIT | GL.GL_TEXTURE_BIT | GL.GL_TRANSFORM_BIT | GL.GL_VIEWPORT_BIT | GL.GL_CURRENT_BIT); attribsPushed = true; gl.glDisable(GL.GL_TEXTURE_2D); // no textures gl.glEnable(GL.GL_BLEND); gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA); gl.glDisable(GL.GL_DEPTH_TEST); double width = this.size.width; double height = this.size.height; // Load a parallel projection with xy dimensions (viewportWidth, viewportHeight) // into the GL projection matrix. java.awt.Rectangle viewport = dc.getView().getViewport(); gl.glMatrixMode(javax.media.opengl.GL.GL_PROJECTION); gl.glPushMatrix(); projectionPushed = true; gl.glLoadIdentity(); double maxwh = width > height ? width : height; gl.glOrtho(0d, viewport.width, 0d, viewport.height, -0.6 * maxwh, 0.6 * maxwh); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); modelviewPushed = true; gl.glLoadIdentity(); // Scale to a width x height space // located at the proper position on screen double scale = this.computeScale(viewport); Vec4 locationSW = this.computeLocation(viewport, scale); gl.glTranslated(locationSW.x(), locationSW.y(), locationSW.z()); gl.glScaled(scale, scale, 1); // Compute scale size in real world Position referencePosition = dc.getViewportCenterPosition(); if (referencePosition != null) { Vec4 groundTarget = dc.getGlobe().computePointFromPosition(referencePosition); Double distance = dc.getView().getEyePoint().distanceTo3(groundTarget); this.pixelSize = dc.getView().computePixelSizeAtDistance(distance); Double scaleSize = this.pixelSize * width * scale; // meter String unitLabel = "m"; if (this.unit.equals(UNIT_METRIC)) { if (scaleSize > 10000) { scaleSize /= 1000; unitLabel = "Km"; } } else if (this.unit.equals(UNIT_IMPERIAL)) { scaleSize *= 3.280839895; // feet unitLabel = "ft"; if (scaleSize > 5280) { scaleSize /= 5280; unitLabel = "mile(s)"; } } // Rounded division size int pot = (int) Math.floor(Math.log10(scaleSize)); if (!Double.isNaN(pot)) { int digit = Integer.parseInt(String.format("%.0f", scaleSize).substring(0, 1)); double divSize = digit * Math.pow(10, pot); if (digit >= 5) divSize = 5 * Math.pow(10, pot); else if (digit >= 2) divSize = 2 * Math.pow(10, pot); double divWidth = width * divSize / scaleSize; // Draw scale if (!dc.isPickingMode()) { // Set color using current layer opacity Color backColor = this.getBackgroundColor(this.color); float[] colorRGB = backColor.getRGBColorComponents(null); gl.glColor4d( colorRGB[0], colorRGB[1], colorRGB[2], (double) backColor.getAlpha() / 255d * this.getOpacity()); gl.glTranslated((width - divWidth) / 2, 0d, 0d); this.drawScale(dc, divWidth, height); colorRGB = this.color.getRGBColorComponents(null); gl.glColor4d(colorRGB[0], colorRGB[1], colorRGB[2], this.getOpacity()); gl.glTranslated(-1d / scale, 1d / scale, 0d); this.drawScale(dc, divWidth, height); // Draw label String label = String.format("%.0f ", divSize) + unitLabel; gl.glLoadIdentity(); gl.glDisable(GL.GL_CULL_FACE); drawLabel( dc, label, locationSW.add3( new Vec4(divWidth * scale / 2 + (width - divWidth) / 2, height * scale, 0))); } else { // Picking this.pickSupport.clearPickList(); this.pickSupport.beginPicking(dc); // Draw unique color across the map Color color = dc.getUniquePickColor(); int colorCode = color.getRGB(); // Add our object(s) to the pickable list this.pickSupport.addPickableObject(colorCode, this, referencePosition, false); gl.glColor3ub((byte) color.getRed(), (byte) color.getGreen(), (byte) color.getBlue()); gl.glTranslated((width - divWidth) / 2, 0d, 0d); this.drawRectangle(dc, divWidth, height); // Done picking this.pickSupport.endPicking(dc); this.pickSupport.resolvePick(dc, dc.getPickPoint(), this); } } } } finally { if (projectionPushed) { gl.glMatrixMode(GL.GL_PROJECTION); gl.glPopMatrix(); } if (modelviewPushed) { gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); } if (attribsPushed) gl.glPopAttrib(); } }
public void display(GLAutoDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); gl.glClear(GL.GL_DEPTH_BUFFER_BIT); gl.glLoadIdentity(); gl.glTranslatef(0.0f, 0.0f, -5.0f); // Front Of House gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); // Front Left Window gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.5f, 0.0f, 0.0f); gl.glVertex3f(-0.75f, 0.25f, 0.0f); gl.glVertex3f(-0.25f, 0.25f, 0.0f); gl.glVertex3f(-0.25f, 0.75f, 0.0f); gl.glVertex3f(-0.75f, 0.75f, 0.0f); gl.glEnd(); // Front Right Window gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.5f, 0.0f, 0.0f); gl.glVertex3f(0.75f, 0.25f, 0.0f); gl.glVertex3f(0.25f, 0.25f, 0.0f); gl.glVertex3f(0.25f, 0.75f, 0.0f); gl.glVertex3f(0.75f, 0.75f, 0.0f); gl.glEnd(); // Door gl.glBegin(GL.GL_QUADS); gl.glColor3f(0.0f, 1.0f, 0.0f); gl.glVertex3f(-0.25f, -1.0f, 0.0f); gl.glVertex3f(0.25f, -1.0f, 0.0f); gl.glVertex3f(0.25f, -0.25f, 0.0f); gl.glVertex3f(-0.25f, -0.25f, 0.0f); gl.glEnd(); // Right Side of house gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(2.0f, -1.0f, -1.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Right Side of roof gl.glBegin(GL.GL_QUADS); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.75f, -1.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glEnd(); // Roof gl.glBegin(GL.GL_TRIANGLES); gl.glColor3f(1.0f, 0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Front Side Of House Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 0.0f); gl.glEnd(); // Right Side of house outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, 0.0f); gl.glVertex3f(2.0f, -1.0f, -1.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Roof Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 0.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glEnd(); // Right Side of roof Outline gl.glBegin(GL.GL_LINE_STRIP); gl.glColor3f(0.0f, 0.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 0.0f); gl.glVertex3f(2.0f, 1.0f, -1.0f); gl.glVertex3f(1.0f, 1.75f, -1.0f); gl.glVertex3f(0.0f, 2.0f, -1.0f); gl.glEnd(); }
// display callback function public void display(final GLAutoDrawable drawable) { final GL gl = drawable.getGL(); // The usual OpenGL stuff to clear the screen and set up viewing. gl.glClearColor(.25f, .25f, .25f, 1.0f); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glMatrixMode(GL.GL_PROJECTION); gl.glLoadIdentity(); glu.gluPerspective(30.0f, 1.0f, .1f, 100); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(4, 4, -4, 0, 0, 0, 0, 1, 0); // Make the object rotate a bit each time the display function // is called gl.glRotatef(curTime, 0, 1, 0); // Now make sure that the vertex and fragment programs, loaded // in LoadCgPrograms() are bound. CgGL.cgGLBindProgram(vertexProgram); CgGL.cgGLBindProgram(fragmentProgram); // Bind uniform parameters to vertex shader CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewProj"), CgGL.CG_GL_MODELVIEW_PROJECTION_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelView"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_IDENTITY); CgGL.cgGLSetStateMatrixParameter( CgGL.cgGetNamedParameter(vertexProgram, "ModelViewIT"), CgGL.CG_GL_MODELVIEW_MATRIX, CgGL.CG_GL_MATRIX_INVERSE_TRANSPOSE); // We can also go ahead and bind varying parameters to vertex shader // that we just want to have the same value for all vertices. The // vertex shader could be modified so that these were uniform for // better efficiency, but this gives us flexibility for the future. final float Kd[] = {.7f, .2f, .2f}, Ks[] = {.9f, .9f, .9f}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "diffuse"), Kd, 0); CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(vertexProgram, "specular"), Ks, 0); // Now bind uniform parameters to fragment shader final float lightPos[] = {3, 2, -3}; CgGL.cgGLSetParameter3fv(CgGL.cgGetNamedParameter(fragmentProgram, "Plight"), lightPos, 0); final float lightColor[] = {1, 1, 1}; CgGL.cgGLSetParameter3fv( CgGL.cgGetNamedParameter(fragmentProgram, "lightColor"), lightColor, 0); CgGL.cgGLSetParameter1f(CgGL.cgGetNamedParameter(fragmentProgram, "shininess"), 40); // And finally, enable the approprate texture for fragment shader; the // texture was originally set up in LoadTextures(). CgGL.cgGLEnableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); // And go ahead and draw the scene geometry DrawGeometry(gl); // Disable the texture now that we're done with it. CgGL.cgGLDisableTextureParameter(CgGL.cgGetNamedParameter(fragmentProgram, "diffuseMap")); ++curTime; }
public void display(GLAutoDrawable glDrawable) { GL gl = glDrawable.getGL(); // Store old matrices gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glMatrixMode(GL.GL_PROJECTION); gl.glPushMatrix(); gl.glLoadIdentity(); gl.glViewport(0, 0, glDrawable.getWidth(), glDrawable.getHeight()); // Store enabled state and disable lighting, texture mapping and the depth buffer gl.glPushAttrib(GL.GL_ENABLE_BIT); gl.glDisable(GL.GL_BLEND); gl.glDisable(GL.GL_LIGHTING); gl.glDisable(GL.GL_TEXTURE_2D); gl.glDisable(GL.GL_DEPTH_TEST); // Retrieve the current viewport and switch to orthographic mode IntBuffer viewPort = BufferUtil.newIntBuffer(4); gl.glGetIntegerv(GL.GL_VIEWPORT, viewPort); glu.gluOrtho2D(0, viewPort.get(2), viewPort.get(3), 0); // Render the text gl.glColor3f(1, 1, 1); int x = OFFSET; int maxx = 0; int y = OFFSET + CHAR_HEIGHT; if (keyboardEntries.size() > 0) { gl.glRasterPos2i(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS); maxx = Math.max( maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, KEYBOARD_CONTROLS)); y += OFFSET; x += INDENT; for (int i = 0; i < keyboardEntries.size(); i++) { gl.glRasterPos2f(x, y); String text = (String) keyboardEntries.get(i); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, text); maxx = Math.max(maxx, OFFSET + glut.glutBitmapLength(GLUT.BITMAP_HELVETICA_12, text)); y += OFFSET; } } if (mouseEntries.size() > 0) { x = maxx + OFFSET; y = OFFSET + CHAR_HEIGHT; gl.glRasterPos2i(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, MOUSE_CONTROLS); y += OFFSET; x += INDENT; for (int i = 0; i < mouseEntries.size(); i++) { gl.glRasterPos2f(x, y); glut.glutBitmapString(GLUT.BITMAP_HELVETICA_12, (String) mouseEntries.get(i)); y += OFFSET; } } // Restore enabled state gl.glPopAttrib(); // Restore old matrices gl.glPopMatrix(); gl.glMatrixMode(GL.GL_MODELVIEW); gl.glPopMatrix(); }