List of usage examples for org.lwjgl.opengl GL11 glBlendFunc
public static void glBlendFunc(@NativeType("GLenum") int sfactor, @NativeType("GLenum") int dfactor)
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();/* w ww .j a v a2 s. c o m*/ } 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: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. * /*from w ww . j a v a2s.co m*/ * @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:chessMod.client.ChessModDrawBlockHighlightHandler.java
License:LGPL
public static void drawQuad(float x, float y, float width, float height, double zLevel) { GL11.glDisable(GL11.GL_LIGHTING);// ww w .j ava 2s . c om GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glLineWidth(5.0F); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(0F, 1F, 0F, pulseTransparency); Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertex(x + 0F, y + height, zLevel); tessellator.addVertex(x + width, y + height, zLevel); tessellator.addVertex(x + width, y + 0F, zLevel); tessellator.addVertex(x + 0F, y + 0F, zLevel); tessellator.draw(); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glEnable(GL11.GL_LIGHTING); }
From source file:cn.academy.ability.client.render.RenderDeveloperAdvanced.java
License:GNU General Public License
@Override public void drawAtOrigin(TileEntity te) { GL11.glDisable(GL11.GL_CULL_FACE);//from www. j a v a2 s.c o m GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); super.drawAtOrigin(te); GL11.glEnable(GL11.GL_CULL_FACE); }
From source file:cn.academy.ability.electro.client.render.skill.SRSmallCharge.java
License:Open Source License
@Override public void draw() { GL11.glDisable(GL11.GL_CULL_FACE);//www. ja va 2s . c o m GL11.glDepthMask(false); GL11.glPushMatrix(); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4d(1, 1, 1, 0.7); GL11.glTranslated(0, 0.9, 0.2); GL11.glRotated(120, 1, 0, 0); GL11.glScaled(0.5, 0.5, 0.5); //RenderUtils.drawCube(1, 1, 2); for (ArcObject arc : arcs) { arc.draw(); } GL11.glPopMatrix(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_CULL_FACE); }
From source file:cn.academy.core.client.gui.GuiMainScreen.java
License:Open Source License
@Override public void draw(ScaledResolution sr) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; AbilityData data = AbilityDataMain.getData(player); double w = sr.getScaledWidth_double(), h = sr.getScaledHeight_double(); double size = 80.0, x = w - 80, y = h - 65; boolean active = EventHandlerClient.isSkillEnabled(); long time = Minecraft.getSystemTime(); GL11.glEnable(GL11.GL_BLEND);/*from w w w.j ava 2s. c om*/ GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPushMatrix(); { GL11.glPushMatrix(); { //Logo rendering double scale = .25; double mAlpha = active ? 0.8 : 0.4; HudUtils.setTextureResolution(256, 256); GL11.glTranslated(w - 80, h - 70, 0); GL11.glScaled(scale, scale, 1); GL11.glColor4d(1, 1, 1, mAlpha); logoBack.draw(); GL11.glColor4d(1, 1, 1, (mAlpha * 1.25) * (0.7 + Math.sin(time / 900D) * 0.3)); logoRays.draw(); GL11.glColor4d(1, 1, 1, mAlpha); logoBack.draw(); logoFrame.draw(); RenderUtils.loadTexture(data.getCategory().getLogo()); HudUtils.drawRect(63, 63, 129, 129); logoGeom.getTransform().setRoll(time / 1000D); logoGeom.draw(); } GL11.glPopMatrix(); RenderUtils.bindIdentity(); //CPBar rendering if (active) { lastActiveTime = time; } else { lastInactiveTime = time; } double mAlpha = active ? Math.min((time - lastInactiveTime) / 300D, 1.0) : Math.max((300 + lastActiveTime - time) / 300D, 0.0); if (mAlpha > 0) { //Cooldown drawCooldownBars(data, mAlpha, w, h); GL11.glColor4d(1, 1, 1, mAlpha * 0.6); RenderUtils.loadTexture(ACClientProps.TEX_HUD_BAR); HudUtils.setTextureResolution(512, 200); double scale = .4; GL11.glTranslated(w - 193, 17, 0); GL11.glScaled(scale, scale, 0); //Back HudUtils.drawRect(0, 0, 0, 73, 455, 127, 455, 127); //CPBar double prog = data.getCurrentCP() / data.getMaxCP(); int[] cs = data.getCategory().getColorStyle(); RenderUtils.bindColor(cs[0], cs[1], cs[2], (int) (mAlpha * 255)); HudUtils.drawRect(439 - 436 * prog, 3, 439 - 436 * prog, 4, 436 * prog, 28, 436 * prog, 28); //CPBar glow double alpha = Math.max(0, (prog - 0.6) / 0.4); GL11.glColor4d(1, 1, 1, alpha * mAlpha); HudUtils.drawRect(3, 3, 3, 42, 436, 28, 436, 28); //Chip HudUtils.drawRect(269, 46, 478, 40, 26, 26, 26, 26); alpha = 0.5 + 0.5 * Math.sin(Minecraft.getSystemTime() / 500D); RenderUtils.bindColor(cs[0], cs[1], cs[2], (int) (alpha * mAlpha * 255)); //Chip glow light HudUtils.drawRect(266, 45, 474, 5, 32, 32, 32, 32); //Level GL11.glColor4d(1, 1, 1, mAlpha * .6); ACClientProps.FONT_YAHEI_32.drawAdjusted(data.getLevel().getDisplayName(), 184, 58, 20, 69); //Numeric CP String str = String.format("%.0f/%.0f", data.getCurrentCP(), data.getMaxCP()); font.drawAdjusted(str, 316, 87, 22, Align.CENTER, 167); } } GL11.glPopMatrix(); RenderUtils.bindIdentity(); GL11.glDisable(GL11.GL_BLEND); }
From source file:cn.academy.core.client.render.SkillRenderDebug.java
License:Open Source License
@SideOnly(Side.CLIENT) @Override//from w w w. ja v a 2 s .co m public void renderSurroundings(EntityPlayer player, long time) { GL11.glPushMatrix(); { GL11.glTranslated(-.5, 0, -.5); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glColor4f(1, 1, 1, 0.3F); RenderUtils.drawCube(1, 1, 2); GL11.glDisable(GL11.GL_BLEND); } GL11.glPopMatrix(); }
From source file:cn.academy.core.client.render.SkillRenderManager.java
License:Open Source License
public static void renderThirdPerson(EntityLivingBase ent, ItemStack stack, ItemRenderType type) { if (type == ItemRenderType.EQUIPPED_FIRST_PERSON || !(ent instanceof EntityPlayer)) return;//from ww w . j a v a 2 s.c om EntityPlayer player = (EntityPlayer) ent; Item item = stack.getItem(); Block block = Block.getBlockFromItem(stack.getItem()); GL11.glDepthFunc(GL11.GL_LEQUAL); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPushMatrix(); { GL11.glColor4d(1, 0.6, 0.6, 0.55); if (stack.getItemSpriteNumber() == 0 && item instanceof ItemBlock) { //block render routine GL11.glTranslated(0, 0, 1.5); GL11.glScalef(2F, 2F, 2F); GL11.glRotated(45, 1, 0, 1); GL11.glRotated(45, 0, 1, 0); GL11.glRotated(180, 1, 0, 0); } else if (item.isFull3D()) { GL11.glTranslated(0.1, 0.8, -.4); GL11.glScalef(.8F, .8F, .8F); GL11.glRotated(45, 0, 0, -1); } else { GL11.glTranslated(-.3, 1.2, -.6); GL11.glRotatef(90, 1, 0, 0); GL11.glScalef(1.5F, 1.5F, 1.5F); } traverseHandRender(player, HandRenderType.EQUIPPED); } GL11.glPopMatrix(); }
From source file:cn.academy.core.client.render.SkillRenderManager.java
License:Open Source License
public static void renderFirstPerson() { //System.out.println("rfp"); GL11.glDepthFunc(GL11.GL_LEQUAL);//from w w w . j a v a 2s . c o m GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPushMatrix(); { GL11.glTranslated(0.28, -0.55, -.9); GL11.glColor4d(1, 0.6, 0.6, 0.55); GL11.glScalef(0.66F, 0.66F, 0.66F); GL11.glRotatef(20, 1, 0, 0); //RenderUtils.loadTexture(ACClientProps.TEX_ARC_SHELL[0]); //RenderUtils.drawCube(1, 1, 1, false); traverseHandRender(Minecraft.getMinecraft().thePlayer, HandRenderType.FIRSTPERSON); //rpe.renderHandEffect(Minecraft.getMinecraft().thePlayer, null, HandRenderType.FIRSTPERSON); } GL11.glPopMatrix(); }
From source file:cn.academy.crafting.client.render.block.RenderImagPhaseLiquid.java
License:GNU General Public License
@Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float w) { if (!(te.getBlockType() instanceof BlockFluidClassic)) return;//from ww w . ja v a 2 s . co m BlockFluidClassic liq = (BlockFluidClassic) te.getBlockType(); double distSq = Minecraft.getMinecraft().thePlayer.getDistanceSq(te.xCoord + .5, te.yCoord + .5, te.zCoord + .5); double alpha = 1 / (1 + 0.2 * Math.pow(distSq, 0.5)); if (alpha < 1E-1) return; GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glPushMatrix(); GL11.glTranslated(x, y, z); GL11.glDepthMask(false); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glDisable(GL11.GL_CULL_FACE); GL11.glColor4d(1, 1, 1, alpha); //GL11.glColor4d(1, 1, 1, 1); RenderHelper.disableStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.defaultTexUnit, 240f, 240f); double ht = 1.2 * Math.sqrt(rbf.getFluidHeightForRender(te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord, (BlockFluidBase) te.getBlockType())); GL11.glEnable(GL11.GL_BLEND); drawLayer(0, -0.3 * ht, 0.3, 0.2, 0.7); drawLayer(1, 0.35 * ht, 0.3, 0.05, 0.7); if (ht > 0.5) drawLayer(2, 0.7 * ht, 0.1, 0.25, 0.7); RenderHelper.enableStandardItemLighting(); GL11.glEnable(GL11.GL_CULL_FACE); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glDepthMask(true); GL11.glPopMatrix(); }