Archived

This topic is now archived and is closed to further replies.

robtherat007

opengl objectorientated with c++

Recommended Posts

The following example is basically how I coded opengl in C. I wonder how opengl can usefully be embedded in c++ and oo. How could I put this little example into objectorientation in c++. The problem is what do I do with the global variables and where do I have to call push and pop when oo? Maybe someone could turn this example into c++ code? GLuint Car,Wheel,Spokes,Body; static void myInit(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor (1.0, 1.0, 1.0, 1.0); Car=glGenLists(1); Body=glGenLists(1); Wheel=glGenLists(1); Spokes=glGenlists(1); glNewList(Body,GL_COMPILE); glBegin(GL_POLYGON); //Vertices for the body of the car glEnd(); glEndList(); glNewList(Wheel,GL_COMPILE); glBegin(GL_POLYGON); //Vertices for the Wheels of the car glEnd(); glCallList(Spokes); glEndList(); glNewList(Spokes,GL_COMPILE); glBegin(GL_POLYGON); //Vertices for the Spokes of the wheels of car glEnd(); glEndList(); glNewList(Car,GL_COMPILE); glPushMatrix(); glTranslatef(); //position of the body glCallList(Body); glPushMatrix(); glTranslatef() //Position of the 1.wheel glcallList(Wheel); glPopMatrix(); glPushMatrix(); glTranslatef() //Position of the 2.wheel glcallList(Wheel); glPopMatrix(); glPushMatrix(); glTranslatef() //Position of the 3.wheel glcallList(Wheel); glPopMatrix(); glPushMatrix(); glTranslatef() //Position of the 4.wheel glcallList(Wheel); glPopMatrix(); glPopMatrix(); glEndList(); } static void myDisplay(void) { glClear(GL_COLOR_BUFFER_BIT); glCallList(Car); glFlush (); } void main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 150); glutCreateWindow("Car"); glutDisplayFunc(myDisplay); myInit(); glutMainLoop(); }

Share this post


Link to post
Share on other sites
There are an infinite number of ways to use OO with OpenGL. For one example, take a look at the NeHe SDK (available on the main NeHe page). From that, you should get a few ideas about how you want to do your own.

Share this post


Link to post
Share on other sites