List of usage examples for org.lwjgl.opengl GL11 glDisable
public static void glDisable(@NativeType("GLenum") int target)
From source file:ccm.burialservices.client.renderers.GraveRenderer.java
License:Open Source License
private static void renderItemHolding(int i, int meta, ItemStack stack, double x, double y, double z, float tickTime) { Icon icon = stack.getItem().getIcon(stack, i); if (icon == null) return;//from w ww . ja v a2 s.c o m GL11.glPushMatrix(); GL11.glTranslated(x, y, z); //Center to block switch (meta) { case 0: break; case 1: GL11.glRotatef(90F, 0.0F, 1.0F, 0.0F); GL11.glTranslated(-1, 0, 0); break; case 2: GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F); GL11.glTranslated(-1, 0, -1); break; case 3: GL11.glRotatef(-90F, 0.0F, 1.0F, 0.0F); GL11.glTranslated(0, 0, -1); break; } if (stack.getItem() instanceof ItemSword) { GL11.glTranslated(0.44, 0.1d, 1.85); GL11.glRotatef(180F, 0.0F, 1.0F, 0.0F); } else { GL11.glTranslated(0.5, 0.1d, 0.5); } GL11.glRotatef(90F, 1.0F, 0.0F, 0.0F); TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.bindTexture(texturemanager.getResourceLocation(stack.getItemSpriteNumber())); Tessellator tessellator = Tessellator.instance; GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glTranslatef(0.65f, 0.6f, -0.1f); // Center on block GL11.glRotatef(135f, 0, 0, 1); ItemRenderer.renderItemIn2D(tessellator, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.06F); GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); }
From source file:ccm.placeableTools.client.ToolRenderer.java
License:Open Source License
public static void doRenderPass(int i, int meta, ItemStack stack, double x, double y, double z) { Icon icon = stack.getItem().getIcon(stack, i); if (icon == null) return;/*from w ww . ja v a 2s . co m*/ GL11.glPushMatrix(); TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.bindTexture(texturemanager.getResourceLocation(stack.getItemSpriteNumber())); Tessellator tessellator = Tessellator.instance; GL11.glTranslated(x, y, z); //Center to block GL11.glEnable(GL12.GL_RESCALE_NORMAL); GL11.glTranslatef(-0.5f, .5f, 0.5f); // Center on block if (stack.getItem() instanceof ItemSpade || stack.getItem() instanceof ItemHoe) { float shift = 0.3f; switch (ForgeDirection.values()[meta]) { case NORTH: GL11.glTranslatef(0, 0, -shift); GL11.glRotatef(15f, -0.5f, 0, 0); break; case SOUTH: GL11.glTranslatef(0, 0, shift); GL11.glRotatef(-15f, -0.5f, 0, 0); break; case EAST: GL11.glRotatef(90f, 0, 1, 0); GL11.glTranslatef(-1, 0, 1); GL11.glTranslatef(0, 0, shift); GL11.glRotatef(-15f, -0.5f, 0, 0); break; case WEST: GL11.glRotatef(90f, 0, 1, 0); GL11.glTranslatef(-1, 0, 1); GL11.glTranslatef(0, 0, -shift); GL11.glRotatef(15f, -0.5f, 0, 0); break; case DOWN: GL11.glRotatef(90f, 0, 1, 0); GL11.glTranslatef(-1, 0, 1); break; } GL11.glTranslatef(0, 0, -0.03f); //Icon depth of the shovel GL11.glRotatef(180f, 1, 0, 0); } else if (stack.getItem() instanceof ItemAxe || stack.getItem() instanceof ItemPickaxe) { float shift = 0.15f; switch (ForgeDirection.values()[meta]) { case NORTH: GL11.glRotatef(90f, 0, 1, 0); GL11.glTranslatef(-1, 0, 1); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-10f, 0, 0, 1); break; case SOUTH: GL11.glRotatef(-90f, 0, 1, 0); GL11.glTranslatef(-1, 0, -1); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-10f, 0, 0, 1); break; case EAST: GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-10f, 0, 0, 1); break; case WEST: GL11.glRotatef(180f, 0, 1, 0); GL11.glTranslatef(-2, 0, 0); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-10f, 0, 0, 1); break; } GL11.glTranslatef(0, 0, 0.03F); } else if (stack.getItem() instanceof ItemSword) { float shift = 0.15f; switch (ForgeDirection.values()[meta]) { case NORTH: GL11.glRotatef(90f, 0, 1, 0); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-90f, 0, 0, 1); GL11.glTranslatef(-1, 0, 1); break; case SOUTH: GL11.glRotatef(-90f, 0, 1, 0); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-90f, 0, 0, 1); GL11.glTranslatef(-1, 0, -1); break; case EAST: GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-90f, 0, 0, 1); GL11.glTranslatef(-1, 1, 0); break; case WEST: GL11.glRotatef(180f, 0, 1, 0); GL11.glTranslatef(-1, 1, 0); GL11.glTranslatef(shift, 0, 0); GL11.glRotatef(-90f, 0, 0, 1); break; case UP: GL11.glRotatef(180f, 1, 0, 0); GL11.glTranslatef(1, 0, 1); GL11.glRotatef(90f, 0, 1, 0); break; case DOWN: GL11.glRotatef(180f, 1, 0, 0); break; } GL11.glTranslatef(-0.05f, 0, 0.03F); } GL11.glRotatef(-45f, 0, 0, 1); GL11.glScalef(1.5f, 1.5f, 1.5f); ItemRenderer.renderItemIn2D(tessellator, icon.getMaxU(), icon.getMinV(), icon.getMinU(), icon.getMaxV(), icon.getIconWidth(), icon.getIconHeight(), 0.06F / 1.5f); if (stack.hasEffect(i)) { GL11.glDepthFunc(GL11.GL_EQUAL); GL11.glDisable(GL11.GL_LIGHTING); texturemanager.bindTexture(RES_ITEM_GLINT); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_COLOR, GL11.GL_ONE); float f7 = 0.76F; GL11.glColor4f(0.5F * f7, 0.25F * f7, 0.8F * f7, 1.0F); GL11.glMatrixMode(GL11.GL_TEXTURE); GL11.glPushMatrix(); float f8 = 0.125F; GL11.glScalef(f8, f8, f8); float f9 = (float) (Minecraft.getSystemTime() % 3000L) / 3000.0F * 8.0F; GL11.glTranslatef(f9, 0.0F, 0.0F); GL11.glRotatef(-50.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.06F / 1.5f); GL11.glPopMatrix(); GL11.glPushMatrix(); GL11.glScalef(f8, f8, f8); f9 = (float) (Minecraft.getSystemTime() % 4873L) / 4873.0F * 8.0F; GL11.glTranslatef(-f9, 0.0F, 0.0F); GL11.glRotatef(10.0F, 0.0F, 0.0F, 1.0F); ItemRenderer.renderItemIn2D(tessellator, 0.0F, 0.0F, 1.0F, 1.0F, 256, 256, 0.06F / 1.5f); GL11.glPopMatrix(); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthFunc(GL11.GL_LEQUAL); } GL11.glDisable(GL12.GL_RESCALE_NORMAL); GL11.glPopMatrix(); }
From source file:cellularautomata.CellularAutomata.java
public static void renderGL() { try { //Trys to create a game window size 500x700. Display.setDisplayMode(new org.lwjgl.opengl.DisplayMode(800, 600)); Display.create();//from w w w . j ava 2 s .com } catch (LWJGLException e) { //Catches exception if game window is not created. e.printStackTrace(); System.exit(0); } GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glShadeModel(GL11.GL_SMOOTH); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_LIGHTING); GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //Sets colour to white. GL11.glClearDepth(1); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glViewport(0, 0, 800, 600); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, 800, 600, 0, 1, -1); GL11.glMatrixMode(GL11.GL_MODELVIEW); Display.setVSyncEnabled(vsync); }
From source file:cellularautomata.CellularAutomata.java
public static void drawTitle(TrueTypeFont trueTypeTitleFont, TrueTypeFont trueTypePaintBrushFont, TrueTypeFont trueTypeDimensionsFont) { GL11.glEnable(GL11.GL_TEXTURE_2D); //Enables textures. trueTypeTitleFont.drawString((800 - trueTypeTitleFont.getWidth("Cellular Automata")) / 2, (600 - trueTypeTitleFont.getHeight("Cellular Automata")) / 2, "Cellular Automata", Color.white); trueTypeDimensionsFont.drawString(650, 570, "By Carson Craig", Color.white); GL11.glDisable(GL11.GL_TEXTURE_2D); //Disables textures. }
From source file:cellularautomata.CellularAutomata.java
public static void drawPath(TrueTypeFont trueTypeTitleFont, TrueTypeFont trueTypeDimensionsFont) { updateColour(7);//from ww w.j a v a2s .com GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(0, 0); GL11.glVertex2f(712, 0); GL11.glVertex2f(712, 600); GL11.glVertex2f(0, 600); GL11.glEnd(); for (int yi = 0; yi < 7; yi++) { updateColour(7); GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(712, yi * 86); GL11.glVertex2f(800, yi * 86); GL11.glVertex2f(800, yi * 86 + 85); GL11.glVertex2f(712, yi * 86 + 85); GL11.glEnd(); } for (int yi = 0; yi < 7; yi++) { for (int xi = 0; xi < 10; xi++) { if (yi == 0) { updateColour(0); } else { updateColour(path[yi - 1][xi]); } GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(xi * 62 + 90, yi * 86); GL11.glVertex2f(xi * 62 + 61 + 90, yi * 86); GL11.glVertex2f(xi * 62 + 61 + 90, yi * 86 + 85); GL11.glVertex2f(xi * 62 + 90, yi * 86 + 85); GL11.glEnd(); } } for (int yi = 0; yi < 7; yi++) { for (int xi = 0; xi < 9; xi = xi + 8) { updateColour(yi); if (xi == 0) { GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(0, yi * 86); GL11.glVertex2f(89, yi * 86); GL11.glVertex2f(89, yi * 86 + 85); GL11.glVertex2f(0, yi * 86 + 85); GL11.glEnd(); } } } GL11.glEnable(GL11.GL_TEXTURE_2D); //Enables textures. for (int i = 0; i < 9; i++) { trueTypeTitleFont.drawString(110 + 62 * i, 20, i + 1 + "", Color.black); } trueTypeTitleFont.drawString(668, 20, "0", Color.black); String dimensions = ""; boolean dimensionsSelected = false; for (int yi = 0; yi < 7; yi++) { if (yi == 0) { dimensions = "800 x 600"; if (pixel == 1) { dimensionsSelected = true; borderSize = 0; } else { dimensionsSelected = false; } } if (yi == 1) { dimensions = "400 x 300"; if (pixel == 2) { dimensionsSelected = true; borderSize = 0; } else { dimensionsSelected = false; } } if (yi == 2) { dimensions = "200 x 150"; if (pixel == 4) { dimensionsSelected = true; borderSize = 0; } else { dimensionsSelected = false; } } if (yi == 3) { dimensions = " 80 x 60"; if (pixel == 10) { dimensionsSelected = true; } else { dimensionsSelected = false; } } if (yi == 4) { dimensions = " 32 x 24"; if (pixel == 25) { dimensionsSelected = true; } else { dimensionsSelected = false; } } if (yi == 5) { dimensions = " 16 x 12"; if (pixel == 50) { dimensionsSelected = true; } else { dimensionsSelected = false; } } if (yi == 6) { dimensions = " 8 x 6"; if (pixel == 100) { dimensionsSelected = true; } else { dimensionsSelected = false; } } if (dimensionsSelected) { trueTypeDimensionsFont.drawString(713, 28 + 86 * yi, dimensions, Color.yellow); } else { trueTypeDimensionsFont.drawString(713, 28 + 86 * yi, dimensions, Color.white); } } GL11.glDisable(GL11.GL_TEXTURE_2D); }
From source file:cellularautomata.CellularAutomata.java
public static void drawWeight(int background, int squares, TrueTypeFont trueTypeTitleFont, TrueTypeFont trueTypePaintBrushFont) { updateColour(background);//from w w w . j a v a 2s . c om GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(0, 0); GL11.glVertex2f(711, 0); GL11.glVertex2f(711, 600); GL11.glVertex2f(0, 600); GL11.glEnd(); Color.black.bind(); for (int yi = 0; yi < 7; yi++) { for (int xi = 0; xi < 9; xi++) { updateColour(squares); if (xi == 0) { updateColour(yi); } if (xi == 8) { updateColour(0); } GL11.glBegin(GL11.GL_QUADS); GL11.glVertex2f(xi * 89, yi * 86); GL11.glVertex2f(xi * 89 + 88, yi * 86); GL11.glVertex2f(xi * 89 + 88, yi * 86 + 85); GL11.glVertex2f(xi * 89, yi * 86 + 85); GL11.glEnd(); } } GL11.glEnable(GL11.GL_TEXTURE_2D); //Enables textures. for (int yi = 0; yi < 7; yi++) { for (int xi = 0; xi < 7; xi++) { if (xi != 3 || yi != 3) { if (squares == 1 || squares == 6) { trueTypeTitleFont.drawString(120 + 89 * xi, 20 + 86 * yi, neighbourhood[yi][xi][menuState] + "", Color.white); } else { trueTypeTitleFont.drawString(120 + 89 * xi, 20 + 86 * yi, neighbourhood[yi][xi][menuState] + "", Color.black); } } } } String stateString = ""; for (int yi = 1; yi < 7; yi++) { if (yi == 1) { if (black == 1) { stateString = " Left"; } else if (black == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 25 + 86 * yi, stateString, Color.black); } if (yi == 2) { if (white == 1) { stateString = " Left"; } else if (white == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 25 + 86 * yi, stateString, Color.white); } if (yi == 3) { if (red == 1) { stateString = " Left"; } else if (red == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 25 + 86 * yi, stateString, Color.red); } if (yi == 4) { if (blue == 1) { stateString = " Left"; } else if (blue == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 25 + 86 * yi, stateString, Color.blue); } if (yi == 5) { if (green == 1) { stateString = " Left"; } else if (green == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 25 + 86 * yi, stateString, Color.green.darker(.7f)); } if (yi == 6) { if (purple == 1) { stateString = " Left"; } else if (purple == 2) stateString = "Right"; else { stateString = " Off"; } trueTypePaintBrushFont.drawString(720, 20 + 86 * yi, stateString, Color.magenta.darker(.7f)); } } if (screenState == 1 && menuState != 6) { trueTypeTitleFont.drawString(745, 20, brushRadius + "", Color.black); } GL11.glDisable(GL11.GL_TEXTURE_2D); }
From source file:chb.mods.mffs.client.TECapacitorRenderer.java
License:Open Source License
@Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { if (tileEntity instanceof TileEntityCapacitor) { TileEntityCapacitor topview = (TileEntityCapacitor) tileEntity; GL11.glPushMatrix();//from ww w . j a v a 2s .com GL11.glPolygonOffset(-10, -10); GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL); int side = topview.getSide(); float dx = 1F / 16; float dz = 1F / 16; float displayWidth = 1 - 2F / 16; float displayHeight = 1 - 2F / 16; GL11.glTranslatef((float) x, (float) y, (float) z); switch (side) { case 1: break; case 0: GL11.glTranslatef(1, 1, 0); GL11.glRotatef(180, 1, 0, 0); GL11.glRotatef(180, 0, 1, 0); break; case 3: GL11.glTranslatef(0, 1, 0); GL11.glRotatef(0, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 2: GL11.glTranslatef(1, 1, 1); GL11.glRotatef(180, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 5: GL11.glTranslatef(0, 1, 1); GL11.glRotatef(90, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 4: GL11.glTranslatef(1, 1, 0); GL11.glRotatef(-90, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; } GL11.glTranslatef(dx + displayWidth / 2, 1F, dz + displayHeight / 2); GL11.glRotatef(-90, 1, 0, 0); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); FontRenderer fontRenderer = this.getFontRenderer(); int maxWidth = 1; String header = "MFFS Capacitor"; maxWidth = Math.max(fontRenderer.getStringWidth(header), maxWidth); maxWidth += 4; int lineHeight = fontRenderer.FONT_HEIGHT + 2; int requiredHeight = lineHeight * 1; float scaleX = displayWidth / maxWidth; float scaleY = displayHeight / requiredHeight; float scale = Math.min(scaleX, scaleY); GL11.glScalef(scale, -scale, scale); GL11.glDepthMask(false); int offsetX; int offsetY; int realHeight = (int) Math.floor(displayHeight / scale); int realWidth = (int) Math.floor(displayWidth / scale); if (scaleX < scaleY) { offsetX = 2; offsetY = (realHeight - requiredHeight) / 2; } else { offsetX = (realWidth - maxWidth) / 2 + 2; offsetY = 0; } GL11.glDisable(GL11.GL_LIGHTING); fontRenderer.drawString(header, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + -2 * lineHeight, 1); fontRenderer.drawString("capacity: ", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 0 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getCapacity()).concat(" % "), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth(String.valueOf(topview.getCapacity()).concat(" % ")), offsetY - realHeight / 2 - 0 * lineHeight, 1); fontRenderer.drawString("range: ", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 1 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getTransmitRange()), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth(String.valueOf(topview.getTransmitRange())), offsetY - realHeight / 2 + 1 * lineHeight, 1); fontRenderer.drawString("linked device: ", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 2 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getLinketProjektor()), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth(String.valueOf(topview.getLinketProjektor())), offsetY - realHeight / 2 + 2 * lineHeight, 1); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthMask(true); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL); GL11.glPopMatrix(); } }
From source file:chb.mods.mffs.client.TEExtractorRenderer.java
License:Open Source License
@Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) { if (tileEntity instanceof TileEntityExtractor) { TileEntityExtractor topview = (TileEntityExtractor) tileEntity; GL11.glPushMatrix();//from ww w .j a va2 s .c o m GL11.glPolygonOffset(-10, -10); GL11.glEnable(GL11.GL_POLYGON_OFFSET_FILL); int side = topview.getSide(); float dx = 1F / 16; float dz = 1F / 16; float displayWidth = 1 - 2F / 16; float displayHeight = 1 - 2F / 16; GL11.glTranslatef((float) x, (float) y, (float) z); switch (side) { case 1: break; case 0: GL11.glTranslatef(1, 1, 0); GL11.glRotatef(180, 1, 0, 0); GL11.glRotatef(180, 0, 1, 0); break; case 3: GL11.glTranslatef(0, 1, 0); GL11.glRotatef(0, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 2: GL11.glTranslatef(1, 1, 1); GL11.glRotatef(180, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 5: GL11.glTranslatef(0, 1, 1); GL11.glRotatef(90, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; case 4: GL11.glTranslatef(1, 1, 0); GL11.glRotatef(-90, 0, 1, 0); GL11.glRotatef(90, 1, 0, 0); break; } GL11.glTranslatef(dx + displayWidth / 2, 1F, dz + displayHeight / 2); GL11.glRotatef(-90, 1, 0, 0); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); FontRenderer fontRenderer = this.getFontRenderer(); int maxWidth = 1; String header = "MFFS Extractor"; maxWidth = Math.max(fontRenderer.getStringWidth(header), maxWidth); maxWidth += 4; int lineHeight = fontRenderer.FONT_HEIGHT + 2; int requiredHeight = lineHeight * 1; float scaleX = displayWidth / maxWidth; float scaleY = displayHeight / requiredHeight; float scale = Math.min(scaleX, scaleY); GL11.glScalef(scale, -scale, scale); GL11.glDepthMask(false); int offsetX; int offsetY; int realHeight = (int) Math.floor(displayHeight / scale); int realWidth = (int) Math.floor(displayWidth / scale); if (scaleX < scaleY) { offsetX = 2; offsetY = (realHeight - requiredHeight) / 2; } else { offsetX = (realWidth - maxWidth) / 2 + 2; offsetY = 0; } GL11.glDisable(GL11.GL_LIGHTING); fontRenderer.drawString(header, offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + -2 * lineHeight, 1); fontRenderer.drawString("WE:", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + -0 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getWorkdone()).concat(" % "), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth(String.valueOf(topview.getWorkdone()).concat(" % ")), offsetY - realHeight / 2 - 0 * lineHeight, 1); fontRenderer.drawString("WC left:", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 1 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getWorkCylce()), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth(String.valueOf(topview.getWorkCylce())), offsetY - realHeight / 2 + 1 * lineHeight, 1); fontRenderer.drawString("FE Cap:", offsetX - realWidth / 2, 1 + offsetY - realHeight / 2 + 2 * lineHeight, 1); fontRenderer.drawString(String.valueOf(topview.getForceEnergybuffer() / 1000).concat("k"), offsetX + realWidth / 2 - offsetX - fontRenderer.getStringWidth( String.valueOf(topview.getForceEnergybuffer() / 1000).concat("k")), offsetY - realHeight / 2 + 2 * lineHeight, 1); GL11.glEnable(GL11.GL_LIGHTING); GL11.glDepthMask(true); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL); GL11.glPopMatrix(); } }
From source file:cheatingessentials.mod.internal.ttf.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. * /*ww w . j a v a 2 s . c om*/ * @param str * the string being rendered; it can contain color codes * @param startX * the x coordinate to draw at * @param startY * the y coordinate to draw at * @param initialColor * 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(final String str, final float startX, float startY, final int initialColor, final 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 */ final 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 */ final 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 */ final 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. */ final char c = str.charAt(glyph.stringIndex); if ((c >= '0') && (c <= '9')) { final int oldWidth = texture.width; texture = digitGlyphs[fontStyle][c - '0'].texture; final 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 */ final float x1 = startX + ((glyphX) / 2.0F); final float x2 = startX + ((glyphX + texture.width) / 2.0F); final float y1 = startY + ((glyph.y) / 2.0F); final 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 */ final Glyph glyph = entry.glyphs[glyphIndex]; /* * The strike/underlines are drawn beyond the glyph's width to * include the extra space between glyphs */ final 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 */ final float x1 = startX + ((glyph.x - glyphSpace) / 2.0F); final float x2 = startX + ((glyph.x + glyph.advance) / 2.0F); final float y1 = startY + ((UNDERLINE_OFFSET) / 2.0F); final 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 */ final float x1 = startX + ((glyph.x - glyphSpace) / 2.0F); final float x2 = startX + ((glyph.x + glyph.advance) / 2.0F); final float y1 = startY + ((STRIKETHROUGH_OFFSET) / 2.0F); final 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); } if (antiAliasEnabled) { GL11.glDisable(GL11.GL_BLEND); } /* * Return total horizontal advance (slightly wider than the bounding * box, but close enough for centering strings) */ return entry.advance / 2; }
From source file:chemistry.electrolysm.client.RenderTileBunsenBurner.java
License:Open Source License
@Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float v4) { renderTripod = ((TileEntityBunsenBurner) tileEntity).hasStand(); renderTestTube = ((TileEntityBunsenBurner) tileEntity).hasTestTube(); //System.out.println("render"); GL11.glPushMatrix();//from w w w .j a v a 2 s .c o m GL11.glEnable(GL11.GL_LIGHTING); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); rotateByMeta(tileEntity.getBlockMetadata()); Block block = tileEntity.getWorldObj().getBlock(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord); if (block instanceof BlockBBElectric) { bindTexture(CommonProxy.MODEL_BB_ELECTRIC); } else if (block instanceof BlockBBGas) { bindTexture(CommonProxy.MODEL_BB_GAS); } else { bindTexture(CommonProxy.MODEL_BUNSEN_BURNER); } GL11.glScalef(1.0F, -1.0F, -1.0F); model.render(null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); if (renderTripod) { model.renderStand(0.0625F); if (renderTestTube) { model.renderTestTube(0.0625F); } } GL11.glDisable(GL11.GL_LIGHTING); GL11.glPopMatrix(); }