One More Drawing Program
- Drawing an off file.
- I decided to break it down into a single indexed array object.
- Instead of the many different polygons
- When I encountered a polygon with more than 3 points
- I added p1, p2 and p3 to the index list
- Then p1, p3, p4
- ...
- Until p1, pn-1, pn
- Thus I could draw everything with glDrawElements
- I made extensive use of the vec3 class
- I built a vertex object (vertexT) out of vec3
- And a vector of these (vertices)
- Which I used for drawing.
- I made a routine to compute normals (DoNormal)
- Which used the built in normalize and cross routines for the vec3 class.
- In MinMax I treated the vec3 as an indexable array, this is nice
- In LoadOff I used
- overloaded stream extraction operator
- And overloaded stream insertion operator (for debugging)
- And many of the overloaded math operators
- And a constructor (vec3(1,1,1))
- Oh, and I scaled translated the data so it was inside the clipping cube centered at 0.
- Nothing huge in setup except
- vecotor.data() returns a pointer to contiguous data store in a vector.
- indices are stored in a GL_ELEMENT_ARRAY_BUFFER buffer.
- And I am using two VBOs for my VAO
- There are more buffer manipulation routines, but this will do for now.
- The code
- The vertex shader