Jump to content
  • Advertisement
Sign in to follow this  
ethought

Opengl And Object Oriented Programming

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Opengl seems very procedural to me. I've done a bit of dabbling with opengl and java via several wrappers but haven't built anything large. Same with opengl and C++ although it might as well be C. Which brings me to my discussion topic. How do you make opengl programming fit in with OO ideals and methodologies?

Share this post


Link to post
Share on other sites
Advertisement
For the most part, you don't. Your graphics card is a big state machine with a zillion global variables whether you like it or not. ;) I think that if you wrote a wrapper that was too object oriented it might be easy to lose sight of this. Object orientation is generally based around the concept of unifying state with methods - and unfortunately the OpenGL state tends to be large and not trivially handled.

However, there's nothing to stop you wrapping up units of functionality yourself, although I can't tell you what to do there - you have to decide for yourself, based on the needs of your application. One example might be a texture class that loads the texture in the constructor and frees the texture in the destructor. Or a mesh class that holds a vertex/texture coordinate buffers and a function to render them.

Share this post


Link to post
Share on other sites
If you like OOP, why don't you use D3D?
Except for portability, you can do in D3D pretty much everything you can do in OpenGL.

Share this post


Link to post
Share on other sites
There is nothing to stop you from taking an OO approach with OpenGL, just don't fall into the trap of wrapping all of the calls into a class and calling it done. You might look at this library for inspiration. G3D does something very similar to what Kylotan described. Look through the class structure to see how it is organized. Look at the RenderDevice and Texture classes especially. Notice how they do not simply wrap OpenGL calls, but provide real abstraction through a meaningful and intuitive interface.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!