text: /*
   NeHe (nehe.gamedev.net) OpenGL tutorial series
   GLUT port.in 2001 by milix (milix_gr@hotmail.com)
   Most comments are from the original tutorials found in NeHe.
   For VC++ users, create a Win32 Console project and link 
   the program with glut32.lib, glu32.lib, opengl32.lib
  */
  
  #include <windows.h>   // Standard Header For MSWindows Applications
  #include <gl/glut.h>   // The GL Utility Toolkit (GLUT) Header
  
  // The Following Directive Fixes The Problem With Extra Console Window
  #pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
  
  // Global Variables
  bool g_gamemode;       // GLUT GameMode ON/OFF
  bool g_fullscreen;     // Fullscreen Mode ON/OFF (When g_gamemode Is OFF)
  
  // Our GL Specific Initializations
  bool init(void)
  {
  	glShadeModel(GL_SMOOTH);							// Enable Smooth Shading
  	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);				// Black Background
  	glClearDepth(1.0f);									// Depth Buffer Setup
  	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing
  	glDepthFunc(GL_LEQUAL);								// The Type Of Depth Testing To Do
  	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// Really Nice Perspective Calculations
  	return true;
  }
  
  // Our Rendering Is Done Here
  void render(void)   
  {
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear Screen And Depth Buffer
      glLoadIdentity();									// Reset The Current Modelview Matrix
  
      // Swap The Buffers To Become Our Rendering Visible
      glutSwapBuffers ( );
  }
  
  // Our Reshaping Handler (Required Even In Fullscreen-Only Modes)
  void reshape(int w, int h)
  {
  	glViewport(0, 0, w, h);
  	glMatrixMode(GL_PROJECTION);     // Select The Projection Matrix
  	glLoadIdentity();                // Reset The Projection Matrix
  	// Calculate The Aspect Ratio And Set The Clipping Volume
  	if (h == 0) h = 1;
  	gluPerspective(80, (float)w/(float)h, 1.0, 5000.0);
  	glMatrixMode(GL_MODELVIEW);      // Select The Modelview Matrix
  	glLoadIdentity();                // Reset The Modelview Matrix
  }
  
  // Our Keyboard Handler (Normal Keys)
  void keyboard(unsigned char key, int x, int y)
  {
  	switch (key) {
  		case 27:        // When Escape Is Pressed...
  			exit(0);    // Exit The Program
  		break;          // Ready For Next Case
  		default:        // Now Wrap It Up
  		break;
  	}
  }
  
  // Our Keyboard Handler For Special Keys (Like Arrow Keys And Function Keys)
  void special_keys(int a_keys, int x, int y)
  {
  	switch (a_keys) {
  		case GLUT_KEY_F1:
  			// We Can Switch Between Windowed Mode And Fullscreen Mode Only
  			if (!g_gamemode) {
  				g_fullscreen = !g_fullscreen;       // Toggle g_fullscreen Flag
  				if (g_fullscreen) glutFullScreen(); // We Went In Fullscreen Mode
  				else glutReshapeWindow(500, 500);   // We Went In Windowed Mode
  			}
  		break;
  		default:
  		break;
  	}
  }
  
  // Ask The User If He Wish To Enter GameMode Or Not
  void ask_gamemode()
  {
  	int answer;
  	// Use Windows MessageBox To Ask The User For Game Or Windowed Mode
  	answer = MessageBox(NULL, "Do you want to enter game mode?", "Question",
  						MB_ICONQUESTION | MB_YESNO);
  	g_gamemode = (answer == IDYES);
  	// If Not Game Mode Selected, Use Windowed Mode (User Can Change That With F1)
  	g_fullscreen = false; 
  }
  
  // Main Function For Bringing It All Together.
  int main(int argc, char** argv)
  {
  	ask_gamemode();                                  // Ask For Fullscreen Mode
  	glutInit(&argc, argv);                           // GLUT Initializtion
  	glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);     // Display Mode (Rgb And Double Buffered)
  	if (g_gamemode) {
  		glutGameModeString("640x480:16");            // Select The 640x480 In 16bpp Mode
  		if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE))
  			glutEnterGameMode();                     // Enter Full Screen
  		else g_gamemode = false;                     // Cannot Enter Game Mode, Switch To Windowed
  	}
  	if (!g_gamemode) {
  		glutInitWindowSize(500, 500);                // Window Size If We Start In Windowed Mode
  		glutCreateWindow("NeHe's OpenGL Framework"); // Window Title 
  	}
  	init();                                          // Our Initialization
  	glutDisplayFunc(render);                         // Register The Display Function
  	glutReshapeFunc(reshape);                        // Register The Reshape Handler
  	glutKeyboardFunc(keyboard);                      // Register The Keyboard Handler
  	glutSpecialFunc(special_keys);                   // Register Special Keys Handler
  	glutMainLoop();                                  // Go To GLUT Main Loop
  	return 0;
  }
  