Results 1 to 6 of 6

Thread: How to create an OpenGL Intro

  1. #1
    Member Newbie
    Join Date
    Apr 2008
    Location
    virginia
    Posts
    30

    How to create an OpenGL Intro

    Code :
    // 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(&amp;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..
    Sean

  2. #2
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: OpenGL error when compling.

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

    http://www.codeguru.com/forum/showthread.php?t=360665

  3. #3
    Member Newbie
    Join Date
    Apr 2008
    Location
    virginia
    Posts
    30

    Re: OpenGL error when compling.

    I modified my post.
    Sean

  4. #4
    Member Contributor
    Join Date
    Nov 2000
    Location
    Thuringia, Germany
    Posts
    85

    Re: OpenGL error when compling.

    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.


    bastian

  5. #5
    Member Newbie
    Join Date
    Apr 2008
    Location
    virginia
    Posts
    30

    Re: OpenGL error when compling.

    Quote Originally Posted by mcbastian
    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.


    bastian
    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.
    Sean

  6. #6
    Senior Member Regular Contributor Rosario Leonardi's Avatar
    Join Date
    Aug 2008
    Location
    Italy
    Posts
    356

    Re: OpenGL error when compling.

    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.

    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.
    ~ ~ I tell you, realtime 3D is made of blood, sweat and screams! ~ ~

Similar Threads

  1. Black Window, OpenGL Programming Guide 8th Ed. First Intro Program
    By Natedawg523 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-17-2015, 06:56 PM
  2. Intro menu OpenGL executable
    By PascalM123 in forum OpenGL: General
    Replies: 0
    Last Post: 11-12-2010, 11:13 AM
  3. money for help w/ an intro OpenGL class
    By jlwgreg in forum OpenGL: macOS
    Replies: 8
    Last Post: 05-31-2004, 03:15 AM
  4. help for money w/ an intro OpenGL class
    By jlwgreg in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 12-06-2003, 06:56 AM
  5. money for help w/ an intro OpenGL class
    By jlwgreg in forum OpenGL: macOS
    Replies: 0
    Last Post: 12-02-2003, 01:15 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean