public void renderBox(GL gl) { gl.glDisable(GL_TEXTURE_2D); int c1 = Math.abs(this.hashCode()) % 256; int c2 = Math.abs(getImage().hashCode()) % 256; gl.glColor4f(c1 / 256f, c2 / 256f, ((c1 + c2) * 34) % 256 / 256f, 0.3f); gl.glPushMatrix(); gl.glTranslatef(bounds.getLeft(), bounds.getTop(), minHeight); gl.glScalef(bounds.getWidth(), bounds.getHeight(), maxHeight - minHeight); gl.glBegin(GL_QUADS); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 1, 0); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 1); gl.glEnd(); gl.glColor4f(1, 1, 0, 0.2f); gl.glBegin(GL_QUAD_STRIP); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glVertex3f(0, 1, 0); gl.glVertex3f(0, 1, 1); gl.glVertex3f(1, 1, 0); gl.glVertex3f(1, 1, 1); gl.glVertex3f(1, 0, 0); gl.glVertex3f(1, 0, 1); gl.glVertex3f(0, 0, 0); gl.glVertex3f(0, 0, 1); gl.glEnd(); gl.glPopMatrix(); }
private void glcolor() { gl.glColor4f( (float) color.getRed() / 255.0f, (float) color.getGreen() / 255.0f, (float) color.getBlue() / 255.0f, (float) color.getAlpha() / 255.0f); }
@Override public void render(GLCanvas canvas) { gui.getGL().glColor4f(bg_col.getR(), bg_col.getG(), bg_col.getB(), bg_col.getA()); renderQuad(pos.x, pos.y, width, height); GL gl = canvas.getGL(); if (texture != null) { texture.bind(0); gl.glColor4f(fg_col.getR(), fg_col.getG(), fg_col.getB(), fg_col.getA()); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f(0, 0); gl.glVertex2f(pos.x, pos.y); gl.glTexCoord2f(texture.getImageWidth() / texture.getWidth(), 0); gl.glVertex2f(pos.x + width, pos.y); gl.glTexCoord2f( texture.getImageWidth() / texture.getWidth(), texture.getImageHeight() / texture.getHeight()); gl.glVertex2f(pos.x + width, pos.y - height); gl.glTexCoord2f(0, texture.getImageHeight() / texture.getHeight()); gl.glVertex2f(pos.x, pos.y - height); gl.glEnd(); texture.unbind(); } gui.getGL() .glColor4f(border_col.getR(), border_col.getG(), border_col.getB(), border_col.getA()); renderOutlinedQuad(pos.x, pos.y, width, height); }
public void paintTex(int glid, int target, int w, int h, int color) { float r, g, b, a; int ir, ig, ib, ia; ia = (color >> 24) & 0xff; ir = (color >> 16) & 0xff; ig = (color >> 8) & 0xff; ib = color & 0xff; a = ia / 255.0f; r = ir / 255.0f; g = ig / 255.0f; b = ib / 255.0f; pushFramebuffer(); setFramebuffer(FBO); FBO.setDrawBuffer(target, glid); saveView(); setOrthographicView(w, h); gl.glColor4f(r, g, b, a); gl.glBegin(GL.GL_QUADS); gl.glVertex2f(0.0f, 0.0f); gl.glVertex2f(w, 0.0f); gl.glVertex2f(w, h); gl.glVertex2f(0.0f, h); gl.glEnd(); restoreView(); popFramebuffer(); }
public void draw() { background(0); rotate++; gl.glColor4f(1, 1, 1, 0.7f); gl.glTranslatef(0, 0, -200); gl.glRotatef(rotate, 0, 1, 0); gl.glRotatef(10, 1, 0, 0); t.draw(); }
public void copyTex(GLTexture srcTex, GLTexture destTex) { float uscale = srcTex.getMaxTextureCoordS(); float vscale = srcTex.getMaxTextureCoordT(); float cx = 0.0f; float sx = +1.0f; if (destTex.isFlippedX()) { cx = 1.0f; sx = -1.0f; } float cy = 0.0f; float sy = +1.0f; if (destTex.isFlippedY()) { cy = 1.0f; sy = -1.0f; } gl.glEnable(srcTex.getTextureTarget()); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID()); pushFramebuffer(); setFramebuffer(FBO); FBO.setDrawBuffer(destTex.getTextureTarget(), destTex.getTextureID()); saveView(); setOrthographicView(destTex.width, destTex.height); gl.glEnable(srcTex.getTextureTarget()); gl.glActiveTexture(GL.GL_TEXTURE0); gl.glBindTexture(srcTex.getTextureTarget(), srcTex.getTextureID()); gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); gl.glBegin(GL.GL_QUADS); gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 0.0f) * vscale); gl.glVertex2f(0.0f, 0.0f); gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 0.0f) * vscale); gl.glVertex2f(srcTex.width, 0.0f); gl.glTexCoord2f((cx + sx * 1.0f) * uscale, (cy + sy * 1.0f) * vscale); gl.glVertex2f(srcTex.width, srcTex.height); gl.glTexCoord2f((cx + sx * 0.0f) * uscale, (cy + sy * 1.0f) * vscale); gl.glVertex2f(0.0f, srcTex.height); gl.glEnd(); gl.glBindTexture(srcTex.getTextureTarget(), 0); restoreView(); popFramebuffer(); }
public void draw(GL gl) { if (visible) { // Seta a cor da peça if (color != null) { float r = color.getR(); float g = color.getG(); float b = color.getB(); float a = color.getAlpha(); gl.glColor4f(r, g, b, a); } else { gl.glColor3d(Math.random(), Math.random(), Math.random()); } // desenha a peça gl.glBegin(drawType); for (Vetor3f v : points) { gl.glVertex3f(v.getX(), v.getY(), v.getZ()); } gl.glEnd(); } }
public void display(GLCanvas canvas) { GL gl = canvas.getGL(); // // render the simulation // try { sim.update(); } catch (Exception e) { Log.println("[Editor] exception in simulation update/calculate paths: " + e.getMessage()); e.printStackTrace(); } renderer.render(sim, canvas); // // render the grid // gl.glColor4f(0.4f, 0.4f, 0.4f, 0.4f); gl.glEnable(GL.GL_BLEND); gl.glBegin(GL.GL_LINES); for (int x = 0; x < 100; x++) { gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4); gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4, 50 * Constants.PLANET_MAX_SIZE * 4); } for (int x = 0; x < 100; x++) { gl.glVertex2f( -50 * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4); gl.glVertex2f( +50 * Constants.PLANET_MAX_SIZE * 4, -50 * Constants.PLANET_MAX_SIZE * 4 + x * Constants.PLANET_MAX_SIZE * 4); } gl.glDisable(GL.GL_BLEND); gl.glEnd(); // // render rectangle selection // if (drag_start != null && drag_end != null && selected_planets.size() == 0) { gl.glLineWidth(2); gl.glColor4f(1, 1, 1, 1); Widget.renderOutlinedQuad( drag_start.x, drag_start.y, drag_end.x - drag_start.x, -(drag_end.y - drag_start.y)); gl.glLineWidth(1); } // // render reference system // gl.glColor3f(1, 1, 1); gl.glBegin(GL.GL_LINES); gl.glColor3f(1, 0, 0); gl.glVertex2f(Constants.PLANET_MAX_SIZE * 50, 0); gl.glVertex2f(-Constants.PLANET_MAX_SIZE * 50, 0); gl.glColor3f(0, 1, 0); gl.glVertex2f(0, Constants.PLANET_MAX_SIZE * 50); gl.glVertex2f(0, -Constants.PLANET_MAX_SIZE * 50); gl.glEnd(); try { Thread.sleep(5); } catch (InterruptedException e) { } // // check mouse over planet // if (sim.getPlanet( renderer.getCamera().getScreenToWorldX(mouse_pos.x), renderer.getCamera().getScreenToWorldY(mouse_pos.y)) != null && !this.wasGuiIntersected(mouse_pos.x, mouse_pos.y) && drag_start != null) for (WorldAlignementContainer cont : conts) cont.setVisible(false); else for (WorldAlignementContainer cont : conts) cont.setVisible(true); }
@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(); }
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) { } }