glut, classes, game (serious shit, check it out)

Hi, I've created class "Game" and I use GLUT.
GLUT's function:
glutDisplayFunc() takes a pointer to a rendering function.

I need to declare this function somewhere and I want to be able to deliver this function to glutDisplayFunc().

I want class "Game" not to enable this function outside. In other words, I want to encapsulate it.

Can someone help?
Last edited on
Declare it in the class' protected or private section, however it will have to be static, because glutDisplayFunc cannot take member functions as parameters.
Thx for reply jsmith,
but I need this function to be non static, cause I want to modify private members in "Game" class.

If it's imposible to go that way, what can be the best walkaroud for this?
You know, I'd rather work on classes.
Last edited on
If glutDisplayFunc() has a void* parameter you can specify that gets passed to the callback function, then pass it the
"this" pointer of the object. Then the callback has to reinterpret_cast the void* to a pointer-to-object. That's your
only option.
Actually declaration of the glut function is:
void glutDisplayFunc(void (*func)(void));

It's not void *.
Last edited on
Last edited on
http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33.2

If you don't want a global variable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typedef void (*callback)();
class Game;
struct aux{
	aux(Game *a){
		obj = a;
	}
	
	static Game *obj;
	static void display(){
		obj->display();
	}
	callback get(){
		return aux::display;
	}
};
Game* aux::obj;

//calling
glutDisplayFunc( aux(game_pointer).get() );
Topic archived. No new replies allowed.