1
\$\begingroup\$

I need to run at least 25 windows concurrently with each window rendering a different game state. I am storing all the 25 game states in the array of type GameState allGameStates[25].

For each of the window, i am currently doing this to register a different draw callback for each of the 25 windows.

 glutCreateWindow(title);
 glutDisplayFunc(allGameStates[i].Draw);

The issue here is that glutDisplayFunc requires a parameter of type function ptr, and i cannot pass in a member function ptr.(i am using GLUT which is in C)

It is not feasible to make the Draw function static as i require the Draw function to render differently accordingly to the other variables in the game state object.

How do i overcome this problem?

\$\endgroup\$
  • \$\begingroup\$ Does this game need to be playable? That sounds like a recipe for disaster. If you enable VSYNC you'll basically only get 2 FPS in your application in the best case ;) \$\endgroup\$ – Andon M. Coleman Mar 23 '15 at 6:56
  • \$\begingroup\$ Luckily for my case ,only 1 window is to be shown to the user at any point in time so vsync is not required.Thanks for the comment though. \$\endgroup\$ – Aspiring Game Dev Mar 23 '15 at 7:42
4
\$\begingroup\$

According to the documentation for glutDisplayFunc():

Before the callback, the current window is set to the window needing to be redisplayed

This means that inside the display callback, you can call glutGetWindow() to find out which window is being drawn to.

This means that you can use a static member function as the display callback; just have that static member function figure out which window is being drawn to, and map from that window to its particular game state object instance, and then call a non-static member function on that instance.

\$\endgroup\$
  • \$\begingroup\$ You Sir , is a Genius \$\endgroup\$ – Aspiring Game Dev Mar 22 '15 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.