List of usage examples for org.lwjgl.opengl GL11 glColor3f
public static native void glColor3f(@NativeType("GLfloat") float red, @NativeType("GLfloat") float green, @NativeType("GLfloat") float blue);
From source file:bd.ac.seu.lwjgldemo.Renderer.java
private void drawSomething() { GL11.glClearColor(0, 0, 0, 1);/*from www . j av a 2 s . com*/ GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glColor3f(1, 1, 0); GL11.glPushMatrix(); GL11.glRotatef(angle, 0, 0, 1); /* GL11.glBegin(GL11.GL_QUADS); for (int row = 0; row < vertices.length; row = row + 3) { double x = vertices[row]; double y = vertices[row + 1]; double z = vertices[row + 2]; GL11.glVertex3d(x, y, z); } GL11.glEnd(); */ GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); // Draw the vertices GL11.glDrawArrays(GL11.GL_QUADS, 0, vertices.length / 3); // Put everything back to default (deselect) GL20.glDisableVertexAttribArray(0); GL30.glBindVertexArray(0); GL11.glPopMatrix(); angle = angle + .10f; frameCounter++; long currentTime = System.nanoTime(); long timeDifference = currentTime - lastTime; double fps = 1000000000.0 / timeDifference; System.out.printf("FPS: %.3f\n", fps); lastTime = currentTime; }
From source file:betterfonts.StringCache.java
License:Open Source License
/** * Render a single-line string to the screen using the current OpenGL color. The (x,y) coordinates are of the uppet-left * corner of the string's bounding box, rather than the baseline position as is typical with fonts. This function will also * add the string to the cache so the next renderString() call with the same string is faster. * * @param str the string being rendered; it can contain color codes * @param x the x coordinate to draw at//from w w w. j a va 2 s . com * @param y the y coordinate to draw at * @param color the initial RGBA color to use when drawing the string; embedded color codes can override the RGB component * @param shadowFlag if true, color codes are replaces by a darker version used for drop shadows * @return the total advance (horizontal distance) of this string * * @todo Add optional NumericShaper to replace ASCII digits with locale specific ones * @todo Add support for the "k" code which randomly replaces letters on each render (used only by splash screen) * @todo Pre-sort by texture to minimize binds; can store colors per glyph in string cache * @todo Optimize the underline/strikethrough drawing to draw a single line for each run */ public int renderString(String str, int startX, int startY, int initialColor, boolean shadowFlag) { /* Check for invalid arguments */ if (str == null || str.isEmpty()) { return 0; } /* Make sure the entire string is cached before rendering and return its glyph representation */ Entry entry = cacheString(str); /* Adjust the baseline of the string because the startY coordinate in Minecraft is for the top of the string */ startY += BASELINE_OFFSET; /* Color currently selected by color code; reapplied to Tessellator instance after glBindTexture() */ int color = initialColor; /* Track which texture is currently bound to minimize the number of glBindTexture() and Tessellator.draw() calls needed */ int boundTextureName = 0; /* * This color change will have no effect on the actual text (since colors are included in the Tessellator vertex * array), however GuiEditSign of all things depends on having the current color set to white when it renders its * "Edit sign message:" text. Otherwise, the sign which is rendered underneath would look too dark. */ GL11.glColor3f(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff); /* * Enable GL_BLEND in case the font is drawn anti-aliased because Minecraft itself only enables blending for chat text * (so it can fade out), but not GUI text or signs. Minecraft uses multiple blend functions so it has to be specified here * as well for consistent blending. To reduce the overhead of OpenGL state changes and making native LWJGL calls, this * function doesn't try to save/restore the blending state. Hopefully everything else that depends on blending in Minecraft * will set its own state as needed. */ if (antiAliasEnabled) { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); } /* Using the Tessellator to queue up data in a vertex array and then draw all at once should be faster than immediate mode */ Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.setColorRGBA(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff, color >> 24 & 0xff); /* The currently active font syle is needed to select the proper ASCII digit style for fast replacement */ int fontStyle = Font.PLAIN; for (int glyphIndex = 0, colorIndex = 0; glyphIndex < entry.glyphs.length; glyphIndex++) { /* * If the original string had a color code at this glyph's position, then change the current GL color that gets added * to the vertex array. Note that only the RGB component of the color is replaced by a color code; the alpha component * of the original color passed into this function will remain. The while loop handles multiple consecutive color codes, * in which case only the last such color code takes effect. */ while (colorIndex < entry.colors.length && entry.glyphs[glyphIndex].stringIndex >= entry.colors[colorIndex].stringIndex) { color = applyColorCode(entry.colors[colorIndex].colorCode, initialColor, shadowFlag); fontStyle = entry.colors[colorIndex].fontStyle; colorIndex++; } /* Select the current glyph's texture information and horizontal layout position within this string */ Glyph glyph = entry.glyphs[glyphIndex]; GlyphCache.Entry texture = glyph.texture; int glyphX = glyph.x; /* * Replace ASCII digits in the string with their respective glyphs; strings differing by digits are only cached once. * If the new replacement glyph has a different width than the original placeholder glyph (e.g. the '1' glyph is often * narrower than other digits), re-center the new glyph over the placeholder's position to minimize the visual impact * of the width mismatch. */ char c = str.charAt(glyph.stringIndex); if (c >= '0' && c <= '9') { int oldWidth = texture.width; texture = digitGlyphs[fontStyle][c - '0'].texture; int newWidth = texture.width; glyphX += (oldWidth - newWidth) >> 1; } /* * Make sure the OpenGL texture storing this glyph's image is bound (if not already bound). All pending glyphs in the * Tessellator's vertex array must be drawn before switching textures, otherwise they would erroneously use the new * texture as well. */ if (boundTextureName != texture.textureName) { tessellator.draw(); tessellator.startDrawingQuads(); tessellator.setColorRGBA(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff, color >> 24 & 0xff); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture.textureName); boundTextureName = texture.textureName; } /* The divide by 2.0F is needed to align with the scaled GUI coordinate system; startX/startY are already scaled */ float x1 = startX + (glyphX) / 2.0F; float x2 = startX + (glyphX + texture.width) / 2.0F; float y1 = startY + (glyph.y) / 2.0F; float y2 = startY + (glyph.y + texture.height) / 2.0F; tessellator.addVertexWithUV(x1, y1, 0, texture.u1, texture.v1); tessellator.addVertexWithUV(x1, y2, 0, texture.u1, texture.v2); tessellator.addVertexWithUV(x2, y2, 0, texture.u2, texture.v2); tessellator.addVertexWithUV(x2, y1, 0, texture.u2, texture.v1); } /* Draw any remaining glyphs in the Tessellator's vertex array (there should be at least one glyph pending) */ tessellator.draw(); /* Draw strikethrough and underlines if the string uses them anywhere */ if (entry.specialRender) { int renderStyle = 0; /* Use initial color passed to renderString(); disable texturing to draw solid color lines */ color = initialColor; GL11.glDisable(GL11.GL_TEXTURE_2D); tessellator.startDrawingQuads(); tessellator.setColorRGBA(color >> 16 & 0xff, color >> 8 & 0xff, color & 0xff, color >> 24 & 0xff); for (int glyphIndex = 0, colorIndex = 0; glyphIndex < entry.glyphs.length; glyphIndex++) { /* * If the original string had a color code at this glyph's position, then change the current GL color that gets added * to the vertex array. The while loop handles multiple consecutive color codes, in which case only the last such * color code takes effect. */ while (colorIndex < entry.colors.length && entry.glyphs[glyphIndex].stringIndex >= entry.colors[colorIndex].stringIndex) { color = applyColorCode(entry.colors[colorIndex].colorCode, initialColor, shadowFlag); renderStyle = entry.colors[colorIndex].renderStyle; colorIndex++; } /* Select the current glyph within this string for its layout position */ Glyph glyph = entry.glyphs[glyphIndex]; /* The strike/underlines are drawn beyond the glyph's width to include the extra space between glyphs */ int glyphSpace = glyph.advance - glyph.texture.width; /* Draw underline under glyph if the style is enabled */ if ((renderStyle & ColorCode.UNDERLINE) != 0) { /* The divide by 2.0F is needed to align with the scaled GUI coordinate system; startX/startY are already scaled */ float x1 = startX + (glyph.x - glyphSpace) / 2.0F; float x2 = startX + (glyph.x + glyph.advance) / 2.0F; float y1 = startY + (UNDERLINE_OFFSET) / 2.0F; float y2 = startY + (UNDERLINE_OFFSET + UNDERLINE_THICKNESS) / 2.0F; tessellator.addVertex(x1, y1, 0); tessellator.addVertex(x1, y2, 0); tessellator.addVertex(x2, y2, 0); tessellator.addVertex(x2, y1, 0); } /* Draw strikethrough in the middle of glyph if the style is enabled */ if ((renderStyle & ColorCode.STRIKETHROUGH) != 0) { /* The divide by 2.0F is needed to align with the scaled GUI coordinate system; startX/startY are already scaled */ float x1 = startX + (glyph.x - glyphSpace) / 2.0F; float x2 = startX + (glyph.x + glyph.advance) / 2.0F; float y1 = startY + (STRIKETHROUGH_OFFSET) / 2.0F; float y2 = startY + (STRIKETHROUGH_OFFSET + STRIKETHROUGH_THICKNESS) / 2.0F; tessellator.addVertex(x1, y1, 0); tessellator.addVertex(x1, y2, 0); tessellator.addVertex(x2, y2, 0); tessellator.addVertex(x2, y1, 0); } } /* Finish drawing the last strikethrough/underline segments */ tessellator.draw(); GL11.glEnable(GL11.GL_TEXTURE_2D); } /* Return total horizontal advance (slightly wider than the bounding box, but close enough for centering strings) */ return entry.advance / 2; }
From source file:buildcraft.core.lib.engines.RenderEngine.java
License:Minecraft Mod Public
private void render(float progress, ForgeDirection orientation, ResourceLocation baseTexture, ResourceLocation chamberTexture, ResourceLocation trunkTexture, double x, double y, double z) { if (BuildCraftCore.render == RenderMode.NoDynamic) { return;/*from w ww .j a v a2s . co m*/ } GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); float step; if (progress > 0.5) { step = 7.99F - (progress - 0.5F) * 2F * 7.99F; } else { step = progress * 2F * 7.99F; } float translatefact = step / 16; float[] angle = { 0, 0, 0 }; float[] translate = { orientation.offsetX, orientation.offsetY, orientation.offsetZ }; switch (orientation) { case EAST: case WEST: case DOWN: angle[2] = angleMap[orientation.ordinal()]; break; case SOUTH: case NORTH: default: angle[0] = angleMap[orientation.ordinal()]; break; } box.rotateAngleX = angle[0]; box.rotateAngleY = angle[1]; box.rotateAngleZ = angle[2]; trunk.rotateAngleX = angle[0]; trunk.rotateAngleY = angle[1]; trunk.rotateAngleZ = angle[2]; movingBox.rotateAngleX = angle[0]; movingBox.rotateAngleY = angle[1]; movingBox.rotateAngleZ = angle[2]; chamber.rotateAngleX = angle[0]; chamber.rotateAngleY = angle[1]; chamber.rotateAngleZ = angle[2]; float factor = (float) (1.0 / 16.0); bindTexture(baseTexture); box.render(factor); GL11.glTranslatef(translate[0] * translatefact, translate[1] * translatefact, translate[2] * translatefact); movingBox.render(factor); GL11.glTranslatef(-translate[0] * translatefact, -translate[1] * translatefact, -translate[2] * translatefact); bindTexture(chamberTexture); float chamberf = 2F / 16F; int chamberc = ((int) step + 4) / 2; for (int i = 0; i <= step + 2; i += 2) { chamber.render(factor); GL11.glTranslatef(translate[0] * chamberf, translate[1] * chamberf, translate[2] * chamberf); } GL11.glTranslatef(-translate[0] * chamberf * chamberc, -translate[1] * chamberf * chamberc, -translate[2] * chamberf * chamberc); bindTexture(trunkTexture); trunk.render(factor); GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:buildcraft.energy.render.RenderEnergyEmitter.java
License:Minecraft Mod Public
public void renderTileEntityAt2(TileEntity tileentity, double x, double y, double z, float f) { if (BuildCraftCore.render == RenderMode.NoDynamic) { return;//from ww w.ja v a2 s .co m } GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); float step; float[] angle = { 0, 0, 0 }; box.rotateAngleX = angle[0]; box.rotateAngleY = angle[1]; box.rotateAngleZ = angle[2]; float factor = (float) (1.0 / 16.0); //bindTexture(EntityLaser.LASER_TEXTURES[3]); bindTexture(CHAMBER_TEXTURE); box.render(factor); GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:buildcraft.energy.render.RenderEngine.java
License:Minecraft Mod Public
private void render(float progress, ForgeDirection orientation, ResourceLocation baseTexture, ResourceLocation chamberTexture, ResourceLocation trunkTexture, double x, double y, double z) { if (BuildCraftCore.render == RenderMode.NoDynamic) { return;/*from w ww . j ava 2 s . c om*/ } GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); float step; if (progress > 0.5) { step = 7.99F - (progress - 0.5F) * 2F * 7.99F; } else { step = progress * 2F * 7.99F; } float translatefact = step / 16; float[] angle = { 0, 0, 0 }; float[] translate = { orientation.offsetX, orientation.offsetY, orientation.offsetZ }; switch (orientation) { case EAST: case WEST: case DOWN: angle[2] = angleMap[orientation.ordinal()]; break; case SOUTH: case NORTH: default: angle[0] = angleMap[orientation.ordinal()]; break; } box.rotateAngleX = angle[0]; box.rotateAngleY = angle[1]; box.rotateAngleZ = angle[2]; trunk.rotateAngleX = angle[0]; trunk.rotateAngleY = angle[1]; trunk.rotateAngleZ = angle[2]; movingBox.rotateAngleX = angle[0]; movingBox.rotateAngleY = angle[1]; movingBox.rotateAngleZ = angle[2]; chamber.rotateAngleX = angle[0]; chamber.rotateAngleY = angle[1]; chamber.rotateAngleZ = angle[2]; float factor = (float) (1.0 / 16.0); bindTexture(baseTexture); box.render(factor); GL11.glTranslatef(translate[0] * translatefact, translate[1] * translatefact, translate[2] * translatefact); movingBox.render(factor); GL11.glTranslatef(-translate[0] * translatefact, -translate[1] * translatefact, -translate[2] * translatefact); bindTexture(chamberTexture); float chamberf = 2F / 16F; for (int i = 0; i <= step + 2; i += 2) { chamber.render(factor); GL11.glTranslatef(translate[0] * chamberf, translate[1] * chamberf, translate[2] * chamberf); } for (int i = 0; i <= step + 2; i += 2) { GL11.glTranslatef(-translate[0] * chamberf, -translate[1] * chamberf, -translate[2] * chamberf); } bindTexture(trunkTexture); trunk.render(factor); GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:buildcraft.robotics.render.RenderRobot.java
License:Minecraft Mod Public
private void doRender(EntityRobot robot, double x, double y, double z, float partialTicks) { GL11.glPushMatrix();//ww w. ja va2 s .c o m GL11.glTranslated(x, y, z); float robotYaw = this.interpolateRotation(robot.prevRenderYawOffset, robot.renderYawOffset, partialTicks); GL11.glRotatef(-robotYaw, 0.0f, 1.0f, 0.0f); if (robot.getStackInSlot(0) != null) { GL11.glPushMatrix(); GL11.glTranslatef(-0.125F, 0, -0.125F); doRenderItem(robot.getStackInSlot(0)); GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.getStackInSlot(1) != null) { GL11.glPushMatrix(); GL11.glTranslatef(+0.125F, 0, -0.125F); doRenderItem(robot.getStackInSlot(1)); GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.getStackInSlot(2) != null) { GL11.glPushMatrix(); GL11.glTranslatef(+0.125F, 0, +0.125F); doRenderItem(robot.getStackInSlot(2)); GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.getStackInSlot(3) != null) { GL11.glPushMatrix(); GL11.glTranslatef(-0.125F, 0, +0.125F); doRenderItem(robot.getStackInSlot(3)); GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.itemInUse != null) { GL11.glPushMatrix(); GL11.glRotatef(robot.itemAngle2, 0, 0, 1); if (robot.itemActive) { long newDate = new Date().getTime(); robot.itemActiveStage = (robot.itemActiveStage + (newDate - robot.lastUpdateTime) / 10) % 45; GL11.glRotatef(robot.itemActiveStage, 0, 0, 1); robot.lastUpdateTime = newDate; } GL11.glTranslatef(-0.4F, 0, 0); GL11.glRotatef(-45F + 180F, 0, 1, 0); GL11.glScalef(0.8F, 0.8F, 0.8F); ItemStack itemstack1 = robot.itemInUse; if (itemstack1.getItem().requiresMultipleRenderPasses()) { for (int k = 0; k < itemstack1.getItem().getRenderPasses(itemstack1.getItemDamage()); ++k) { RenderUtils.setGLColorFromInt(itemstack1.getItem().getColorFromItemStack(itemstack1, k)); this.renderManager.itemRenderer.renderItem(robot, itemstack1, k); } } else { RenderUtils.setGLColorFromInt(itemstack1.getItem().getColorFromItemStack(itemstack1, 0)); this.renderManager.itemRenderer.renderItem(robot, itemstack1, 0); } GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.laser.isVisible) { robot.laser.head.x = robot.posX; robot.laser.head.y = robot.posY; robot.laser.head.z = robot.posZ; RenderLaser.doRenderLaser(renderManager.renderEngine, robot.laser, EntityLaser.LASER_TEXTURES[1]); } if (robot.getTexture() != null) { renderManager.renderEngine.bindTexture(robot.getTexture()); float storagePercent = (float) robot.getBattery().getEnergyStored() / (float) robot.getBattery().getMaxEnergyStored(); if (robot.hurtTime > 0) { GL11.glColor3f(1.0f, 0.6f, 0.6f); GL11.glRotatef(robot.hurtTime * 0.01f, 0, 0, 1); } doRenderRobot(1F / 16F, renderManager.renderEngine, storagePercent, robot.isActive()); } for (ItemStack s : robot.getWearables()) { doRenderWearable(robot, renderManager.renderEngine, s); } GL11.glPopMatrix(); }
From source file:buildcraft.robots.render.RenderRobot.java
License:Minecraft Mod Public
private void doRender(EntityRobot robot, double x, double y, double z) { GL11.glPushMatrix();/*from w ww . j av a2 s .co m*/ GL11.glTranslated(x, y, z); if (robot.getStackInSlot(0) != null) { GL11.glPushMatrix(); GL11.glTranslatef(-0.125F, 0, -0.125F); doRenderItem(robot.getStackInSlot(0)); GL11.glPopMatrix(); } if (robot.getStackInSlot(1) != null) { GL11.glPushMatrix(); GL11.glTranslatef(+0.125F, 0, -0.125F); doRenderItem(robot.getStackInSlot(1)); GL11.glPopMatrix(); } if (robot.getStackInSlot(2) != null) { GL11.glPushMatrix(); GL11.glTranslatef(+0.125F, 0, +0.125F); doRenderItem(robot.getStackInSlot(2)); GL11.glPopMatrix(); } if (robot.getStackInSlot(3) != null) { GL11.glPushMatrix(); GL11.glTranslatef(-0.125F, 0, +0.125F); doRenderItem(robot.getStackInSlot(3)); GL11.glPopMatrix(); } if (robot.itemInUse != null) { GL11.glPushMatrix(); GL11.glRotatef((float) (-robot.itemAngle1 / (2 * Math.PI) * 360) + 180, 0, 1, 0); GL11.glRotatef((float) (robot.itemAngle2 / (2 * Math.PI) * 360), 0, 0, 1); if (robot.itemActive) { long newDate = new Date().getTime(); robot.itemActiveStage = (robot.itemActiveStage + (newDate - robot.lastUpdateTime) / 10) % 45; GL11.glRotatef(robot.itemActiveStage, 0, 0, 1); robot.lastUpdateTime = newDate; } GL11.glTranslatef(-0.4F, 0, 0); GL11.glRotatef(-45F + 180F, 0, 1, 0); GL11.glScalef(0.8F, 0.8F, 0.8F); ItemStack itemstack1 = robot.itemInUse; if (itemstack1.getItem().requiresMultipleRenderPasses()) { for (int k = 0; k < itemstack1.getItem().getRenderPasses(itemstack1.getItemDamage()); ++k) { RenderUtils.setGLColorFromInt(itemstack1.getItem().getColorFromItemStack(itemstack1, k)); this.renderManager.itemRenderer.renderItem(robot, itemstack1, k); } } else { RenderUtils.setGLColorFromInt(itemstack1.getItem().getColorFromItemStack(itemstack1, 0)); this.renderManager.itemRenderer.renderItem(robot, itemstack1, 0); } GL11.glColor3f(1, 1, 1); GL11.glPopMatrix(); } if (robot.laser.isVisible) { robot.laser.head.x = robot.posX; robot.laser.head.y = robot.posY; robot.laser.head.z = robot.posZ; RenderLaser.doRenderLaser(renderManager.renderEngine, robot.laser, EntityLaser.LASER_TEXTURES[1]); } if (robot.getTexture() != null) { renderManager.renderEngine.bindTexture(robot.getTexture()); doRenderRobot(1F / 16F, renderManager.renderEngine); } GL11.glPopMatrix(); }
From source file:buildcraft.transport.render.PipeRendererTESR.java
License:Minecraft Mod Public
private void pipeWireRender(TileGenericPipe pipe, float cx, float cy, float cz, PipeWire color, double x, double y, double z) { PipeRenderState state = pipe.renderState; float minX = CoreConstants.PIPE_MIN_POS; float minY = CoreConstants.PIPE_MIN_POS; float minZ = CoreConstants.PIPE_MIN_POS; float maxX = CoreConstants.PIPE_MAX_POS; float maxY = CoreConstants.PIPE_MAX_POS; float maxZ = CoreConstants.PIPE_MAX_POS; boolean foundX = false, foundY = false, foundZ = false; if (state.wireMatrix.isWireConnected(color, ForgeDirection.WEST)) { minX = 0;/*from www.j ava2 s .c o m*/ foundX = true; } if (state.wireMatrix.isWireConnected(color, ForgeDirection.EAST)) { maxX = 1; foundX = true; } if (state.wireMatrix.isWireConnected(color, ForgeDirection.DOWN)) { minY = 0; foundY = true; } if (state.wireMatrix.isWireConnected(color, ForgeDirection.UP)) { maxY = 1; foundY = true; } if (state.wireMatrix.isWireConnected(color, ForgeDirection.NORTH)) { minZ = 0; foundZ = true; } if (state.wireMatrix.isWireConnected(color, ForgeDirection.SOUTH)) { maxZ = 1; foundZ = true; } boolean center = false; if (minX == 0 && maxX != 1 && (foundY || foundZ)) { if (cx == CoreConstants.PIPE_MIN_POS) { maxX = CoreConstants.PIPE_MIN_POS; } else { center = true; } } if (minX != 0 && maxX == 1 && (foundY || foundZ)) { if (cx == CoreConstants.PIPE_MAX_POS) { minX = CoreConstants.PIPE_MAX_POS; } else { center = true; } } if (minY == 0 && maxY != 1 && (foundX || foundZ)) { if (cy == CoreConstants.PIPE_MIN_POS) { maxY = CoreConstants.PIPE_MIN_POS; } else { center = true; } } if (minY != 0 && maxY == 1 && (foundX || foundZ)) { if (cy == CoreConstants.PIPE_MAX_POS) { minY = CoreConstants.PIPE_MAX_POS; } else { center = true; } } if (minZ == 0 && maxZ != 1 && (foundX || foundY)) { if (cz == CoreConstants.PIPE_MIN_POS) { maxZ = CoreConstants.PIPE_MIN_POS; } else { center = true; } } if (minZ != 0 && maxZ == 1 && (foundX || foundY)) { if (cz == CoreConstants.PIPE_MAX_POS) { minZ = CoreConstants.PIPE_MAX_POS; } else { center = true; } } boolean found = foundX || foundY || foundZ; GL11.glPushMatrix(); GL11.glPushAttrib(GL11.GL_ENABLE_BIT); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); RenderHelper.disableStandardItemLighting(); GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); float scale = 1.001f; GL11.glTranslatef(0.5F, 0.5F, 0.5F); GL11.glScalef(scale, scale, scale); GL11.glTranslatef(-0.5F, -0.5F, -0.5F); bindTexture(TextureMap.locationBlocksTexture); RenderInfo renderBox = new RenderInfo(); renderBox.texture = BuildCraftTransport.instance.wireIconProvider .getIcon(state.wireMatrix.getWireIconIndex(color)); // Z render if (minZ != CoreConstants.PIPE_MIN_POS || maxZ != CoreConstants.PIPE_MAX_POS || !found) { renderBox.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, minZ, cx == CoreConstants.PIPE_MIN_POS ? cx : cx + 0.05F, cy == CoreConstants.PIPE_MIN_POS ? cy : cy + 0.05F, maxZ); RenderEntityBlock.INSTANCE.renderBlock(renderBox, pipe.getWorldObj(), 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } // X render if (minX != CoreConstants.PIPE_MIN_POS || maxX != CoreConstants.PIPE_MAX_POS || !found) { renderBox.setBounds(minX, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, maxX, cy == CoreConstants.PIPE_MIN_POS ? cy : cy + 0.05F, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(renderBox, pipe.getWorldObj(), 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } // Y render if (minY != CoreConstants.PIPE_MIN_POS || maxY != CoreConstants.PIPE_MAX_POS || !found) { renderBox.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, minY, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, cx == CoreConstants.PIPE_MIN_POS ? cx : cx + 0.05F, maxY, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(renderBox, pipe.getWorldObj(), 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } if (center || !found) { renderBox.setBounds(cx == CoreConstants.PIPE_MIN_POS ? cx - 0.05F : cx, cy == CoreConstants.PIPE_MIN_POS ? cy - 0.05F : cy, cz == CoreConstants.PIPE_MIN_POS ? cz - 0.05F : cz, cx == CoreConstants.PIPE_MIN_POS ? cx : cx + 0.05F, cy == CoreConstants.PIPE_MIN_POS ? cy : cy + 0.05F, cz == CoreConstants.PIPE_MIN_POS ? cz : cz + 0.05F); RenderEntityBlock.INSTANCE.renderBlock(renderBox, pipe.getWorldObj(), 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true); } RenderHelper.enableStandardItemLighting(); GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:buildcraft.transport.render.PipeRendererTESR.java
License:Minecraft Mod Public
private void pipeGateRender(TileGenericPipe pipe, double x, double y, double z) { GL11.glPushMatrix();/* ww w. j a v a 2s. co m*/ GL11.glPushAttrib(GL11.GL_ENABLE_BIT); // GL11.glEnable(GL11.GL_LIGHTING); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_CULL_FACE); // GL11.glDisable(GL11.GL_TEXTURE_2D); RenderHelper.disableStandardItemLighting(); GL11.glColor3f(1, 1, 1); GL11.glTranslatef((float) x, (float) y, (float) z); bindTexture(TextureMap.locationBlocksTexture); IIcon iconLogic; if (pipe.renderState.isGateLit()) { iconLogic = pipe.pipe.gate.logic.getIconLit(); } else { iconLogic = pipe.pipe.gate.logic.getIconDark(); } float translateCenter = 0; // Render base gate renderGate(pipe, iconLogic, 0, 0.1F, 0, 0); float pulseStage = pipe.pipe.gate.getPulseStage() * 2F; if (pipe.renderState.isGatePulsing() || pulseStage != 0) { // Render pulsing gate float amplitude = 0.10F; float start = 0.01F; if (pulseStage < 1) { translateCenter = (pulseStage * amplitude) + start; } else { translateCenter = amplitude - ((pulseStage - 1F) * amplitude) + start; } renderGate(pipe, iconLogic, 0, 0.13F, translateCenter, translateCenter); } IIcon materialIcon = pipe.pipe.gate.material.getIconBlock(); if (materialIcon != null) { renderGate(pipe, materialIcon, 1, 0.13F, translateCenter, translateCenter); } for (IGateExpansion expansion : pipe.pipe.gate.expansions.keySet()) { renderGate(pipe, expansion.getOverlayBlock(), 2, 0.13F, translateCenter, translateCenter); } RenderHelper.enableStandardItemLighting(); GL11.glPopAttrib(); GL11.glPopMatrix(); }
From source file:buildcraftAdditions.client.render.entities.EntityLaserShotRenderer.java
License:GNU General Public License
private void doRender(EntityLaserShot entity, double x, double y, double z, float rotation, float partialTicks) { bindEntityTexture(entity);/* w w w. j a v a 2 s. co m*/ GL11.glPushMatrix(); float strength = entity.getStrength(); if (strength >= 1) GL11.glColor3f(1, 0, 0); else if (strength > 0.75) GL11.glColor3f(0.75F, 0, 0.25F); else if (strength > 0.6) GL11.glColor3f(0.5F, 0, 0.5F); else if (strength > 0.35) GL11.glColor3f(0.25F, 0, 0.75F); else GL11.glColor3f(0, 0, 1); GL11.glTranslated(x, y, z); GL11.glRotatef(entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * partialTicks - 90, 0, 1, 0); GL11.glRotatef(entity.prevRotationPitch + (entity.rotationPitch - entity.prevRotationPitch) * partialTicks, 0, 0, 1); Tessellator t = Tessellator.instance; double d1 = 0; double d2 = 0.5; double d3 = 0 / 32D; double d4 = 5 / 32D; double d5 = 0.05625; GL11.glEnable(GL12.GL_RESCALE_NORMAL); float f1 = entity.throwableShake - partialTicks; if (f1 > 0) { float f2 = -MathHelper.sin(f1 * 3) * f1; GL11.glRotatef(f2, 0, 0, 1); } GL11.glRotatef(45, 1, 0, 0); GL11.glScaled(d5, d5, d5); GL11.glTranslatef(-4, 0, 0); for (int i = 0; i < 4; i++) { GL11.glRotatef(90, 1, 0, 0); GL11.glNormal3d(0, 0, d5); t.startDrawingQuads(); t.addVertexWithUV(-8, -2, 0, d1, d3); t.addVertexWithUV(8, -2, 0, d2, d3); t.addVertexWithUV(8, 2, 0, d2, d4); t.addVertexWithUV(-8, 2, 0, d1, d4); t.draw(); } GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); }