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 void createShader(Shader shader) { this.shader = shader; glActiveTexture(GL_TEXTURE1); shader.bind(); int uniform = glGetUniformLocation(shader.getID(), "texture"); glUniform1i(uniform, 1); glActiveTexture(GL_TEXTURE2); uniform = glGetUniformLocation(shader.getID(), "extraTexture"); glUniform1i(uniform, 2); shader.release(); }
public void bindUniforms(List<Light> lights) { if (lights.size() > 10) { System.err.println("Too many lights."); return; } float[] positions = new float[10 * 2]; float[] colors = new float[10 * 3]; float[] intensities = new float[10]; for (int i = 0; i < lights.size() * 2; i += 2) { positions[i] = lights.get(i >> 1).getX() - lights.get(i >> 1).getXOffset(); positions[i + 1] = GameSettings.height - lights.get(i >> 1).getY() + lights.get(i >> 1).getYOffset(); } for (int i = 0; i < lights.size(); i++) { intensities[i] = lights.get(i).intensity; } for (int i = 0; i < lights.size() * 3; i += 3) { colors[i] = lights.get(i / 3).vc.x; colors[i + 1] = lights.get(i / 3).vc.y; colors[i + 2] = lights.get(i / 3).vc.z; } shader.bind(); int uniform = glGetUniformLocation(shader.getID(), "lightPosition"); glUniform2(uniform, Buffer.createFloatBuffer(positions)); uniform = glGetUniformLocation(shader.getID(), "lightColor"); glUniform3(uniform, Buffer.createFloatBuffer(colors)); uniform = glGetUniformLocation(shader.getID(), "lightIntensity"); glUniform1(uniform, Buffer.createFloatBuffer(intensities)); shader.release(); }
public void update() { shader.bind(); int uniform = shader.getUniform("tileInUse"); shader.setUniformf(uniform, tileInUse); uniform = shader.getUniform("isProtected"); shader.setUniformf(uniform, isLightProtected); shader.release(); /* * float sub = (float) random.nextFloat(); int div = random.nextInt(50); if (this.extraLevel < 1f && this.extraLevel >= 0f && (sub / div) > 0f && (sub / div) < 1f) this.extraLevel += sub / div; else this.extraLevel = 0.0f; */ // setExtraLevel(0f); }
public void bindUniforms(Light light) { shader.bind(); light.bindUniforms(shader.getID(), 999); shader.setUniform1f("extraLevel", this.extraLevel); shader.release(); }