public void render(int x, int y, float extra) { setExtraLevel(extra); glPushMatrix(); shader.bind(); glBindVertexArray(vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); { glTranslatef(x, y, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, Texture.Lava); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); glActiveTexture(GL_TEXTURE1); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); /* * glTranslatef(x, y, 0); glBindTexture(GL_TEXTURE_2D, texture); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); */ } glDisableVertexAttribArray(1); glDisableVertexAttribArray(0); glBindVertexArray(0); shader.release(); glPopMatrix(); }
public static void beginWater() { useProgram(Shaders.ProgramWater); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, mc.renderEngine.getTexture("/terrain_nh.png")); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, mc.renderEngine.getTexture("/terrain_s.png")); glActiveTexture(GL_TEXTURE0); }
public static void beginTerrain() { useProgram(Shaders.ProgramTerrain); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, mc.renderEngine.getTexture("/terrain_nh.png")); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, mc.renderEngine.getTexture("/terrain_s.png")); glActiveTexture(GL_TEXTURE0); FloatBuffer projection = BufferUtils.createFloatBuffer(16); }
private static void setupShadowRenderTexture() { if (shadowPassInterval <= 0) { return; } // depth glDeleteTextures(sfbDepthTexture); sfbDepthTexture = glGenTextures(); glBindTexture(GL_TEXTURE_2D, sfbDepthTexture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ByteBuffer buffer = ByteBuffer.allocateDirect(shadowMapWidth * shadowMapHeight * 4); glTexImage2D( GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, shadowMapWidth, shadowMapHeight, 0, GL_DEPTH_COMPONENT, GL11.GL_FLOAT, buffer); }
/** * Method called by the World Class to render the Tile. * * @param x : location to where the Tile is going to be rendered. * @param y : location to where the Tile is going to be rendered. * @param w : instance of the World Class * @param ent : List of entities that emit light. */ public void render(int x, int y, World w, ArrayList<Entity> ent) { // Binding the Uniforms to make the light effects. bindUniforms(w, ent); // Setting up OpenGL for render glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ZERO); // Updating the Tile coordinates. this.x = x; this.y = y; glTranslatef(x, y, 0); // Activating and Binding the Tile Texture. glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, this.tex); // Sending the texture to the shader. glUniform1i(glGetUniformLocation(shade.getShader(), "texture"), 0); // Drawing the QUAD. glBegin(GL_QUADS); { glTexCoord2f(0, 0); glVertex2f(0, 0); glTexCoord2f(0, 1); glVertex2f(0, this.height); glTexCoord2f(1, 1); glVertex2f(this.width, this.height); glTexCoord2f(1, 0); glVertex2f(this.width, 0); } glEnd(); // Releasing the Texture. glBindTexture(GL_TEXTURE_2D, 0); // Getting the location back to the inicial coordinates. glTranslatef(-x, -y, 0); // Disabling BLEND and releasing shader for next render. glDisable(GL_BLEND); shade.release(); glClear(GL_STENCIL_BUFFER_BIT); }
private static TextureResource loadTexture(String fileName) { String[] splitArray = fileName.split("\\."); String ext = splitArray[splitArray.length - 1]; try { BufferedImage image = ImageIO.read(new File("./res/textures/" + fileName)); int[] pixels = image.getRGB(0, 0, image.getWidth(), image.getHeight(), null, 0, image.getWidth()); ByteBuffer buffer = Util.createByteBuffer(image.getHeight() * image.getWidth() * 4); boolean hasAlpha = image.getColorModel().hasAlpha(); for (int y = 0; y < image.getHeight(); y++) { for (int x = 0; x < image.getWidth(); x++) { int pixel = pixels[y * image.getWidth() + x]; buffer.put((byte) ((pixel >> 16) & 0xFF)); buffer.put((byte) ((pixel >> 8) & 0xFF)); buffer.put((byte) ((pixel) & 0xFF)); if (hasAlpha) buffer.put((byte) ((pixel >> 24) & 0xFF)); else buffer.put((byte) (0xFF)); } } buffer.flip(); TextureResource resource = new TextureResource(); glBindTexture(GL_TEXTURE_2D, resource.getId()); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, image.getWidth(), image.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); return resource; } catch (Exception e) { e.printStackTrace(); System.exit(1); } return null; }
public void render() { glPushMatrix(); glEnable(GL_BLEND); shader.bind(); glBindVertexArray(vao); glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); { glTranslatef(x, y, 0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, texture); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vio); glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_BYTE, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindTexture(GL_TEXTURE_2D, 0); } glDisableVertexAttribArray(1); glDisableVertexAttribArray(0); glBindVertexArray(0); shader.release(); glDisable(GL_BLEND); glPopMatrix(); }
private static void setupRenderTextures() { glDeleteTextures(dfbTextures); glGenTextures(dfbTextures); for (int i = 0; i < colorAttachments; ++i) { glBindTexture(GL_TEXTURE_2D, dfbTextures.get(i)); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if (i == 1) { // depth buffer ByteBuffer buffer = ByteBuffer.allocateDirect(renderWidth * renderHeight * 4 * 4); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB32F_ARB, renderWidth, renderHeight, 0, GL_RGBA, GL11.GL_FLOAT, buffer); } else { ByteBuffer buffer = ByteBuffer.allocateDirect(renderWidth * renderHeight * 4); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, renderWidth, renderHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer); } } }
public void bind(int samplerSlot) { assert (samplerSlot >= 0 && samplerSlot <= 31); glActiveTexture(GL_TEXTURE0 + samplerSlot); glBindTexture(GL_TEXTURE_2D, resource.getId()); }
@Override public void flush() { glBindTexture(GL_TEXTURE_2D, lastTex); super.flush(); }
public static void endRender() { if (isShadowPass) { return; } glPushMatrix(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); // composite glDisable(GL_BLEND); useProgram(ProgramComposite); glDrawBuffers(dfbDrawBuffers); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(0)); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(1)); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(2)); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(3)); if (colorAttachments >= 5) { glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(4)); if (colorAttachments >= 6) { glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(5)); if (colorAttachments >= 7) { glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(6)); } } } if (shadowPassInterval > 0) { glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, sfbDepthTexture); } glActiveTexture(GL_TEXTURE0); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); // final glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); useProgram(ProgramFinal); glClearColor(clearColor[0], clearColor[1], clearColor[2], 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(0)); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(1)); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(2)); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(3)); if (colorAttachments >= 5) { glActiveTexture(GL_TEXTURE4); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(4)); if (colorAttachments >= 6) { glActiveTexture(GL_TEXTURE5); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(5)); if (colorAttachments >= 7) { glActiveTexture(GL_TEXTURE6); glBindTexture(GL_TEXTURE_2D, dfbTextures.get(6)); } } } if (shadowPassInterval > 0) { glActiveTexture(GL_TEXTURE7); glBindTexture(GL_TEXTURE_2D, sfbDepthTexture); } glActiveTexture(GL_TEXTURE0); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, 0.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 1.0f, 0.0f); glEnd(); glEnable(GL_BLEND); glPopMatrix(); useProgram(ProgramNone); }