Sign in to follow this  

glut and game states

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";
	if (key == 'a')

void GameState::Draw(CGameEngine* game) {

void GameState::processNormalKeys(unsigned char key, CGameEngine* game) {
	if (key == 27) {
		cout << "exiting GameState";
	if (key == 'b')

i can switch states using 'a' or 'b', and each state should draw a different primitive. in main.cpp i have:
void renderScene() {

CGameEngine game; // the global game

int main(int argc, char **argv) {

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this