fullscreen exit

Hello

i have a problem with my fullscreen mode(glut). When i render my scene in the fullscreen mode,
i see my scene very well but i want to use the esc button to exit the programm.Can you tell me
a way to do that?
I give you the code I use.Can you tell me what changes should i make to solve my problem?
The code is compiled and has 0 errors so you can see exactly what i mean.
I need changes in the main function!How can i totally kill my window???

THANKS A LOT!!!

#include <math.h> // - for mathematic functions
#include <stdlib.h> // - for the exit condition
#include <windows.h> // - Windows API and system calls
#include <stdio.h> // - Just for some ASCII messages
#include <gl/gl.h> // - The OpenGL API
#include <gl/glaux.h> // - A windows library extension API
#include <gl/glut.h> // - An interface and windows
// management library

//-------- Functions --------------------------------

void Render(); // The function responsible for drawing everything in the
// OpenGL context associated to a window.

void Resize(int w, int h); // Handle the window size changes and define the world coordinate
// system and projection type

void Setup(); // Set up the OpenGL state machine and create a light source

////////////////// State Variables ////////////////////////

BOOL done=FALSE;
bool keys[256]; // Array Used For The Keyboard Routine
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default

///////////////// Main Program ///////////////////////////

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

// Ask The User Which Screen Mode They Prefer
if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	fullscreen=FALSE;	// Windowed Mode

if(fullscreen==FALSE)
{
glutInit(&argc, argv); // initialize GLUT library state
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE); // Set up the display using the GLUT functions to
// get rid of the window setup details:
// - Use true RGB colour mode ( and transparency )
// - Enable double buffering for faster window update
// - Allocate a Depth-Buffer in the system memory or
// in the video memory if 3D acceleration available

glutInitWindowSize(480,480); // Define the main window size and initial position
glutInitWindowPosition(50,50); // ( upper left corner, boundaries included )

// Create and label the main window
glutCreateWindow(“Pavlopoulos_Georgios-018200000146-PENGUIN”);

// Configure various properties of the OpenGL rendering context
Setup();

// Callbacks for the GL and GLUT events:

glutDisplayFunc(Render); // The rendering function
glutReshapeFunc(Resize);

glutIdleFunc(Render);

glutMainLoop(); //Enter main event handling loop
}

else if (fullscreen==TRUE)
{
glutInit(&argc, argv) ;

    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB) ; 

	glutGameModeString("1024x768:32@60") ;
  	
	while(!done)								// Loop That Runs While done=FALSE
{
    // Draw The Scene.  Watch For ESC Key And Quit Messages From DrawGLScene()
	
			if (keys[VK_ESCAPE])				// Was ESC Pressed?
				done=TRUE;						// ESC Signalled A Quit				    
			

			else
			{		
	if (glutGameModeGet(GLUT_GAME_MODE_WIDTH) != -1) // if the width is different to -1

	{

	glutEnterGameMode() ; // enter full screen mode

	glutDisplayFunc(Render) ;

	glutReshapeFunc(Resize) ;

	glutIdleFunc(Render) ;		

	}

	else // print out that this mode is not available

	printf("The current mode is not supported in this system

") ;

	glutMainLoop();
			}
    glutSwapBuffers();
}//while 		   

}
}//end of main

void Render()
{

glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glFrontFace(GL_CCW);

glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
glTranslatef( 0.0, 0.0,-100.0 );

glRotatef(0.0,0.0,1.0,0.0);

glPushMatrix();//-------------------------------------------
glTranslatef( 0.0, -26.5,0.0 );
glScalef(3.0,0.2,3.0);
glColor4f(0,0.7,0.7,1);
glutSolidCube(25.0);
glPopMatrix();

glutSwapBuffers();

}

void Resize(int w, int h)
{

// define the visible area of the window ( in pixels )
if (h==0) h=1;
glViewport(0,0,w,h);

// Setup viewing volume
// glOrtho (-50.0f, 50.0f, -50.0f, 50.0f,100.0f,-100.0f);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

glOrtho(-50.0f,50.0f,-50.0,50.0f,-1500.0f,-1500.0f);

/* if(w<=h)
glOrtho();
else
glOrtho();*/

// L R B T N F
gluPerspective(60.0, w/h, 1.0, 500.0 );

}

//-----------------------------------------------------------

void Setup()
{
bool bDepth=FALSE;

glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

glEnable( GL_CULL_FACE );
glEnable( GL_LIGHTING );
glShadeModel( GL_SMOOTH );

if(bDepth)
glEnable(GL_DEPTH_TEST);
else
glDisable(GL_DEPTH_TEST);

//Set up light source
GLfloat ambientLight[] = { 0.2, 0.2, 0.2, 1.0 };
GLfloat diffuseLight[] = { 0.8, 0.8, 0.8, 1.0 };
GLfloat lightPos[] = { -30.0, 20.0, 170.0, 1.0 };

glLightfv( GL_LIGHT0, GL_AMBIENT, ambientLight );
glLightfv( GL_LIGHT0, GL_DIFFUSE, diffuseLight );
glLightfv( GL_LIGHT0, GL_POSITION,lightPos );
glEnable( GL_LIGHT0);

// polygon rendering mode and material properties
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);

glEnable(GL_COLOR_MATERIAL);
glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

// Blue background
glClearColor(0.0f,0.0f,1.0f,1.0f);

}

Hello,

I think I can help you.

Add this in your code:

void keyboard( unsigned char key, int x, int y ) {
switch ( key )
case 27:
exit( 0 );
}

and After that put this after your EnterGameMode code:

glutKeyboardFunc(keyboard);

Hope This Helps!!!

  • VC6-OGL