GUI::TWindowContextPtr
COgreWindowManagerImp::CreateWindowContext( const GUI::CString& title ,
                                            const GUI::UInt32 width   ,
                                            const GUI::UInt32 height  ,
                                            const bool fullscreen     )
{GUCEF_TRACE;

    GUI::CVideoSettings videoSettings;
    videoSettings.SetFullscreenState( fullscreen );
    videoSettings.SetResolution( width, height, 24 );

    return CreateWindowContext( title         ,
                                videoSettings ,
                                NULL          );
}
GUI::TWindowContextPtr
CAndroidWindowManagerImp::CreateWindowContext( const GUI::CString& title      ,
                                               const GUI::UInt32 width        ,
                                               const GUI::UInt32 height       ,
                                               const bool fullscreen          ,
                                               const CORE::CValueList& params )
{GUCEF_TRACE;

    GUI::CVideoSettings videoSettings;
    videoSettings.SetFullscreenState( fullscreen );
    videoSettings.SetResolution( width, height, 24 );

    return CreateWindowContext( title         ,
                                videoSettings ,
                                &params       );
}
bool
CWin32WindowContext::Initialize( const GUI::CString& title                ,
                                     const GUI::CVideoSettings& videoSettings )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    if ( !CORE::CMsWin32Window::RegisterWindowClass( GetClassTypeName() ) )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "Win32WindowContext: Could not register window class" );
        return false;
    }

    // First create a regular Win32 window
    if ( m_window.WindowCreate( GetClassTypeName()                          ,
                                title                                       ,
                                0                                           ,
                                0                                           ,
                                videoSettings.GetResolutionWidthInPixels()  ,
                                videoSettings.GetResolutionHeightInPixels() ) )
    {
        // Display the new window
        m_window.Show();
        m_window.SendToForegound();
        m_window.GrabFocus();

        // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
        CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator(); 
        pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
        SubscribeTo( &pulseGenerator );

        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "Win32WindowContext: Succesfully created Win32 window" );
        return true;
    }
    return false;
}
bool
CAndroidGLESWindowContext::Initialize( const GUI::CVideoSettings& videoSettings )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // @TODO: get the app from somewhere
    struct android_app* app = NULL;
    EGLint bitDepth = (EGLint) videoSettings.GetResolutionDepthInBits() / 3;

    /*
     * Here specify the attributes of the desired configuration.
     * Below, we select an EGLConfig with at least <bitDepth> bits per color
     * component compatible with on-screen windows
     *  if <bitDepth> is 0 then the smallest available size is used.
     */
    const EGLint attribs[] =
    {
            EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
            EGL_BLUE_SIZE, bitDepth,
            EGL_GREEN_SIZE, bitDepth,
            EGL_RED_SIZE, bitDepth,
            EGL_NONE
    };
    EGLint w, h, format;
    EGLint numConfigs;
    EGLConfig config;

    m_display = eglGetDisplay( EGL_DEFAULT_DISPLAY );

    eglInitialize( m_display, 0, 0 );

    /* Here, the application chooses the configuration it desires. In this
     * sample, we have a very simplified selection process, where we pick
     * the first EGLConfig that matches our criteria */
    eglChooseConfig( m_display, attribs, &config, 1, &numConfigs );

    /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is
     * guaranteed to be accepted by ANativeWindow_setBuffersGeometry().
     * As soon as we picked a EGLConfig, we can safely reconfigure the
     * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */
    eglGetConfigAttrib( m_display, config, EGL_NATIVE_VISUAL_ID, &format );

    ANativeWindow_setBuffersGeometry( app->window, 0, 0, format );

    m_surface = eglCreateWindowSurface( m_display, config, app->window, NULL );
    m_context = eglCreateContext( m_display, config, NULL, NULL );

    if ( eglMakeCurrent( m_display, m_surface, m_surface, m_context ) == EGL_FALSE )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_IMPORTANT, "eglMakeCurrent failed" );
        return false;
    }

    eglQuerySurface( m_display, m_surface, EGL_WIDTH, &w );
    eglQuerySurface( m_display, m_surface, EGL_HEIGHT, &h );

    //engine->width = w;
    //engine->height = h;

    // Initialize GL state.
    glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST );
    glEnable( GL_CULL_FACE );
    glShadeModel( GL_SMOOTH );
    glDisable( GL_DEPTH_TEST );

    return true;
}
bool
CXWinGLWindowContext::Initialize( const GUI::CString& title                ,
                                  const GUI::CVideoSettings& videoSettings )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // First get access to the display
    ::Display* display = CORE::CX11EventDispatcher::Instance()->GetDisplay();
    if ( NULL == display )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not open display" );
        return false;
    }

    // Now proceed with setting up the OpenGL specifics
    int dummy = 0;
    if ( 0 == glXQueryExtension( display, &dummy, &dummy ) )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: X server has no OpenGL GLX extension" );
        Shutdown();
        return false;
    }

    // find an OpenGL-capable Color Index visual with depth buffer
    static int attributes[] = {GLX_RGBA, GLX_DOUBLEBUFFER, None};
    //static int attributes[] = {GLX_DEPTH_SIZE, 16, GLX_DOUBLEBUFFER, None};
    XVisualInfo* vi = glXChooseVisual( display, DefaultScreen( display ), attributes );
    if ( NULL == vi )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not get visual info for display" );
        Shutdown();
        return false;
    }

    // create an OpenGL rendering context
    GLXContext cx = glXCreateContext( display, vi,  None, GL_TRUE );
    if ( NULL == cx )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Could not create rendering context" );
        XFree( vi );
        Shutdown();
        return false;
    }
    GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Created GL context using GLX" );

    // create an X colormap since probably not using default visual
    ::Colormap cmap = ::XCreateColormap( display, RootWindow( display, vi->screen),
                                vi->visual, AllocNone);

    ::XSetWindowAttributes swa;
    swa.colormap = cmap;
    swa.border_pixel = 0;
    swa.event_mask = ExposureMask | EnterWindowMask | StructureNotifyMask | SubstructureNotifyMask;

    ::Window glwin = ::XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, videoSettings.GetResolutionWidthInPixels(),
                        videoSettings.GetResolutionHeightInPixels(), 0, vi->depth, InputOutput, vi->visual,
                        CWBorderPixel | CWColormap | CWEventMask, &swa);
    if ( 0 == glwin )
    {
        GUCEF_ERROR_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Failed to create X11 window" );
        ::XFree( vi );
        Shutdown();
        return false;
    }
    GUCEF_DEBUG_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Created X11 Window" );

//    ::XSetStandardProperties(display, glwin, "xogl", "xogl", None, 0,
//                                0, NULL);

    glXMakeCurrent( display, glwin, cx );

    // Set up the default GL state.
    glClearColor(0, 0, 0, 1);
    //glEnableClientState( GL_VERTEX_ARRAY );
    //glEnableClientState( GL_COLOR_ARRAY );

    //glEnable( GL_BLEND );
    //glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    glOrtho( 0, GetWidth(), GetHeight(), 0, -1, 1 );

    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Hook up our window object to re-use its eventing capabilities
    m_window.SetDisplay( display );
    m_window.SetScreen( vi->screen );
    m_window.SetWindow( glwin );
    m_window.SetText( title );

    // cleanup
    ::XFree( vi );

    // Display the new window
    m_window.Show();
    m_window.SendToForegound();
    //m_window.GrabFocus();

    // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
    CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator();
    pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
    SubscribeTo( &pulseGenerator, CORE::CPulseGenerator::PulseEvent );

    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "CXWinGLWindowContext: Succesfully created OpenGL rendering context" );

    return true;
}
示例#6
0
bool
COgreWindowContext::Initialize( const GUI::CString& title                ,
                                const GUI::CVideoSettings& videoSettings ,
                                const GUI::CString& ogreRenderSystem     )
{GUCEF_TRACE;

    // Do not initialize twice
    Shutdown();

    // First create a regular O/S window
    if ( m_osWindow->WindowCreate( title                                       ,
                                   0                                           ,
                                   0                                           ,
                                   videoSettings.GetResolutionWidthInPixels()  ,
                                   videoSettings.GetResolutionHeightInPixels() ) )
    {
        // Display the new window
        m_osWindow->Show();
        m_osWindow->SendToForegound();
        m_osWindow->GrabFocus();

	    // Now proceed with setting up the Ogre specifics
        
        // We grab the O/S window identifier 'the handle' 
        // This is passed to Ogre to tie things together
        CORE::Int64 windowRef = 0; 
        CORE::CString windowIntStr = m_osWindow->GetProperty( "WINDOWINT" );
        if ( !windowIntStr.IsNULLOrEmpty() )
        {
            windowRef = CORE::StringToInt64( windowIntStr );
        }
        Ogre::NameValuePairList options;         
        options[ "externalWindowHandle" ] = Ogre::StringConverter::toString( (size_t) windowRef ); 

        Ogre::Root* ogreRoot = Ogre::Root::getSingletonPtr();
        if ( ogreRoot == nullptr )
        {            
            ogreRoot = OGRE_NEW Ogre::Root( "", "", "" ); 
        }

        if ( !ogreRoot->isInitialised() )
        {
            // Load any Ogre plugins not loaded yet from the bootstrap group
            CORE::CCoreGlobal::Instance()->GetPluginControl().LoadPluginGroup( "Ogre" );
            
            const Ogre::RenderSystemList& rsList = ogreRoot->getAvailableRenderers();
            if ( rsList.size() == 0 )
            {
                GUCEF_ERROR_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: No Ogre render systems are available, cannot initialize" );
                return false;
            }

            Ogre::RenderSystem* renderSystem = nullptr;
            Ogre::RenderSystemList::const_iterator i = rsList.begin();
            while ( i != rsList.end() )
            {
                GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Available Ogre render system: " + (*i)->getFriendlyName() );
                if ( ogreRenderSystem == (*i)->getName() )
                {
                    GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Found desired/preferred Ogre render system: " + (*i)->getFriendlyName() );
                    renderSystem = (*i); 
                }
                ++i;
            }
            if ( renderSystem == nullptr )
            {
                GUCEF_WARNING_LOG( CORE::LOGLEVEL_IMPORTANT, "OgreWindowContext: Preferred Ogre render systems not available, using first available alternative: " + (*rsList.begin())->getFriendlyName() );
                renderSystem = *rsList.begin();
            }

            ogreRoot->setRenderSystem( renderSystem );
            m_sceneManager = ogreRoot->createSceneManager( Ogre::ST_GENERIC );

            m_renderWindow = ogreRoot->initialise( false, title );
        }

        m_renderWindow = ogreRoot->createRenderWindow( title, 
                                                       videoSettings.GetResolutionWidthInPixels(), 
                                                       videoSettings.GetResolutionHeightInPixels(), 
                                                       videoSettings.GetFullscreenState(),
                                                       &options ); 

        // Grab the main app pulse generator and set the update interval for the context to the desired refresh rate
        CORE::CPulseGenerator& pulseGenerator = CORE::CCoreGlobal::Instance()->GetPulseGenerator(); 
        pulseGenerator.RequestPeriodicPulses( this, 1000 / videoSettings.GetFrequency() );
        SubscribeTo( &pulseGenerator );

        GUCEF_SYSTEM_LOG( CORE::LOGLEVEL_NORMAL, "OgreWindowContext: Succesfully created Ogre rendering context" );
        m_initialized = true;
        return true;
    }
    return false;
}