Jump to content
  • Advertisement
Sign in to follow this  
eyechild

GLUT game mode

This topic is 4091 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'm having trouble creating and attaching menus in GLUT, and the problem seems to be that GLUT is in "game mode", in which you are not allowed to attach menus. However, I've tried to use the glutLeaveGameMode() function, and then I'm told you cannot leave game mode as GLUT is not in game mode! This is the code I'm having trouble with. It's a very simple example program which allows the user to clear the screen or exit the program using a menu:
#include <gl/glut.h>

void display()
{
	glClear(GL_COLOR_BUFFER_BIT);
	glBegin(GL_TRIANGLES);
		glVertex2f(0.5, -0.5);
		glVertex2f(0.0, 0.5);
		glVertex2f(-0.5, -0.5);
	glEnd();
	glFlush();
}

void menuFunc(int value)
{
	if (value == 1)
	{
		glClear(GL_COLOR_BUFFER_BIT);
		glFlush();
	}
	else if (value == 2) 
		exit(0);
}

void initMenus()
{
	glutCreateMenu(menuFunc);
	glutAddMenuEntry("Clear Screen", 1);
	glutAddMenuEntry("Exit", 2);
        glutLeaveGameMode(); // Must be done to allow menu to be attached
	glutAttachMenu(GLUT_RIGHT_BUTTON);
}
	
int main(int argc, char* argv[])
{
	glutInit(&argc, argv);
	initMenus();
	glutCreateWindow("Menu Example");
	glutDisplayFunc(display);
	glutMainLoop();
	return 0;
}
My only guess as to what is causing this is that a particular GLUT function call causes entry to game mode, but I'm damned if I know which one. Can anyone help me out?

Share this post


Link to post
Share on other sites
Advertisement
@eyechild

move the "initMenus()" call to AFTER the glutCreateWindow call :)

works fine for me if you do that. Good luck.

Andy

edit PS: modified example follows to avoid any confusion.

#include <gl/glut.h>

void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_TRIANGLES);
glVertex2f(0.5, -0.5);
glVertex2f(0.0, 0.5);
glVertex2f(-0.5, -0.5);
glEnd();
glFlush();
}

void menuFunc(int value)
{
if (value == 1)
{
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
else if (value == 2)
exit(0);
}

void initMenus()
{
glutCreateMenu(menuFunc);
glutAddMenuEntry("Clear Screen", 1);
glutAddMenuEntry("Exit", 2);
glutLeaveGameMode(); // Must be done to allow menu to be attached
glutAttachMenu(GLUT_RIGHT_BUTTON);
}

int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutCreateWindow("Menu Example");
// initMenus requires a window for glutAttachMenu to attach too ;)
initMenus();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!