View Full Version : How can I encapsulate OpenGL with C++?

03-14-2003, 01:56 AM
I have studied opengl for a month,and I have been thinking about how to encapsulate OpenGL so I can using OpenGL in OO way.
We can abstract basic geometries such as triangle,point,and line because they are drawn by similar steps. And maybe we can write a class called MyLight,it contains all properities and effects that a light has . And we can write a 'Assemble' class which can hold 'geometry' objects and 'light' objects , rotate a 'Assemble' means rotate all objects it holds.
With these and other classes, we can control a 'tank' in a very convenient way,so we can control big and complex scene.
The most difficult thing is , how can I control states and combined effect( a geometry may draw under various combination of lights,materials,normals,and other) in OO way .
Can somebody give me some advices or tell me similar things that someone has already done?
finally, thank you for reading this ,and I am sorry for my poor English.

03-14-2003, 02:11 AM
Yes, its kind-of like, normal to do this kind of thing. Just do a google for "scene graph + opengl + oo" or something.

Most engines out there have scene graphs and use some form of OO.

Robert Osfield
03-16-2003, 11:26 PM
Originally posted by wu_kuan:
I have studied opengl for a month,and I have been thinking about how to encapsulate OpenGL so I can using OpenGL in OO way.

There are several levels at which to encapsulate OpenGL in an OO way.

The base level is wrapping of sets of related OpenGL calls into classes that encapsulate the data needed to be passed to the OGL functions, and the OGL function themselves. This level is really an OpenGL++ layer.

Once you want to compose your scene descrption itself in an OO way the most flexibile approach is to use a tree structure - known as a scene graph, with the hierachy able to compose your world as spatial groupings and logical relationships i.e. adding a transform above a gun turrent, which is part of tank, which has a transform above, which is part of landscape etc.

Scene graphs will typically have both the lower level OpenGL++ encapsulation and the higher scene encapsulation, as well as traversers/cullers/renders which do all sorts of good things for you.

Rather than reinvent the wheel you could just leverage the work of others. There numerous open source and commerical scene graphs available. With the open source ones you'll get to learn much more about the OO implemention of course http://www.opengl.org/discussion_boards/ubb/smile.gif


03-17-2003, 03:17 PM
Thanks for your advices, I have begin my
encaplation now .