Jump to content
  • Advertisement
Sign in to follow this  
kikkler

glut and game states

This topic is 4455 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!