Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. package ecumene.opengl;
  2.  
  3. import java.nio.FloatBuffer;
  4.  
  5. import org.lwjgl.BufferUtils;
  6. import org.lwjgl.opengl.GL11;
  7. import org.lwjgl.opengl.GL15;
  8. import org.lwjgl.opengl.GL20;
  9.  
  10. /**
  11. * TODO: Comment
  12. * @author Ecumene
  13. */
  14. public class VertexAttrib {
  15. /**The vertex attribute's location*/
  16. private int id;
  17. /**The buffer*/
  18. private FloatBuffer data;
  19. /**The vertex attribute's index*/
  20. private int index;
  21.  
  22. /**
  23. * Initializes the vertex attribute object with some data
  24. * to put into its buffer
  25. *
  26. * @param floats The data to add
  27. */
  28. public VertexAttrib(int index, int size, float ... floats) {
  29. data = BufferUtils.createFloatBuffer(floats.length);
  30. data.put(floats);
  31. data.flip();
  32.  
  33. id = GL15.glGenBuffers();
  34. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, id);
  35. GL15.glBufferData(GL15.GL_ARRAY_BUFFER, data, GL15.GL_STATIC_DRAW);
  36. GL20.glVertexAttribPointer(index, size, GL11.GL_FLOAT, false, 0, 0);
  37. GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0);
  38.  
  39. this.index = index;
  40. }
  41.  
  42. /**
  43. * Binds/enables the vertex attribute object
  44. */
  45. public void bind(){
  46. GL20.glEnableVertexAttribArray(index);
  47. System.out.println("enabled vaa: " + index);
  48. }
  49.  
  50. /**
  51. * unbinds/disables the vertex attribute object
  52. */
  53. public void unbind(){
  54. GL20.glDisableVertexAttribArray(index);
  55. System.out.println("disabled vaa: " + index);
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement