Ember

oglmesh

Feb 15th, 2014
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. // Allocate an OpenGL vertex array object.
  2. OpenGL->glGenVertexArrays(1, &m_vertexArrayId);
  3.  
  4. // Bind the vertex array object to store all the buffers and vertex attributes we create here.
  5. OpenGL->glBindVertexArray(m_vertexArrayId);
  6.  
  7. // Generate an ID for the vertex buffer.
  8. OpenGL->glGenBuffers(1, &m_vertexBufferId);
  9.  
  10. // Bind the vertex buffer and load the vertex (position and color) data into the vertex buffer.
  11. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId);
  12. OpenGL->glBufferData(GL_ARRAY_BUFFER, m_vertexCount * sizeof(VertexType), vertices, GL_STATIC_DRAW);
  13.  
  14. // Enable the two vertex array attributes.
  15. OpenGL->glEnableVertexAttribArray(0);  // Vertex position.
  16. OpenGL->glEnableVertexAttribArray(1);  // Vertex color.
  17.  
  18. // Specify the location and format of the position portion of the vertex buffer.
  19. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId);
  20. OpenGL->glVertexAttribPointer(0, 3, GL_FLOAT, false, sizeof(VertexType), 0);
  21.  
  22. // Specify the location and format of the color portion of the vertex buffer.
  23. OpenGL->glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferId);
  24. OpenGL->glVertexAttribPointer(1, 3, GL_FLOAT, false, sizeof(VertexType), (unsigned char*)NULL + (3 * sizeof(float)));
  25.  
  26. // Generate an ID for the index buffer.
  27. OpenGL->glGenBuffers(1, &m_indexBufferId);
  28.  
  29. // Bind the index buffer and load the index data into it.
  30. OpenGL->glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_indexBufferId);
  31. OpenGL->glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexCount* sizeof(unsigned int), indices, GL_STATIC_DRAW);
Advertisement
Add Comment
Please, Sign In to add comment