protected boolean prepare(int fbufWidth, int fbufHeight) { if (ctx.useShader(this) && glIsProgram(program)) { glUseProgram(program); ctx.checkGLError("Shader.prepare useProgram"); glUniform2f(uScreenSizeLoc, fbufWidth, fbufHeight); // ctx.checkGLError("Shader.prepare uScreenSizeLoc set to " + fbufWidth + " " + fbufHeight); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementBuffer); ctx.checkGLError("Shader.prepare BindBuffer"); glEnableVertexAttribArray(aMatrix); glEnableVertexAttribArray(aTranslation); glEnableVertexAttribArray(aPosition); if (aTexture != -1) glEnableVertexAttribArray(aTexture); ctx.checkGLError("Shader.prepare AttribArrays enabled"); glVertexAttribPointer(aMatrix, 4, GL_FLOAT, false, VERTEX_STRIDE, 0); glVertexAttribPointer(aTranslation, 2, GL_FLOAT, false, VERTEX_STRIDE, 16); glVertexAttribPointer(aPosition, 2, GL_FLOAT, false, VERTEX_STRIDE, 24); if (aTexture != -1) glVertexAttribPointer(aTexture, 2, GL_FLOAT, false, VERTEX_STRIDE, 32); ctx.checkGLError("Shader.prepare AttribPointer"); return true; } return false; }
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(); }
protected void compile() { vao = glGenVertexArrays(); glBindVertexArray(vao); { vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); { glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); } glBindBuffer(GL_ARRAY_BUFFER, 0); vio = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vio); { glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW); } glBindBuffer(GL_ARRAY_BUFFER, 0); vto = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vto); { glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1); } glBindBuffer(GL_ARRAY_BUFFER, 0); } glBindVertexArray(0); }
protected void compile() { vao = glGenVertexArrays(); glBindVertexArray(vao); { vbo = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vbo); { glBufferData(GL_ARRAY_BUFFER, Buffer.createFloatBuffer(vertices), GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0); } glBindBuffer(GL_ARRAY_BUFFER, 0); vio = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vio); { glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(indices), GL_STATIC_DRAW); } glBindBuffer(GL_ARRAY_BUFFER, 0); vto = glGenBuffers(); glBindBuffer(GL_ARRAY_BUFFER, vto); { glBufferData(GL_ARRAY_BUFFER, Buffer.createByteBuffer(texCoords), GL_STATIC_DRAW); glVertexAttribPointer(1, 3, GL_UNSIGNED_BYTE, false, 0, 1); } glBindBuffer(GL_ARRAY_BUFFER, 0); } glBindVertexArray(0); glActiveTexture(GL_TEXTURE1); shader.bind(); int uniform = glGetUniformLocation(shader.getID(), "texture"); glUniform1i(uniform, 1); shader.release(); }
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(); }