I'm using OpenGL to display a 3D network, with nodes represented as spheres (I haven't gotten to edges yet). I'm a total novice, and having a bit of trouble wrapping my head around OpenGL.
These networks need to be generated programmatically, so I've got a function that produces vertices for a sphere with radius 1 centred at the origin, and I'm translating and scaling it to produce each of the nodes in the network. I'm using glDrawElements()
to draw my nodes, so I'm storing indices for the vertices of my sphere as well.
Once a network is produced, it doesn't change. The camera position can change, but nothing else will. My current strategy is the following:
- When a network is generated, for each node, make a copy of the unit sphere, and apply the appropriate translation * scale matrix. Store all of the vertices (and associated colours) in a single array/VBO.
- When drawing, set the scene-to-camera and perspective matrices to a uniform, then use a single
glDrawElements()
call to draw all my nodes.
So a couple of questions about this:
- Since all my nodes are essentially identical, I could just store vertices for one sphere, and transform the sphere on the fly when I render the scene. There might be a lot of nodes, so this could save substantial memory. But each sphere has quite a different set of colours... is there a way to tell OpenGL to use an offset for the colour data but not the vertex data?
- Assuming the answer to part 1 is no, would it be better to keep vertices for a single sphere in my VBO, and then substitute the colour data and draw each node with a separate call to
glDrawElements()
? Or is there some other solution that I'm not thinking of?