I want to combine the game states managment technique presented
here with that of glut.
i have the class CGameEngine which basically encapsulates a stack of CGameState*, and in the usual glut functions (renderScene, processNormalKeys etc') i just call the eqvivalent function of the top state. that way each state can implement his own drawing/input handling functionality
here's a test code :
void IntroState::Draw(CGameEngine* game) {
glutSolidSphere(0.1, 16, 16);
}
void IntroState::processNormalKeys(unsigned char key, CGameEngine* game) {
if (key == 27) {
cout << "exiting IntroState";
exit(0);
}
if (key == 'a')
game->ChangeState(GameState::Instance());
}
void GameState::Draw(CGameEngine* game) {
glutSolidCube(1.0);
}
void GameState::processNormalKeys(unsigned char key, CGameEngine* game) {
if (key == 27) {
cout << "exiting GameState";
exit(0);
}
if (key == 'b')
game->ChangeState(IntroState::Instance());
}
i can switch states using 'a' or 'b', and each state should draw a different primitive. in main.cpp i have:
void renderScene() {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
game.Draw();
glutSwapBuffers();
}
CGameEngine game; // the global game
int main(int argc, char **argv) {
game.ChangeState(IntroState::Instance());
...
glutDisplayFunc(renderScene);
...
}
the problem is that while i can see that the states do change correctly (because each one prints something else when exiting), the sphere (of IntroState) remains constant and the cube never get drawn, even when changing to GameState
any ideas anyone?
tell me if you need some more code
thanks