Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ecumene.opengl;
- import java.nio.FloatBuffer;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.opengl.GL11;
- import org.lwjgl.opengl.GL15;
- import org.lwjgl.opengl.GL20;
- /**
- * TODO: Comment
- * @author Ecumene
- */
- public class VertexAttrib {
- /**The vertex attribute's location*/
- private int id;
- /**The buffer*/
- private FloatBuffer data;
- /**The vertex attribute's index*/
- private int index;
- /**
- * Initializes the vertex attribute object with some data
- * to put into its buffer
- *
- * @param floats The data to add
- */
- public VertexAttrib(int index, int size, float ... floats) {
- data = BufferUtils.createFloatBuffer(floats.length);
- data.put(floats);
- data.flip();
- id = GL15.glGenBuffers();
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id);
- GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
- GL20.glVertexAttribPointer(index, size, GL11.GL_FLOAT, false, 0, 0);
- GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
- this.index = index;
- }
- /**
- * Binds/enables the vertex attribute object
- */
- public void bind(){
- GL20.glEnableVertexAttribArray(index);
- System.out.println("enabled vaa: " + index);
- }
- /**
- * unbinds/disables the vertex attribute object
- */
- public void unbind(){
- GL20.glDisableVertexAttribArray(index);
- System.out.println("disabled vaa: " + index);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement