Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MindCode

Glut problem

This topic is 5818 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 trying to incorporate a menu screen using glut. Basically I created a glut window and when you start the game it switches the callbacks to the in-game functions, and when you go to the menu by pressing esc-key it switches back to the menu callbacks. The bug is that when I switch to the game screen, then switch back to the menu screen everything takes on a blue tint. Here's the code

#include <gl/glut.h>
#include <gl/glu.h>
#include <gl/gl.h>

#include <il/ilut.h>
#include <il/ilu.h>
#include <il/il.h>

#include <iostream>
#include <fstream>

enum {
	MENU_EXIT = 0,
	MENU_BEGIN
};


GLint g_iWidth;
GLint g_iHeight;

GLint g_GLgamewindow;
GLint g_GLmenu;

GLuint g_GLwallpaper;

bool g_vbKeyboard[128];





GLvoid GW_MakeCurrent(GLvoid) {

	glutDestroyMenu(g_GLmenu);


	glutDisplayFunc(GW_Display);

	glutReshapeFunc(GW_Reshape);

	glutKeyboardFunc(GW_Keyboard);

	glutKeyboardUpFunc(GW_KeyboardUp);

	glutIdleFunc(GW_Idle);


	glutReshapeWindow(g_iWidth, g_iHeight);

	glutPostRedisplay();
}


GLvoid GW_Display(GLvoid) {

	static GLfloat fRot1;
	static GLfloat fRot2;

	fRot1 += 0.3f;
	fRot2 += 0.1f;

	glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

	glLoadIdentity();

	glTranslatef(-1.5f, 0.f, -6.f);

	glRotatef(fRot1, 0.f, 1.f, 0.f);

	glBegin( GL_TRIANGLES );

		glColor3f(1.f, 0.f, 0.f);
		glVertex3f(0.f, 1.f, 0.f);

		glColor3f(0.f, 1.f, 0.f);
		glVertex3f(-1.f, -1.f, 0.f);

		glColor3f(0.f, 0.f, 1.f);
		glVertex3f(1.f, -1.f, 0.f);

	glEnd();

	glLoadIdentity();

	glTranslatef(1.5f, 0.f, -6.f);

	glRotatef(fRot2, 1.f, 0.f, 0.f);

	glColor3f(0.5f, 0.5f, 1.f);

	glBegin( GL_QUADS );

		glVertex3f(-1.0f, 1.0f, 0.0f);
		glVertex3f( 1.0f, 1.0f, 0.0f);
		glVertex3f( 1.0f,-1.0f, 0.0f);
		glVertex3f(-1.0f,-1.0f, 0.0f);

	glEnd();

	glutSwapBuffers();
}



GLvoid GW_Reshape(int iWidth, int iHeight) {

	if(!iHeight) {

		iHeight++;
	}

	GLfloat fRatio = float(iWidth)/float(iHeight);

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glViewport(0, 0, iWidth, iHeight);
	gluPerspective(45, fRatio, 1, 1000);

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glDisable( GL_TEXTURE_2D );

	g_iWidth  = glutGet( GLUT_WINDOW_WIDTH );
	g_iHeight = glutGet( GLUT_WINDOW_HEIGHT );
}


GLvoid GW_Keyboard(GLubyte ucKey, GLint x, GLint y) {

	g_vbKeyboard[ucKey] = true;
}


GLvoid GW_KeyboardUp(GLubyte ucKey, GLint x, GLint y) {

	g_vbKeyboard[ucKey] = false;
}


GLvoid GW_Idle(GLvoid) {

	glutPostRedisplay();

	if(g_vbKeyboard[27]) {

		MW_MakeCurrent();
	}

	memset(&g_vbKeyboard[0],0,16);
}


GLvoid MW_MakeCurrent(GLvoid) {

	g_GLmenu = glutCreateMenu(MW_Menu);

	glutAddMenuEntry("Exit", MENU_EXIT);
	glutAddMenuEntry("Begin", MENU_BEGIN);

	glutAttachMenu(GLUT_LEFT_BUTTON);


	glutDisplayFunc(MW_Display);

	glutReshapeFunc(MW_Reshape);

	glutKeyboardFunc(NULL);

	glutKeyboardUpFunc(NULL);

	glutIdleFunc(MW_Idle);


	glutReshapeWindow(g_iWidth, g_iHeight);

	glutPostRedisplay();
}


GLvoid MW_Menu(GLint eValue) {

	switch(eValue) {

		case MENU_EXIT:

			exit(0);

		break;

		case MENU_BEGIN:

			GW_MakeCurrent();

		break;
	};
}


GLvoid MW_Display() {

	glClear( GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

	glLoadIdentity();

	glBindTexture(GL_TEXTURE_2D, g_GLwallpaper);

	glRasterPos2i(0, 0);

	glBegin( GL_QUADS );

		glTexCoord2f(0.f, 0.f);
		glVertex2i(0L, 0L);

		glTexCoord2f(1.f, 0.f);
		glVertex2i(g_iWidth, 0L);

		glTexCoord2f(1.f, 1.f);
		glVertex2i(g_iWidth, g_iHeight);

		glTexCoord2f(0.f, 1.f);
		glVertex2i(0L, g_iHeight);

	glEnd();

	glutSwapBuffers();
}


GLvoid MW_Reshape(int iWidth, int iHeight) {

	if(!iHeight) {

		iHeight++;
	}

	glMatrixMode( GL_PROJECTION );
	glLoadIdentity();

	glOrtho(0, iWidth, 0, iHeight, -1, +1);

	glMatrixMode( GL_MODELVIEW );
	glLoadIdentity();

	glEnable( GL_TEXTURE_2D );

	g_iWidth  = glutGet( GLUT_WINDOW_WIDTH );
	g_iHeight = glutGet( GLUT_WINDOW_HEIGHT );
}


GLvoid MW_Idle() {

	glutPostRedisplay();
}



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


	ilInit();

	iluInit();

	ilutInit();

	ilutRenderer( ILUT_OPENGL );

	ilutEnable( ILUT_OPENGL_CONV );


	glutInit(&argc, argv);

	glutInitWindowPosition(10, 10);

	glutInitWindowSize(320, 240);

	glutInitDisplayMode( GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH );

	g_GLgamewindow = glutCreateWindow("GWin");


	g_GLwallpaper = ilutGLLoadImage("Wallpaper.bmp");


	MW_MakeCurrent();


	glutMainLoop();

	return 0;
}
 
[edited by - MindCode on October 16, 2002 2:12:48 AM]

Share this post


Link to post
Share on other sites
Advertisement

  • 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!