How to create an OpenGL Intro

// 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

// 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

// 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…

your problem is by far not related to opengl, try on a more general forum or use google:

I modified my post.

your post seems still not to be opengl-related.
Try reading a book about CPP in general.
what is a separate cpp page?
you might mean, a separate cpp file. if you don’t know how to do that, go out and learn!

you can call any cpp function in your render loop. and, of course, you can use opengl in those functions you call inside the render loop.


ok, for right now I’m using Ms Visual C++ 2008 V9.

What if we say we have our main.cpp page. This is our function loop where we have to hit a key to exit.

now lets say I want to use open gl to do a quick flash"type" intro with all the companies involved on the project. This will be called intro.cpp

Now lets say after we load the intro and it completes we want our menu system in place. This would be called menu.cpp.

Finally we get to our last page where we build our code for tic tac toe. this one will be called tictac.cpp.

All of these c plus plus pages will need access to opengl in one form or another. I just can’t rap my head around it enough to figure out how to code it so that everything has access to it and still getting it to work.

As they told you these are C++ related question, you better improve you C/C++ knowledge and how to use your compiler before adventure in graphics world. :slight_smile:

To create an intro you have to create a state machine (with a class or with a switch).
In the intro state you will display all the animation you like and in the other state you have your game.
State machine are commonly used on application with intro or menu.

To access openGL functions you have to include the gl.h header on the top of every files that uses openGL.