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 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; }
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; }