Integration and coexistence with external OpenGL applications - Linderdaum Engine
Gallery
Community
SEARCH
TOOLBOX
LANGUAGES

Integration and coexistence with external OpenGL applications

From Linderdaum Engine

Jump to: navigation, search

In this tutorial we will learn how to integrate Linderdaum Engine into existing OpenGL application.

GLUT integration

Consider simple example where we would like to use the engine together with GLUT library. We initialize GLUT OpenGL window the following way:

   const LString WindowName = "Linderdaum Engine - GLUT integration";
   glutInit(&argc, argv);     
 
   glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);
   glutInitWindowSize(1024, 768);      
   glutCreateWindow( WindowName.c_str() );

here OpenGL context is created and we want the engine to share the existing context with GLUT library. To do this we need to use clDeployer::DeployEnvironment() method and pass to it a handle to GLUT window:

   sEnvironment Env;
 
   // get handle to the GLUT window
   HWND hwnd = FindWindow( "GLUT", WindowName.c_str() );
 
   Env.DeployEnvironment( "",                        // empty command line
                          DEFAULT_ENGINE_LOG_FILE,          
                          DEFAULT_ENGINE_ROOT_DIR, 
                          DEFAULT_ENGINE_ROOT_PACK,
                          DEFAULT_ENGINE_INI_FILE,
                          false,                     // don't open new viewport
                          true,                      // use existing OpenGL context
                          hwnd );                    // handle to application window for rendering

Now the engine is attached to GLUT window and existing OpenGL context. Also it gets all keyboard and mouse user input. Let us organize main loop:

   // GLUT display function
   void display()
   {
       // do GLUT rendering here
       // .........
 
      // update engine
      Env.Engine->GenerateTicks();
 
      // swap back and front buffer
      SwapBuffers( wglGetCurrentDC() );
   }

and pass it to GLUT display and idle functions:

   glutDisplayFunc( display );      
   glutIdleFunc( display );      
 
   // start main loop
   glutMainLoop();

That's it. You now have Linderdaum Engine integrated into existing GLUT application.