title: OpenGL and OOP program structure
body: <p>I've worked on a variety of demo projects with OpenGL and C++, but they've all involved simply rendering a single cube (or similarly simple mesh) with some interesting effects. For a simple scene like this, the vertex data for the cube could be stored in an inelegant global array. I'm now looking into rendering more complex scenes, with multiple objects of different types.</p>
  
  <p>I think it makes sense to have different classes for different types of objects (<code>Rock</code>, <code>Tree</code>, <code>Character</code>, etc), but I'm wondering how to cleanly break up the data and rendering functionality for objects in the scene. Each class will store its own array of vertex positions, texture coordinates, normals, etc. However I'm not sure where to put the OpenGL calls. I'm thinking that I will have a loop (in a <code>World</code> or <code>Scene</code> class) that iterates over all the objects in the scene and renders them.</p>
  
  <p>Should rendering them involve calling a render method in each object <code>(Rock::render(), Tree::render(),...)</code> or a single render method that takes in an object as a parameter <code>(render(Rock), render(Tree),...)</code>? The latter seems cleaner, since I won't have duplicate code in each class (although that could be mitigated by inheriting from a single <code>RenderableObject</code> class), and it allows the render() method to be easily replaced if I want to later port to DirectX. On the other hand, I'm not sure if I can keep them separate, since I might need OpenGL specific types stored in the objects anyway (vertex buffers, for example). In addition, it seems a bit cumbersome to have the render functionality separate from the object, since it will have to call lots of <code>Get()</code> methods to get the data from the objects. Finally, I'm not sure how this system would handle objects that have to be drawn in different ways (different shaders, different variables to pass in to the shaders, etc).</p>
  
  <p>Is one of these designs clearly better than the other? In what ways can I improve upon them to keep my code well-organised and efficient?</p>