Advertisement
Guest User

Untitled

a guest
Feb 5th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. class OGLObj {
  2. public:
  3. OGLObj(OpenGLImp *pParentImp) :
  4. m_pParentImp(pParentImp)
  5. {
  6. /* empty stub */
  7. }
  8.  
  9. ~OGLObj() {
  10. /* empty stub */
  11. }
  12.  
  13. virtual inline vertex *VertexData() = 0;
  14. virtual inline int VertexDataSize() = 0;
  15. virtual RESULT Render() = 0;
  16.  
  17.  
  18. // This needs to be called from the sub-class constructor
  19. // or externally from the object (TODO: factory class needed)
  20. RESULT OGLInitialize() {
  21. RESULT r = R_PASS;
  22.  
  23. float z = 0.0f;
  24. float height = 0.8f;
  25. float width = 0.8f;
  26. vertex vertTemp[3];
  27. vertTemp[0].SetPoint(0.0f, height, z);
  28. vertTemp[0].SetColor(1.0f, 0.0f, 0.0f);
  29.  
  30. vertTemp[1].SetPoint(-width, -height, z);
  31. vertTemp[1].SetColor(0.0f, 1.0f, 0.0f);
  32.  
  33. vertTemp[2].SetPoint(width, -height, z);
  34. vertTemp[2].SetColor(0.0f, 0.0f, 1.0f);
  35.  
  36. // Set up the Vertex Array Object (VAO)
  37. CR(m_pParentImp->glGenVertexArrays(1, &m_hVAO));
  38. CR(m_pParentImp->glBindVertexArray(m_hVAO));
  39.  
  40. // Create Buffer Objects
  41. //CR(m_pParentImp->glGenBuffers(NUM_VBO, &m_hVBOs[0]));
  42. CR(m_pParentImp->glGenBuffers(1, &m_hVBO));
  43. CR(m_pParentImp->glBindBuffer(GL_ARRAY_BUFFER, m_hVBO));
  44.  
  45. vertex *pVertex = VertexData();
  46. GLsizeiptr pVertex_n = VertexDataSize();
  47.  
  48. CR(m_pParentImp->glBufferData(GL_ARRAY_BUFFER, pVertex_n, &pVertex[0], GL_STATIC_DRAW));
  49. //CR(m_pParentImp->glBufferData(GL_ARRAY_BUFFER, 3 * sizeof(vertex), vertTemp, GL_STATIC_DRAW));
  50.  
  51. // For readability
  52. //GLuint positionBufferHandle = m_hVBOs[0];
  53. //GLuint colorBufferHandle = m_hVBOs[1];
  54.  
  55. /* Index Element Buffer
  56. //index buffer object -> we hold the index of vertex
  57. glGenBuffers(1, &gl_index_buffer_object);
  58. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, gl_index_buffer_object);
  59. glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size()*sizeof(unsigned int), &indices[0], GL_STATIC_DRAW);
  60. */
  61.  
  62. // Color Buffer
  63. // TODO: Is this needed with a custom vertex structure?
  64. //CR(m_pParentImp->glBindBuffer(GL_ARRAY_BUFFER, colorBufferHandle));
  65. //CR(m_pParentImp->glBufferData(GL_ARRAY_BUFFER, pVertex_n, pVertex, GL_STATIC_DRAW));
  66.  
  67. // Enable the vertex attribute arrays
  68. // TODO: This needs to come out of the Implementation shader compilation, should not be static
  69.  
  70. // Bind Position
  71. CR(m_pParentImp->glBindBuffer(GL_ARRAY_BUFFER, m_hVBO));
  72. CR(m_pParentImp->glEnableVertexAtrribArray(0)); // TEMP: Position
  73. CR(m_pParentImp->glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), vertex::GetVertexOffset()));
  74.  
  75. // Color
  76. CR(m_pParentImp->glEnableVertexAtrribArray(1)); // TEMP: Color
  77. CR(m_pParentImp->glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, sizeof(vertex), vertex::GetColorOffset()));
  78.  
  79. //*/
  80.  
  81. Error:
  82. return r;
  83. }
  84.  
  85. protected:
  86. GLuint m_hVAO;
  87. //GLuint m_hVBOs[NUM_VBO];
  88. GLuint m_hVBO;
  89. OpenGLImp *m_pParentImp;
  90. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement