
OpenGL and C++ Classes
Hi! The following question is regarding OpenGL and the use of classes and inheritance. I roughly understand how inheritance and classes work in C++, and also understand roughly how OpenGL works.
In order to understand OpenGL better, I''ve been trying to code a 3D engine that I can understand easily. So far so good, until this problem I have...
To simplify the engine, I have classes called:
- OBJ3D to store the vertices, etc.
- MATERIAL to store the material properties of the object (basically just to group those glMaterial functions)
- MAP is a base class to specify the "mapping method" on the object (i.e. I''m planning to be able to specify if I want to use an image for texture, or just use the vertex colors specified)
- MAP_VERTEXCOLOR is a class derived from base class (inherits from it), that activates the "vertex color mapping method".
The reason I used MAP_VERTEXCOLOR derived from MAP is that, in MATERIAL there is a MAP*, so that I can change to any other mapping methods that I implement later (like using images for texturing).
MATERIAL has a function called Activate() that will run all the glMaterial functions for ambient, diffuse, etc. Nothing fancy there. MAP_VERTEXCOLOR has function that will setup the object to be drawn using the vertex colors
class MAP {
public:
MAP(GLenum Property); // constructor
virtual bool Process() = 0;
GLenum property, activeface; }; // property represents what material property this map is for, i.e. diffuse or ambient. Activeface is which face it is to be applied to, i.e. GL_FRONT, GL_BACK or GL_FRONT_AND_BACK
class MAP_VERTEXCOLOR {
public:
MAP_VERTEXCOLOR(GLenum Property);
bool Process(); };
MAP::MAP(GLenum Property)
{ property = Property; };
MAP_VERTEXCOLOR::MAP_VERTEXCOLOR(GLenum Property)
:MAP(Property)
{ property = Property; }
bool MAP_VERTEXCOLOR:
rocess()
{
glEnable(GL_COLOR_MATERIAL); glColorMaterial(activeface,property);
return true; }
NOTE: Please excuse the coding. I''m just doing a rough version of whatever I can think of, and test if it works first, and when it does, then only I optimize things and make it look better.
... So, what I need to do is to:
- create and activate a MAP_VERTEXCOLOR [i.e. call Process() function]
- create, set and activate a MATERIAL object
- draw any 3D object.
Before creating the MAP_VERTEXCOLOR class, everything in the engine was working fine. The MATERIAL object will be able to set the properties correctly and such...
However, when I create (just CREATE without calling any other functions) a MAP_VERTEXCOLOR anywhere in the Main.cpp file, the MATERIAL object doesn''t seem to set all the properties according. It remains as though the MATERIAL object doesn''t exist (I tried removing the creation of the MATERIAL object and I got the same result).
Anyone can point out the error? Please excuse the long post and possibly bad coding...

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement