Jump to content
  • Advertisement
Sign in to follow this  
openglJunkie

OpenGL OpenGL, Objects and Inheritence

This topic is 3666 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

I'm wanting to create seperate classes for each of my objects, but they require the headers "gl.h" and "glut.h". I was wondering if it was practical to make a main object, let's call it "GLController.h", which includes the headers "gl.h" and "glut.h" and this way my objects can inherit from the "GLController" class. I keep running into the issue when including my objects in "main.cpp" when the headers "gl.h" and "glut.h" are already included from whichever object I #included first in main.cpp. I've thought of using #ifndef CLASS_H #define CLASS_H #endif but I think it only works for the class that you're working with itself, such that in case CLASS_H is already defined, then don't include it. I don't think this works for required header files.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by openglJunkie
I'm wanting to create seperate classes for each of my objects, but they require the headers "gl.h" and "glut.h". I was wondering if it was practical to make a main object, let's call it "GLController.h", which includes the headers "gl.h" and "glut.h" and this way my objects can inherit from the "GLController" class.


But the header files for your objects would still include "GL.h" and "Glut.h", just indirectly via "GLController.h".

Quote:
#ifndef CLASS_H
#define CLASS_H
#endif


Those are called include guards, and they must appear in every header file.

I'm not sure I fully understand your problem, but I think reading this article will help you.

Share this post


Link to post
Share on other sites
Ah, yes. I was running into the issue of duplicate definitions, which uses include guards apparently. Here's my plan:

I'm making a box class, which I can put the OpenGL code to draw it within the class by making a call to glBegin and glEnd, but what if I save the information required to draw it (vector positions, size) and pass it to a graphics class that stores a list of vectors for each type (QUAD, TRIANGLE, etc) and draws that, although if that happened some polygons might appear out of order.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!