List of usage examples for org.lwjgl.opengl GL11 glBindTexture
public static void glBindTexture(@NativeType("GLenum") int target, @NativeType("GLuint") int texture)
From source file:engine.render.TexturedQuad.java
public void renderQuad() { int shaderID = shader.getProgramID(); GL20.glUseProgram(shaderID);//from w w w. j a v a 2 s . co m glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); GL30.glBindVertexArray(vaoId); GL20.glEnableVertexAttribArray(0); GL20.glEnableVertexAttribArray(1); GL20.glEnableVertexAttribArray(2); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, vboiId); glUniform2f(glGetUniformLocation(shaderID, "scale"), scale.x, scale.y); glUniform2f(glGetUniformLocation(shaderID, "translation"), translation.x, translation.y); glUniform2f(glGetUniformLocation(shaderID, "cameraOffset"), cameraOffset.x, cameraOffset.y); glUniform1f(glGetUniformLocation(shaderID, "rotation"), rotation); glUniform2f(glGetUniformLocation(shaderID, "resolution"), resolution.x, resolution.y); GL11.glDrawElements(GL11.GL_TRIANGLES, indicesCount, GL11.GL_UNSIGNED_BYTE, 0); GL15.glBindBuffer(GL15.GL_ELEMENT_ARRAY_BUFFER, 0); GL20.glDisableVertexAttribArray(0); GL20.glDisableVertexAttribArray(1); GL20.glDisableVertexAttribArray(2); GL30.glBindVertexArray(0); glDisable(GL_BLEND); GL20.glUseProgram(0); }
From source file:espresso3d.engine.fileloaders.E3DImageLoader.java
License:Open Source License
public static E3DTexture loadImageIntoGL(E3DEngine engine, String textureName, Image image) { // Extract The Image BufferedImage tex = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = (Graphics2D) tex.getGraphics(); g.drawImage(image, null, null);// w w w . j av a 2 s.c o m g.dispose(); // Flip Image AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -image.getHeight(null)); AffineTransformOp op = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); tex = op.filter(tex, null); // Put Image In Memory ByteBuffer scratch = ByteBuffer.allocateDirect(4 * tex.getWidth() * tex.getHeight()); byte data[] = (byte[]) tex.getRaster().getDataElements(0, 0, tex.getWidth(), tex.getHeight(), null); scratch.clear(); scratch.put(data); scratch.rewind(); // Create A IntBuffer For Image Address In Memory IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer(); GL11.glGenTextures(buf); // Create Texture In OpenGL GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0)); // Typical Texture Generation Using Data From The Image // Linear Filtering GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); // Linear Filtering GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); // Generate The Texture GLU.gluBuild2DMipmaps(GL11.GL_TEXTURE_2D, 3, tex.getWidth(), tex.getHeight(), GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch); // GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tex.getWidth(), tex.getHeight(), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch); E3DTexture texture = new E3DTexture(engine, textureName, buf.get(0)); texture.setWidth(image.getWidth(null)); texture.setHeight(image.getHeight(null)); return texture; // Return Image Address In Memory }
From source file:espresso3d.engine.renderer.E3DGeometryRenderer.java
License:Open Source License
public void initTextureUnit(int unitNum, int glTextureID) { if (unitNum == 0) ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB); else if (unitNum == 1) ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE1_ARB); else if (unitNum == 2) ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE2_ARB); GL11.glEnable(GL11.GL_TEXTURE_2D);//from w w w . j a va 2 s. c o m GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTextureID); // GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); // GL11.glEnableClientState(GL11.GL_COLOR_ARRAY); // GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); // ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB); // GL11.glEnable(GL11.GL_TEXTURE_2D); }
From source file:espresso3d.engine.renderer.E3DGeometryRenderer.java
License:Open Source License
/*********************************/ public void setupTextureUnits(int glTextureID, int detail0TextureID, int detail1TextureID) { ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE0_ARB); if (glTextureID != -1) { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTextureID); /* if(detail0TextureID != -1) {/* www . ja v a 2 s.co m*/ GL11.glTexEnvf (GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, ARBTextureEnvCombine.GL_COMBINE_ARB); GL11.glTexEnvf (GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_COMBINE_RGB_ARB, GL11.GL_REPLACE); } else {*/ GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, GL11.GL_MODULATE); // } } else GL11.glDisable(GL11.GL_TEXTURE_2D); if (getEngine().getFeatureChecker().getArbMultitextureNumTexUnitsSupported() < 2) return; ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE1_ARB); if (detail0TextureID != -1) { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, detail0TextureID); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, ARBTextureEnvCombine.GL_COMBINE_ARB); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_COMBINE_RGB_ARB, GL11.GL_ADD); } else GL11.glDisable(GL11.GL_TEXTURE_2D); if (getEngine().getFeatureChecker().getArbMultitextureNumTexUnitsSupported() < 3) return; ARBMultitexture.glActiveTextureARB(ARBMultitexture.GL_TEXTURE2_ARB); if (detail1TextureID != -1) { GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBindTexture(GL11.GL_TEXTURE_2D, detail1TextureID); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, GL11.GL_TEXTURE_ENV_MODE, ARBTextureEnvCombine.GL_COMBINE_ARB); GL11.glTexEnvf(GL11.GL_TEXTURE_ENV, ARBTextureEnvCombine.GL_COMBINE_RGB_ARB, GL11.GL_ADD); } else GL11.glDisable(GL11.GL_TEXTURE_2D); }
From source file:eu.over9000.veya.gui.TrueTypeFont.java
License:Open Source License
private void buildTexture(final BufferedImage imgTemp) throws IOException { textureId = GL11.glGenTextures();/*from w ww. j av a2 s. c o m*/ GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); ImageIO.write(imgTemp, "png", byteArrayOutputStream); final PNGDecoder decoder = new PNGDecoder(new ByteArrayInputStream(byteArrayOutputStream.toByteArray())); final ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(buffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA); buffer.flip(); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); }
From source file:eu.over9000.veya.gui.TrueTypeFont.java
License:Open Source License
public void drawString(final float x, final float y, final String whatchars, final Color color, final int startIndex, final int endIndex) { GL11.glColor4f(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha()); GL11.glEnable(GL11.GL_TEXTURE_2D);//w w w . j ava 2s . co m GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId); CharDataContainer charDataContainer; int charCurrent; GL11.glBegin(GL11.GL_QUADS); int totalwidth = 0; for (int i = 0; i < whatchars.length(); i++) { charCurrent = whatchars.charAt(i); if (charCurrent < 256) { charDataContainer = charData[charCurrent]; } else { charDataContainer = customChars.get((char) charCurrent); } if (charDataContainer != null) { if ((i >= startIndex) || (i <= endIndex)) { drawQuad((x + totalwidth), y, (x + totalwidth + charDataContainer.width), (y + charDataContainer.height), charDataContainer.storedX, charDataContainer.storedY, charDataContainer.storedX + charDataContainer.width, charDataContainer.storedY + charDataContainer.height); } totalwidth += charDataContainer.width; } } GL11.glEnd(); }
From source file:eu.over9000.veya.rendering.Scene.java
License:Open Source License
public void render() { this.checkCameraPosition(); ChunkChunkVAOPair addEntry;/*from ww w.j av a 2 s .c om*/ while ((addEntry = this.toAdd.poll()) != null) { addEntry.getChunkVAO().create(); this.displayedChunks.put(addEntry.getChunk(), addEntry.getChunkVAO()); } ChunkChunkVAOPair removeEntry; while ((removeEntry = this.toRemove.poll()) != null) { this.displayedChunks.remove(removeEntry.getChunk()); removeEntry.getChunkVAO().dispose(); } ChunkChunkVAOPair updatedEntry; while ((updatedEntry = this.updatedUpdateOffRender.poll()) != null) { updatedEntry.getChunkVAO().create(); final ChunkVAO oldVAO = this.displayedChunks.put(updatedEntry.getChunk(), updatedEntry.getChunkVAO()); if (oldVAO != null) { oldVAO.dispose(); } } int updates = 0; for (final Chunk chunk : displayedChunks.keySet()) { if (world.hasChunkChanged(chunk)) { if (chunk.getLocation().nextTo(centerChunk)) { final ChunkVAO newVAO = new ChunkVAO(chunk); final ChunkVAO oldVAO = this.displayedChunks.put(chunk, newVAO); oldVAO.dispose(); newVAO.create(); chunkUpdateCounterInRender.incrementAndGet(); updates++; if (updates > MAX_CHUNK_UPDATES_PER_FRAME) { break; } } else { toUpdateOffRender.add(chunk); } } } shadow.preRender(); Util.checkGLError(); internalRender(false); Util.checkGLError(); shadow.postRender(); Util.checkGLError(); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL30.GL_TEXTURE_2D_ARRAY, this.texture_handle); internalRender(true); if (Veya.debugShadow) { Veya.program_debug.use(true); GL20.glUniform1f(Veya.program_debug.getUniformLocation("near_plane"), Shadow.SHADOW_NEAR); GL20.glUniform1f(Veya.program_debug.getUniformLocation("far_plane"), Shadow.SHADOW_FAR); GL13.glActiveTexture(GL13.GL_TEXTURE0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, shadow.getDepthMap()); shadow.renderQuad(); } Veya.program_normal.use(true); }
From source file:eu.over9000.veya.rendering.Shadow.java
License:Open Source License
public void init() { depthMap = GL11.glGenTextures();/* w w w . j a v a 2 s . c o m*/ GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthMap); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_DEPTH_COMPONENT, SHADOW_WIDTH, SHADOW_HEIGHT, 0, GL11.GL_DEPTH_COMPONENT, GL11.GL_FLOAT, (ByteBuffer) null); 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); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL13.GL_CLAMP_TO_BORDER); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL13.GL_CLAMP_TO_BORDER); shadowFBO = GL30.glGenFramebuffers(); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, shadowFBO); GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL11.GL_TEXTURE_2D, depthMap, 0); GL11.glDrawBuffer(GL11.GL_NONE); GL11.glReadBuffer(GL11.GL_NONE); GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); }
From source file:eu.over9000.veya.rendering.Shadow.java
License:Open Source License
public void postRender() { GL11.glCullFace(GL11.GL_BACK); // don't forget to reset original culling face GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0); Veya.program_normal.use(true);/*from w w w .j a v a 2 s.c o m*/ GL11.glViewport(0, 0, Display.getWidth(), Display.getHeight()); GL13.glActiveTexture(GL13.GL_TEXTURE1); GL11.glBindTexture(GL11.GL_TEXTURE_2D, depthMap); }
From source file:eu.over9000.veya.util.TextureLoader.java
License:Open Source License
public static int loadFontTexture(final int textureUnit) { final int texId = GL11.glGenTextures(); try {//from www .j ava 2 s .com final InputStream in = TextureLoader.class.getResourceAsStream("/textures/font.png"); final PNGDecoder decoder = new PNGDecoder(in); final int sourceTexWidth = decoder.getWidth(); final int sourceTexHeight = decoder.getHeight(); final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight()); decoder.decode(byteBuffer, decoder.getWidth() * 4, Format.RGBA); byteBuffer.flip(); GL13.glActiveTexture(textureUnit); GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, sourceTexWidth, sourceTexHeight, 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, byteBuffer); // Setup the ST coordinate system GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); // Setup what to do when the texture has to be scaled GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); org.lwjgl.opengl.Util.checkGLError(); GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0); } catch (final IOException e) { e.printStackTrace(); System.exit(-1); } return texId; }