Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: openGL glut how to make loading screen and more?

  1. #1
    Newbie Newbie
    Join Date
    Aug 2017
    Posts
    2

    openGL glut how to make loading screen and more?

    Hi Im Alex(BOY) and Im 12 but that's deep information XD.

    So Im asking how do i make a loading screen, and i have other questions.
    So what Im trying to do is to add a loading screen or to be clear a loading screen for a game,
    and that contains the basic game loop.

    (Just to say im using openGL c++ glut/windows)

    That means you won't help me if you tell me something made with glew/SDL/sfml ect.
    If you tell me something from this list (i'll be (\-_-/)whut the).
    I know it sounds stupid but im trying to make my own fps shooter game for PC
    and i want it to be from only openGL glut and other libraries in the compiler VS2017,
    and the only thing i want to know is how do i make a loading screen and the basic game loop.

    Thanks in advance <3 <3.

    -xXrandomryzeXx/ALexander

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    Quote Originally Posted by xXrandomryzeXx View Post
    Hi Im Alex
    Welcome to the boards!

    ...how do i make a loading screen and the basic game loop. ...im using openGL c++ glut/windows)
    In a basic GLUT program (see below), you implement your own callback function to render the contents of the window. You register this callback function with GLUT using glutDisplayFunc(). You prompt GLUT to call this function again soon by calling glutPostRedisplay().

    As far as a loading screen, if your game is in "loading mode" you can have your display function clear the screen and render some text, display an image, or whatever you want to do in loading mode.

    As far as the basic game loop, GLUT basically takes care of that for you in glutMainLoop(). Inside this loop, it invokes callback functions you implement when "something happens" in the game loop that it thinks you might want to react to (e.g. mouse button pressed, key pressed, mouse moved, window needs displayed, etc.). All you have to do is implement and register the appropriate callbacks.

    If you haven't already, you might want to browse some of the GLUT tutorials for ideas:

    * GLUT Examples
    * Lighthouse3D GLUT Tutorials

    in particular:

    * GLUT Tutorial (Lighthouse3D)

    Keep in mind that GLUT is one of the older OpenGL toolkits, so many of the OpenGL GLUT tutorials you find on the net typically won't be exercising modern OpenGL techniques (though you can implement modern OpenGL in a GLUT-based program!) At some point you may outgrow it. However, GLUT is great when you're just getting started with GL and for whipping up small GL test programs because it abstracts all the platform-specific silliness needed to create windows and receive device events. I still use it occasionally!

    Code cpp:
    //-----------------------------------------------------------------------
    //  Stand-alone GLUT test program
    //-----------------------------------------------------------------------
     
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <GL/glew.h>
    #include <GL/glut.h>
     
    //-----------------------------------------------------------------------
     
    void checkGLError( const char hdr[] )
    {
        int err = glGetError();
        if( err )
        {
            fprintf(stderr, "ERROR %s: %s\n", hdr, gluErrorString(err));
            exit(1);
        }
    }
     
    //-----------------------------------------------------------------------
     
    void init()
    {
        //------------------------------------------------------------
        // Put your GL init code here.
        //------------------------------------------------------------
     
        // glGenBuffers( 1, &Vbo_handle );
        //   etc.
     
        checkGLError( "init" );
    }
     
    //-----------------------------------------------------------------------
     
    void reshape( int width, int height )
    {
        glViewport(0, 0, width, height);
    }
     
    //-----------------------------------------------------------------------
     
    void display()
    {
        // Clear screen
        glClearColor( 0.1f, 0.1f, 0.43f, 1.0f );
        glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
     
        //------------------------------------------------------------
        // Put your GL draw code here.
        //------------------------------------------------------------
     
        // Swap
        glutSwapBuffers();
     
        // Cause display() to be called again.
        glutPostRedisplay();
        checkGLError( "End of display()" );
    }
     
    //-----------------------------------------------------------------------
     
    void keyboard( unsigned char key, int x, int y )
    {
        switch (key)
        {
            case 27:         // ESC quits
                exit(0);
                break;
        }
    }
     
    int main( int argc, char** argv )
    {
        // Init GLUT
        glutInit( &argc, argv );
        glutInitDisplayMode(  GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE  );
        glutCreateWindow( argv[0] );
     
        glutKeyboardFunc( keyboard );
        glutDisplayFunc( display );
        glutReshapeFunc( reshape );
     
        glutReshapeWindow( 400,400 );
     
        // Init GLEW
        GLenum err = glewInit();
        if ( err != GLEW_OK )
        {
            // Problem: glewInit failed, something is seriously wrong.
            fprintf( stderr, "Error: %s\n", glewGetErrorString(err) );
            exit(1);
        }
     
        printf( "GL_RENDERER = %s\n", glGetString( GL_RENDERER) );
     
        init();
     
        glutMainLoop();
        return 0;
    }
    Last edited by Dark Photon; 08-25-2017 at 05:38 AM.

  3. #3
    Newbie Newbie
    Join Date
    Aug 2017
    Posts
    2

    thanks

    Thanks for this and i'll sure be checking the tutorials, and maybe i'll use other libraries from some point because of you and thanks for that tho.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •