I'm just starting with OpenGL and I'm trying to figure out how to stick all the functions like drawScene, handleKeyPress, etc, into a class. This works fine:
class Viz {
public:
staticvoid handleKeypress(unsignedchar key, int x, int y) {
...
}
staticvoid initRendering() {
...
}
staticvoid handleResize(int w, int h) {
...
}
staticvoid drawScene() {
// draw the objects here
...
}
staticvoid Draw(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(400, 400);
glutCreateWindow("Window Title");
initRendering();
glutDisplayFunc(drawScene);
glutKeyboardFunc(handleKeypress);
glutReshapeFunc(handleResize);
glutMainLoop();
}
};
int main(int argc, char** argv)
{
Viz::Draw(argc, argv);
return 0;
}
But what I really need to do is to have drawScene() depend on some variable, say an integer. Writing
staticvoid drawScene(int an_integer)
doesn't work. I could use a global variable, that works fine. But it really seems messy. I figured it would be much nicer to have the integer as a member variable of Viz. Something like this:
glut functions will only accept static functions. Static functions can only use static variables. If you take the first snippet of code and add staticint an_integer; in the class and int Viz::an_integer; outside it, things should work.