##################################################################
Integrating a HOOPS Luminate Window into an Existing OpenGL Window
##################################################################

A HOOPS Luminate window can be created from a window handle provided by the application (a HWND on Windows, a NSView on OSX, a Display / Visual / Screen info on Linux). In this case, the HOOPS Luminate window internally creates and manages the OpenGL context it'll use for the rendering. In HOOPS Luminate, it's possible to create a window that uses an OpenGL context that exist already and that is used by the hosting application already:

.. code:: cpp

    // Assuming we have an application that has a running OpenGL window:
    //  - 'app_hwnd' must be be a valid application handle (HWND).
    //  - 'app_hdc' is a valid application device context (HDC).
    //  - 'app_hglrc' is a valid application OpenGL context (HGLRC).
    RED_RC rc;
    RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
    int width = 1920;
    int height = 1080;

    // Create a RED::WindowRenderInfo instance to setup external OpenGL parameters:
    RED::WindowRenderInfo winfo;
    winfo.SetHostingContext( app_hdc, app_hglrc );

    // Create a rendering window using the external context specification:
    RED::Object* window = RED::Factory::CreateREDWindow( *resmgr, app_hwnd, width, height, &winfo, rc );
    if( !window )
    {
        // Handle critical errors here.
    }
    if( rc != RED_OK )
    {
        // Handle error codes here.
    }

Once created, HOOPS Luminate can be used to draw in the application window directly, co-existing with the application's OpenGL code. See :doc:`/book/subjects/bk_ba/bk_ba_w/bk_ba_integration_into_an_external_opengl_window` for details on how to proceed. 
