public void desenhar(GL gl, GLUT glut) { gl.glShadeModel(GL.GL_FLAT); gl.glNormal3f(0.0f, 0.0f, 1.0f); gl.glColor3f(1f, 1f, 1f); float corWhite[] = {1.0f, 1.0f, 1.0f, 1.0f}; // base setTexture(Util.loadImage("texture/textureBrick.png")); getTexture().enable(); getTexture().bind(); gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT_AND_DIFFUSE, corWhite, 0); gl.glEnable(GL.GL_LIGHTING); gl.glPushMatrix(); gl.glTranslatef(0f, -dif, 0f); gl.glScalef(getxEscala(), getyEscala(), getzEscala()); glut.glutSolidCube(1f); gl.glPopMatrix(); // esquerda setTexture(Util.loadImage("texture/tijolos/medio2.png")); getTexture().enable(); getTexture().bind(); gl.glPushMatrix(); gl.glTranslatef(-(getxEscala() / 2), (getAltura() / 2) - dif, 0f); gl.glScalef(0.1f, getAltura(), getzEscala()); glut.glutSolidCube(1f); gl.glPopMatrix(); gl.glDisable(GL.GL_LIGHTING); // direita setTexture(Util.loadImage("texture/tijolos/medio2.png")); getTexture().enable(); getTexture().bind(); gl.glPushMatrix(); gl.glTranslatef(getxEscala() / 2, (getAltura() / 2) - dif, 0f); gl.glScalef(0.1f, getAltura(), getzEscala()); glut.glutSolidCube(1f); gl.glPopMatrix(); gl.glDisable(GL.GL_LIGHTING); // fundo setTexture(Util.loadImage("texture/tijolos/fraco.png")); getTexture().enable(); getTexture().bind(); gl.glPushMatrix(); gl.glTranslatef(0f, (getAltura() / 2) - dif, -(getzEscala() / 2)); gl.glScalef(getxEscala(), getAltura(), 0.1f); glut.glutSolidCube(1f); gl.glPopMatrix(); gl.glDisable(GL.GL_LIGHTING); }
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(); }
/** * @param glRenderContext * @param prototype * @param buffer to be used for rendering. */ public static synchronized void render( RenderContext glRenderContext, PrototypeReference prototype, DirectGeometryBuffer buffer) { if (prototype == null || prototype.getPrototypeID() == null) { return; } RenderablePrototype model = prototypes.get(prototype.getPrototypeID()); if (model == null) { LOG.warn("No model found for prototype: " + prototype.getPrototypeID()); return; } GL context = glRenderContext.getContext(); context.glPushMatrix(); float[] loc = prototype.getLocation(); context.glTranslatef(loc[0], loc[1], loc[2]); context.glRotatef(prototype.getAngle(), 0, 0, 1); context.glScalef(prototype.getWidth(), prototype.getDepth(), prototype.getHeight()); if (buffer == null) { model.render(null); } else { model.renderPrepared(glRenderContext, buffer); } context.glPopMatrix(); }
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(); }
public void render(GLOContext ctx) { GUIContext guictx = (GUIContext) ctx; GL gl = ctx.getGL(); ModelRenderer mrend = guictx.rendcache.getModelRenderer(xpointermodel, ModelRenderer.NO_NORMALS); gl.glPushMatrix(); // #1 gl.glPushAttrib(GL.GL_ENABLE_BIT | GL.GL_POLYGON_BIT); gl.glEnable(GL.GL_CULL_FACE); setShader("xpointer"); Point org = origin; float w2 = getWidth() * 0.5f; float h2 = getHeight() * 0.5f; float cenx = org.x + w2; float ceny = org.y + h2; gl.glTranslatef(cenx, ceny, 0); gl.glScalef(w2, h2, 1); // must convert right-hand to left-hand coords // draw the x value gl.glPushMatrix(); float xval = getXValue(); xval = Math.max(-maxrot, Math.min(maxrot, xval * maxrot)); gl.glRotatef(90, 0, 0, 1); gl.glRotatef(xval, -1, 0, 0); mrend.render(); gl.glPopMatrix(); // draw the y value float yval = getYValue(); yval = Math.max(-maxrot, Math.min(maxrot, yval * maxrot)); gl.glRotatef(yval, -1, 0, 0); mrend.render(); gl.glPopAttrib(); gl.glPopMatrix(); // #1 }
@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(); }