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:org.spoutcraft.client.gui.MCRenderDelegate.java
License:Open Source License
public void render(GenericGradient gradient) { GL11.glDisable(GL11.GL_TEXTURE_2D);/* w w w . j ava 2s. c o m*/ GL11.glEnable(GL11.GL_BLEND); GL11.glDisable(GL11.GL_ALPHA_TEST); GL11.glBlendFunc(770, 771); GL11.glShadeModel(GL11.GL_SMOOTH); Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); boolean VERT = gradient.getOrientation() == Orientation.VERTICAL; tessellator.setColorRGBA_F(gradient.getTopColor().getRedF(), gradient.getTopColor().getGreenF(), gradient.getTopColor().getBlueF(), gradient.getTopColor().getAlphaF()); tessellator.addVertex((VERT ? gradient.getWidth() : 0) + gradient.getScreenX(), (VERT ? 0 : gradient.getHeight()) + gradient.getScreenY(), 0.0D); tessellator.addVertex(gradient.getScreenX(), gradient.getScreenY(), 0.0D); tessellator.setColorRGBA_F(gradient.getBottomColor().getRedF(), gradient.getBottomColor().getGreenF(), gradient.getBottomColor().getBlueF(), gradient.getBottomColor().getAlphaF()); tessellator.addVertex((VERT ? 0 : gradient.getWidth()) + gradient.getScreenX(), (VERT ? gradient.getHeight() : 0) + gradient.getScreenY(), 0.0D); tessellator.addVertex(gradient.getWidth() + gradient.getScreenX(), gradient.getHeight() + gradient.getScreenY(), 0.0D); tessellator.draw(); GL11.glShadeModel(GL11.GL_FLAT); GL11.glDisable(GL11.GL_BLEND); GL11.glEnable(GL11.GL_ALPHA_TEST); GL11.glEnable(GL11.GL_TEXTURE_2D); }
From source file:org.spoutcraft.client.gui.MCRenderDelegate.java
License:Open Source License
public void render(GenericBitmap bitmap) { int textureId; if (bitmapId.containsKey(bitmap)) { textureId = bitmapId.get(bitmap); } else {//from w w w.j av a2s . c o m IntBuffer tmp = IntBuffer.allocate(1); GL11.glGenTextures(tmp); textureId = tmp.get(0); bitmapId.put(bitmap, textureId); } int width = (int) bitmap.getActualWidth(); int height = (int) bitmap.getActualHeight(); int left = bitmap.getLeft(); int top = bitmap.getTop(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, bitmap.getRawWidth(), bitmap.getRawHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, bitmap.getBuffer()); GL11.glTranslatef((float) bitmap.getScreenX(), (float) bitmap.getScreenY(), 0); // moves texture into place GL11.glPushMatrix(); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(770, 771); GL11.glDepthMask(false); bindColor(new Color(1.0F, 1.0F, 1.0F)); SpoutClient.getHandle().renderEngine.bindTexture(textureId); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); double tLeft = 0, tTop = 0, rWidth = bitmap.getWidth(), rHeight = bitmap.getHeight(), tWidth = rWidth, tHeight = rHeight; if (top >= 0 && left >= 0) { tWidth = Math.min(tWidth, width); tHeight = Math.min(tHeight, height); tLeft = Math.min(Math.max(0, left), rWidth); tTop = Math.min(Math.max(0, top), rHeight); } Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop); // draw corners tessellator.addVertexWithUV(width, height, -90, tWidth, tTop); tessellator.addVertexWithUV(width, 0.0D, -90, tWidth, tHeight); tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tHeight); tessellator.draw(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); GL11.glDisable(GL11.GL_BLEND); }
From source file:org.spoutcraft.client.gui.MCRenderDelegate.java
License:Open Source License
public void drawTexture(Texture textureBinding, int width, int height, Color color, boolean blend, int left, int top, boolean mipmap, int filter) { if (textureBinding == null) { return;/*from w w w .jav a 2s . c o m*/ } GL11.glPushMatrix(); GL11.glDisable(GL11.GL_DEPTH_TEST); boolean wasBlend = GL11.glGetBoolean(GL11.GL_BLEND); if (blend) { GL11.glEnable(GL11.GL_BLEND); GL11.glBlendFunc(770, 771); } GL11.glDepthMask(false); bindColor(color); SpoutClient.getHandle().renderEngine.bindTexture(textureBinding.getTextureID()); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, filter); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, filter); if (mipmap) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL12.GL_TEXTURE_MAX_LOD, 8); ContextCapabilities capabilities = GLContext.getCapabilities(); if (capabilities.OpenGL30) { GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D); } else if (capabilities.GL_EXT_framebuffer_object) { EXTFramebufferObject.glGenerateMipmapEXT(GL11.GL_TEXTURE_2D); } else if (capabilities.OpenGL14) { GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL14.GL_GENERATE_MIPMAP, GL11.GL_TRUE); } } double tLeft = 0, tTop = 0, rWidth = textureBinding.getWidth(), rHeight = textureBinding.getHeight(), tWidth = rWidth, tHeight = rHeight; if (top >= 0 && left >= 0) { tWidth = Math.min(tWidth, (width / (double) textureBinding.getImageWidth()) * textureBinding.getWidth()); tHeight = Math.min(tHeight, (height / (double) textureBinding.getImageHeight()) * textureBinding.getHeight()); tLeft = Math.min( Math.max(0, (left / (double) textureBinding.getImageWidth())) * textureBinding.getWidth(), rWidth); tTop = Math.min( Math.max(0, (top / (double) textureBinding.getImageHeight()) * textureBinding.getHeight()), rHeight); } tHeight = -tHeight; tTop = rHeight - tTop; Tessellator tessellator = Tessellator.instance; tessellator.startDrawingQuads(); tessellator.addVertexWithUV(0.0D, height, -90, tLeft, tTop + tHeight); // draw corners tessellator.addVertexWithUV(width, height, -90, tLeft + tWidth, tTop + tHeight); tessellator.addVertexWithUV(width, 0.0D, -90, tLeft + tWidth, tTop); tessellator.addVertexWithUV(0.0D, 0.0D, -90, tLeft, tTop); tessellator.draw(); GL11.glDepthMask(true); GL11.glEnable(GL11.GL_DEPTH_TEST); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glPopMatrix(); if (blend && !wasBlend) { GL11.glDisable(GL11.GL_BLEND); } }
From source file:org.spoutcraft.client.gui.minimap.MapRenderer.java
License:Open Source License
private void renderMap() { GL11.glDisable(2929);//from w ww .ja v a 2s.c o m GL11.glEnable(3042); GL11.glDepthMask(false); GL11.glBlendFunc(770, 0); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); if (MinimapConfig.getInstance().isEnabled()) { if (MinimapConfig.getInstance().isSquare()) { // Scale GL11.glPushMatrix(); switch (MinimapConfig.getInstance().getZoom()) { case 0: GL11.glScalef(8F, 8F, 1F); GL11.glTranslatef(56, 0, 0F); break; case 1: GL11.glScalef(4F, 4F, 1F); GL11.glTranslatef(48, 0, 0F); break; case 2: GL11.glScalef(2F, 2F, 1F); GL11.glTranslatef(32, 0, 0F); break; } map.loadColorImage(); drawOnMap(); if (MinimapConfig.getInstance().isHeightmap()) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_COLOR); map.loadHeightImage(); drawOnMap(); } GL11.glPopMatrix(); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); renderEntities(); try { GL11.glPushMatrix(); GL11.glScalef(1.8f, 1.8f, 1.0f); GL11.glTranslatef(27, -1, 0F); // don't ask if (MinimapConfig.getInstance().isShowBackground()) { texman.loadMinimap(); } else { GL11.glScalef(138F / 256F, 138F / 256F, 1F); GL11.glTranslatef(-54, 0, 0); texman.loadWhiteMinimap(); } drawOnMap(); } catch (Exception e) { // System.err.println("error: minimap overlay not found!"); // e.printStackTrace(); } finally { GL11.glPopMatrix(); } renderWaypoints(); try { GL11.glPushMatrix(); texman.loadMMArrow(); GL11.glTranslatef(-34.0F, 30.0F, 0.0F); GL11.glRotatef(-this.direction + 90F, 0.0F, 0.0F, 1.0F); GL11.glTranslatef(32.0F, -(32.0F), 0.0F); drawOnMap(); } catch (Exception e) { // System.err.println("Error: minimap arrow not found!"); e.printStackTrace(); } finally { GL11.glPopMatrix(); } GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // render directions with fudge factor to make them line up GL11.glPushMatrix(); GL11.glTranslatef(-2, 2, 0.0F); drawDirections(); drawFocusSquare(); GL11.glPopMatrix(); } else { GL11.glPushMatrix(); map.loadColorImage(); GL11.glTranslatef(-32.0f, 32.0F, 0.0F); GL11.glRotatef(this.direction + 90.0F, 0.0F, 0.0F, 1.0F); GL11.glTranslatef(32.0F, -(32.0F), 0.0F); switch (MinimapConfig.getInstance().getZoom()) { case 0: GL11.glScalef(8F, 8F, 1F); GL11.glTranslatef(56.25F, 0.25F, 0F); break; case 1: GL11.glScalef(4F, 4F, 1F); GL11.glTranslatef(48.5F, 0.5F, 0F); break; case 2: GL11.glScalef(2F, 2F, 1F); GL11.glTranslatef(33F, 1F, 0F); break; case 3: GL11.glTranslatef(2F, 2F, 0F); break; } drawOnMap(); if (MinimapConfig.getInstance().isHeightmap()) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_COLOR); map.loadHeightImage(); drawOnMap(); } GL11.glPopMatrix(); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); renderWaypoints(); renderEntities(); drawRound(); drawDirections(); GL11.glPushMatrix(); drawFocusRound(); GL11.glPopMatrix(); } } }
From source file:org.spoutcraft.client.gui.minimap.MapWidget.java
License:Open Source License
@Override public void renderContents() { GL11.glDisable(2929);//from w ww .j a v a 2 s. c o m GL11.glEnable(3042); GL11.glDepthMask(false); GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); int scrollX = (int) (getScrollPosition(Orientation.HORIZONTAL) / scale); int scrollY = (int) (getScrollPosition(Orientation.VERTICAL) / scale); GL11.glScaled(scale, scale, scale); GL11.glTranslatef(-heightMap.getMinX() * 16, -heightMap.getMinZ() * 16, 0); int minChunkX = heightMap.getMinX() + scrollX / 16, minChunkZ = heightMap.getMinZ() + scrollY / 16, maxChunkX = 0, maxChunkZ = 0; int horiz = (int) (getWidth() / 16 / scale) + 1; int vert = (int) (getHeight() / 16 / scale) + 1; maxChunkX = minChunkX + horiz; maxChunkZ = minChunkZ + vert; minChunkX = Math.max(minChunkX, heightMap.getMinX()); minChunkZ = Math.max(minChunkZ, heightMap.getMinZ()); maxChunkX = Math.min(maxChunkX, heightMap.getMaxX()); maxChunkZ = Math.min(maxChunkZ, heightMap.getMaxZ()); GL11.glPushMatrix(); synchronized (chunks) { for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX += levelOfDetail) { for (int chunkZ = minChunkZ; chunkZ <= maxChunkZ; chunkZ += levelOfDetail) { Map map = getChunkMap(levelOfDetail).get(chunkX, chunkZ); if (dirty || map == null || random.nextInt(10000) == 0) { renderer.renderQueue.add(new Point(chunkX, chunkZ)); } if (map != null && map != blankMap) { GL11.glPushMatrix(); int x = chunkX * 16; int y = chunkZ * 16; int width = x + 16 * levelOfDetail; int height = y + 16 * levelOfDetail; map.loadColorImage(); MinecraftTessellator tessellator = Spoutcraft.getTessellator(); tessellator.startDrawingQuads(); tessellator.addVertexWithUV((double) width, (double) height, -90, 1, 1); tessellator.addVertexWithUV((double) width, (double) y, -90, 1, 0); tessellator.addVertexWithUV((double) x, (double) y, -90, 0, 0); tessellator.addVertexWithUV((double) x, (double) height, -90, 0, 1); tessellator.draw(); // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // RenderUtil.drawRectangle(x, y, width, height, 0x88ffffff); if (MinimapConfig.getInstance().isHeightmap()) { GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_DST_COLOR); map.loadHeightImage(); tessellator.startDrawingQuads(); tessellator.addVertexWithUV((double) width, (double) height, -90, 1, 1); tessellator.addVertexWithUV((double) width, (double) y, -90, 1, 0); tessellator.addVertexWithUV((double) x, (double) y, -90, 0, 0); tessellator.addVertexWithUV((double) x, (double) height, -90, 0, 1); tessellator.draw(); } GL11.glPopMatrix(); } } } } int x = (int) SpoutClient.getHandle().thePlayer.posX; int z = (int) SpoutClient.getHandle().thePlayer.posZ; drawPOI("You", x, z, 0xffff0000); for (Waypoint waypoint : MinimapConfig.getInstance().getAllWaypoints(MinimapUtils.getWorldName())) { if (!waypoint.deathpoint || MinimapConfig.getInstance().isDeathpoints()) { drawPOI(waypoint.name, waypoint.x, waypoint.z, 0xff00ff00); } } if (MinimapConfig.getInstance().getFocussedWaypoint() != null) { Waypoint pos = MinimapConfig.getInstance().getFocussedWaypoint(); drawPOI("Marker", pos.x, pos.z, 0xff00ffff); } GL11.glPopMatrix(); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(2929); GL11.glDisable(3042); dirty = false; Point newpos = getPlayerPosition(); if (lastPlayerPos.getX() != newpos.getX() || lastPlayerPos.getY() != newpos.getY()) { showPlayer(0); lastPlayerPos = newpos; } }
From source file:org.spoutcraft.spoutcraftapi.gui.ChatTextBox.java
License:Open Source License
public void render() { GL11.glEnable(GL11.GL_BLEND);//from w ww .j a va2 s. c o m GL11.glBlendFunc(GL11.GL_SRC_ALPHA, 771); if (!isVisible()) { return; } float chatOpacity = Spoutcraft.getChatManager().getOpacity(); int scroll = Spoutcraft.getChatManager().getScroll(); MinecraftFont font = Spoutcraft.getMinecraftFont(); Iterator<ChatMessage> iter = chatMessages.iterator(); for (int i = 0; i < scroll; i++) { if (iter.hasNext()) { iter.next(); } } int lines = 0; int bottom = (int) getScreen().getHeight() - 50; while (iter.hasNext()) { ChatMessage message = iter.next(); if (message.isIgnoredPerson() && Spoutcraft.getChatManager().isIgnoringPlayers()) { continue; } if (message.isJoinMessage() && !Spoutcraft.getChatManager().isShowingJoins()) { continue; } double opacity = 1D; if (message.getAge() > getFadeoutTicks() - 20) { opacity = 1D - ((double) message.getAge() - (double) getFadeoutTicks()) / 20d; } if (opacity > 1.0d) { opacity = 1.0d; } if (opacity < 0.0d) { opacity = 0.0d; } if (message.getAge() > getFadeoutTicks() + 20 && !chatOpen) { break; } if (chatOpen) { opacity = 1D; } if (opacity == 0) { continue; } //int chatColor = (chatOpen ? 255 : (int)(255D * opacity)); int chatColor = 0x00ffffff; int textAlpha = (int) (opacity * 255) << 24; chatColor |= textAlpha; int backgroundAlpha = (int) (Math.min(chatOpacity, opacity) * 255) << 24; int backgroundColor = 0x00000000 | backgroundAlpha; if (Spoutcraft.getChatManager().isHighlightingWords() && message.isHighlighted() && !message.isJoinMessage()) { backgroundColor = 0x00ff0000 | backgroundAlpha; } RenderUtil.drawRectangle(3, bottom - 1, 3 + 320, bottom + 9, backgroundColor); font.drawShadowedString(message.getUnparsedMessage(), 4, bottom, chatColor); bottom -= 10; lines++; if (!chatOpen && lines > visibleLines) { break; } else if (chatOpen && lines > visibleChatLines) { break; } } GL11.glDisable(GL11.GL_BLEND); }
From source file:org.terasology.rendering.dag.nodes.SimpleBlendMaterialsNode.java
License:Apache License
@Override public void process() { PerformanceMonitor.startActivity("rendering/simpleBlendMaterials"); READ_ONLY_GBUFFER.setRenderBufferMask(true, true, true); // TODO: make a glBlendFunc StateChange and eliminate this line GL11.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // (*) // (*) In this context SRC is Foreground. This effectively says: // Resulting RGB = ForegroundRGB * ForegroundAlpha + BackgroundRGB * (1 - ForegroundAlpha) // Which might still look complicated, but it's actually the most typical alpha-driven composite. // A neat tool to play with this settings can be found here: http://www.andersriggelsen.dk/glblendfunc.php for (RenderSystem renderer : componentSystemManager.iterateRenderSubscribers()) { renderer.renderAlphaBlend();/*from www.j a va2 s.c o m*/ } PerformanceMonitor.endActivity(); }
From source file:org.terasology.rendering.opengl.GraphicState.java
License:Apache License
/** * Sets the state for the rendering of objects or portions of objects having some degree of transparency. * * Generally speaking objects drawn with this state will have their color blended with the background * color, depending on their opacity. I.e. a 25% opaque foreground object will provide 25% of its * color while the background will provide the remaining 75%. The sum of the two RGBA vectors gets * written onto the output buffer./* ww w . j a v a 2 s .co m*/ * * Important note: this method disables writing to the Depth Buffer. This is why filters relying on * depth information (i.e. DoF) have problems with transparent objects: the depth of their pixels is * found to be that of the background. This is an unresolved (unresolv-able?) issue that would only * be reversed, not eliminated, by re-enabling writing to the Depth Buffer. */ public void preRenderSetupSimpleBlendMaterials() { buffers.sceneOpaque.bind(); setRenderBufferMask(buffers.sceneOpaque, true, true, true); GL11.glEnable(GL_BLEND); GL11.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // (*) GL11.glDepthMask(false); // (*) In this context SRC is Foreground. This effectively says: // Resulting RGB = ForegroundRGB * ForegroundAlpha + BackgroundRGB * (1 - ForegroundAlpha) // Which might still look complicated, but it's actually the most typical alpha-driven composite. // A neat tool to play with this settings can be found here: http://www.andersriggelsen.dk/glblendfunc.php }
From source file:org.voxels.platform.LWJGLOpenGLAdapter.java
License:Open Source License
@Override public void glBlendFunc(final int sfactor, final int dfactor) { GL11.glBlendFunc(sfactor, dfactor); }
From source file:org.xmlvm.iphone.gl.GL.java
License:Open Source License
public static void glBlendFunc(int src, int dst) { GL11.glBlendFunc(src, dst); }