View Full Version : [SOLVED]Draw a class
03-27-2012, 07:46 AM
I'm pretty new to OpenGL, and I understand the basics. Now, I have this Player class, with a function to draw a rectangle at its position. But how do I draw this, since all my drawing goes via a drawScene function, but I can't use it there. I also can't use a glutDisplayFunc, so how do I draw my player. The function is called DrawPlayer.
03-27-2012, 08:25 AM
Why can't you call DrawPlayer from drawScene - I assume drawScene is the function you registered with glutDisplayFunc?
I'd say a fairly usual way to set things up with GLUT would look like something along these lines:
Player p; // global variable, holding player instance
// buffer clearing, state set up, etc.
// draw everything else that is visible
// initialize GLUT
// register other event handlers with GLUT
The trick to not produce too messy code is to keep the number of global variables small, but since GLUT does allow registering member functions as callbacks  there is not really a good way around a few of them.
 GLUT is a C API, so it knows nothing about classes and member functions. Also the latter of course require a class instance to be called on and there is no way for GLUT to know which instance to use.
03-27-2012, 08:57 AM
Thanks, that worked. I actually never knew you could create a class as a global variable. Thanks!
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.