// The Following Directive Fixes The Problem With Extra Console Window
#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"")
#include <windows.h> // Standard Header For MSWindows Applications
#include <glut.h> // The GL Utility Toolkit (GLUT) Header
// 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(800, 600); // 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, L"Do you wish to be in Full window mode?", L"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("800x600:32"); // Select The 800x600 In 32bpp 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(800, 600); // 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;
}
If I wanted to take this code and make a little intro before dumping me into an menu area. How would I do that? I know you have to put it on a sqaure. But What if I want to put the intro page on a seperate cpp page? So that if I want to change it it’s a little cleaner…