CGwenStart::CGwenStart( vgui::VPANEL parent ) : vgui::Panel( NULL, "GwenStart" ) { SetParent( parent ); SetVisible( false ); int x, y, w, h; vgui::surface()->GetWorkspaceBounds( x, y, w, h ); SetBounds( x, y, w, h ); vgui::ISurface *surface = vgui::surface(); if ( !g_pRenderer ) { g_pRenderer = new Gwen::Renderer::VguiRenderer( surface, vgui::scheme() ); } if ( !g_pSkin ) { Gwen::Skin::TexturedBase *skin = new Gwen::Skin::TexturedBase(); skin->SetRender( g_pRenderer ); skin->Init( "gwen/DefaultSkin" ); skin->SetDefaultFont( L"Tahoma", 11 ); g_pSkin = skin; } }
// // Program starts here // int main(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // // Create a window and attach directx to it // g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ); g_pHWND = CreateGameWindow(); CreateD3DDevice(); // // Create a GWEN DirectX renderer // Gwen::Renderer::DirectX9* pRenderer = new Gwen::Renderer::DirectX9( g_pD3DDevice ); // // Create a GWEN skin // Gwen::Skin::TexturedBase skin; skin.SetRender( pRenderer ); skin.Init( "DefaultSkin.png" ); // // Create a Canvas (it's root, on which all other GWEN panels are created) // Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas->SetSize( 1000, 622 ); pCanvas->SetDrawBackground( true ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); // // Create our unittest control (which is a Window with controls in it) // UnitTest* pUnit = new UnitTest( pCanvas ); pUnit->SetPos( 10, 10 ); // // Create a Windows Control helper // (Processes Windows MSG's and fires input at GWEN) // Gwen::Input::Windows GwenInput; GwenInput.Initialize( pCanvas ); // // Begin the main game loop // MSG msg; while( true ) { // Skip out if the window is closed if ( !IsWindowVisible( g_pHWND ) ) break; // If we have a message from windows.. if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { // .. give it to the input handler to process GwenInput.ProcessMessage( msg ); // if it's QUIT then quit.. if ( msg.message == WM_QUIT ) break; // Handle the regular window stuff.. TranslateMessage(&msg); DispatchMessage(&msg); } else { // Normal DirectX rendering loop g_pD3DDevice->BeginScene(); g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 0, 0, 0 ), 1, 0 ); // This is how easy it is to render GWEN! pCanvas->RenderCanvas(); g_pD3DDevice->EndScene(); g_pD3DDevice->Present( NULL, NULL, NULL, NULL ); } } if ( g_pD3DDevice ) { g_pD3DDevice->Release(); g_pD3DDevice = NULL; } if ( g_pD3D ) { g_pD3D->Release(); g_pD3D = NULL; } }
int main() { b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow(); window->setKeyboardCallback(keyCallback); b3gWindowConstructionInfo wci; wci.m_openglVersion = 2; wci.m_width = sWidth; wci.m_height = sHeight; // wci.m_resizeCallback = MyResizeCallback; window->createWindow(wci); window->setResizeCallback(MyResizeCallback); int majorGlVersion, minorGlVersion; if (!sscanf((const char*)glGetString(GL_VERSION), "%d.%d", &majorGlVersion, &minorGlVersion)==2) { printf("Exit: Error cannot extract OpenGL version from GL_VERSION string\n"); exit(0); } char title[1024]; if (wci.m_openglVersion>2) { sprintf(title,"Gwen with OpenGL %d.%d\n",majorGlVersion,minorGlVersion); } else { sprintf(title,"Gwen with OpenGL %d\n",wci.m_openglVersion); } window->setWindowTitle(title); if (majorGlVersion>=3 && wci.m_openglVersion>=3) { float retinaScale = 1.f; #ifndef __APPLE__ #ifndef _WIN32 //we need glewExperimental on Linux glewExperimental = GL_TRUE; #endif // _WIN32 glewInit(); #endif //we ned to call glGetError twice, because of some Ubuntu/Intel/OpenGL issue GLuint err = glGetError(); err = glGetError(); assert(err==GL_NO_ERROR); retinaScale = window->getRetinaScale(); primRenderer = new GLPrimitiveRenderer(sWidth,sHeight); sth_stash* font = initFont(primRenderer ); gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale); } else { //OpenGL 2.x gwenRenderer = new Gwen::Renderer::OpenGL_DebugFont(); skin.SetRender( gwenRenderer ); glClearColor(1,0,0,1); } // // Create a GWEN OpenGL Renderer // // Gwen::Renderer::OpenGL_DebugFont * pRenderer = new Gwen::Renderer::OpenGL_DebugFont(); // // Create a GWEN skin // #ifdef USE_TEXTURED_SKIN Gwen::Skin::TexturedBase skin; skin.SetRender( pRenderer ); skin.Init("DefaultSkin.png"); #else skin.SetRender( gwenRenderer ); #endif // // Create a Canvas (it's root, on which all other GWEN panels are created) // pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas->SetSize( sWidth, sHeight); pCanvas->SetDrawBackground( true ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); window->setMouseButtonCallback(MyMouseButtonCallback); window->setMouseMoveCallback(MyMouseMoveCallback); // // Create our unittest control (which is a Window with controls in it) // UnitTest* pUnit = new UnitTest( pCanvas ); pUnit->SetPos( 10, 10 ); // // Create a Windows Control helper // (Processes Windows MSG's and fires input at GWEN) // //Gwen::Input::Windows GwenInput; //GwenInput.Initialize( pCanvas ); // // Begin the main game loop // // MSG msg; while( !window->requestedExit() ) { if (majorGlVersion<3 || wci.m_openglVersion<3) { saveOpenGLState(sWidth,sHeight); } // Skip out if the window is closed //if ( !IsWindowVisible( g_pHWND ) ) //break; // If we have a message from windows.. // if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { // .. give it to the input handler to process // GwenInput.ProcessMessage( msg ); // if it's QUIT then quit.. // if ( msg.message == WM_QUIT ) // break; // Handle the regular window stuff.. // TranslateMessage(&msg); // DispatchMessage(&msg); } window->startRendering(); // Main OpenGL Render Loop { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable(GL_BLEND); GLint err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); //glColor4ub(255,0,0,255); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glEnable(GL_BLEND); err = glGetError(); assert(err==GL_NO_ERROR); pCanvas->RenderCanvas(); if (avoidUpdate<=0) avoidUpdate++; // SwapBuffers( GetDC( g_pHWND ) ); } window->endRendering(); if (majorGlVersion<3 || wci.m_openglVersion<3) { restoreOpenGLState(); } } window->closeWindow(); delete window; }
int main(int argc, char* argv[]) { if(!ParseArguments(argc, argv)) { printf("libdetector Test Application Usage:\n"); printf("\t--save=STRING\t\tDirectory to save motion videos (if absent, will not save!)\n"); return 0; } printf("Loading Skin...\n"); // Init the Gwen GUI and SFML window sf::RenderWindow App( sf::VideoMode( 1366, 690, 32 ), "Detector", sf::Style::Close ); Gwen::Renderer::SFML GwenRenderer( App ); Gwen::Skin::TexturedBase skin; skin.SetRender( &GwenRenderer ); skin.Init( "DefaultSkin.png" ); skin.SetDefaultFont( L"OpenSans.ttf", 11 ); Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas->SetSize( App.GetWidth(), App.GetHeight() ); pCanvas->SetDrawBackground( true ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); Gwen::Input::SFML GwenInput; GwenInput.Initialize( pCanvas ); printf("Canvas created!\n"); InstanceManager* mgr = new InstanceManager(pCanvas); thread t(InstanceThread, mgr); //sf::Sleep(1.0); while ( App.IsOpened() ) { // Handle events sf::Event Event; while ( App.GetEvent(Event) ) { if ((Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))) { App.Close(); break; } GwenInput.ProcessMessage( Event ); } App.Clear(); while(mgr->UsingContext()) // Wait until we don't have the context anymore before retaking it back { sf::Sleep(0.1); printf("Using context!\n"); } pCanvas->RenderCanvas(); App.Display(); } return 0; }
//////////////////////////////////////////////////////////// /// Entry point of application /// /// \return Application exit code /// //////////////////////////////////////////////////////////// int main() { // Create the window of the application sf::RenderWindow App( sf::VideoMode( 800, 600, 32 ), "GWEN: SFML" ); Gwen::Renderer::SFML GwenRenderer( App ); // // Create a GWEN skin // //Gwen::Skin::Simple skin; //skin.SetRender( &GwenRenderer ); Gwen::Skin::TexturedBase skin; skin.SetRender( &GwenRenderer ); skin.Init( "DefaultSkin.png" ); // The fonts work differently in SFML - it can't use // system fonts. So force the skin to use a local one. skin.SetDefaultFont( L"OpenSans.ttf", 11 ); // // Create a Canvas (it's root, on which all other GWEN panels are created) // Gwen::Controls::Canvas* pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas->SetSize( 800, 600 ); pCanvas->SetDrawBackground( true ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); // // Create our unittest control (which is a Window with controls in it) // UnitTest* pUnit = new UnitTest( pCanvas ); pUnit->SetPos( 10, 10 ); // // Create an input processor // Gwen::Input::SFML GwenInput; GwenInput.Initialize( pCanvas ); while ( App.IsOpened() ) { // Handle events sf::Event Event; #if SFML_VERSION_MAJOR == 2 while ( App.PollEvent(Event) ) #else while ( App.GetEvent(Event) ) #endif { // Window closed or escape key pressed : exit #if SFML_VERSION_MAJOR == 2 if ((Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Keyboard::Escape))) #else if ((Event.Type == sf::Event::Closed) || ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))) #endif { App.Close(); break; } GwenInput.ProcessMessage( Event ); } // Clear the window App.Clear(); pCanvas->RenderCanvas(); App.Display(); } return EXIT_SUCCESS; }
int main() { float retinaScale = 1.f; b3gDefaultOpenGLWindow* window = new b3gDefaultOpenGLWindow(); b3gWindowConstructionInfo wci; wci.m_width = sWidth; wci.m_height = sHeight; window->createWindow(wci); window->setResizeCallback(MyResizeCallback); window->setWindowTitle("render test"); #ifndef __APPLE__ glewInit(); #endif retinaScale = window->getRetinaScale(); primRenderer = new GLPrimitiveRenderer(sWidth,sHeight); sth_stash* font = initFont(primRenderer ); gwenRenderer = new GwenOpenGL3CoreRenderer(primRenderer,font,sWidth,sHeight,retinaScale); // // Create a GWEN OpenGL Renderer // // Gwen::Renderer::OpenGL_DebugFont * pRenderer = new Gwen::Renderer::OpenGL_DebugFont(); // // Create a GWEN skin // #ifdef USE_TEXTURED_SKIN Gwen::Skin::TexturedBase skin; skin.SetRender( pRenderer ); skin.Init("DefaultSkin.png"); #else Gwen::Skin::Simple skin; skin.SetRender( gwenRenderer ); #endif // // Create a Canvas (it's root, on which all other GWEN panels are created) // pCanvas = new Gwen::Controls::Canvas( &skin ); pCanvas->SetSize( sWidth, sHeight); pCanvas->SetDrawBackground( true ); pCanvas->SetBackgroundColor( Gwen::Color( 150, 170, 170, 255 ) ); window->setMouseButtonCallback(MyMouseButtonCallback); window->setMouseMoveCallback(MyMouseMoveCallback); // // Create our unittest control (which is a Window with controls in it) // UnitTest* pUnit = new UnitTest( pCanvas ); pUnit->SetPos( 10, 10 ); // // Create a Windows Control helper // (Processes Windows MSG's and fires input at GWEN) // //Gwen::Input::Windows GwenInput; //GwenInput.Initialize( pCanvas ); // // Begin the main game loop // // MSG msg; while( !window->requestedExit() ) { // Skip out if the window is closed //if ( !IsWindowVisible( g_pHWND ) ) //break; // If we have a message from windows.. // if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) { // .. give it to the input handler to process // GwenInput.ProcessMessage( msg ); // if it's QUIT then quit.. // if ( msg.message == WM_QUIT ) // break; // Handle the regular window stuff.. // TranslateMessage(&msg); // DispatchMessage(&msg); } window->startRendering(); // Main OpenGL Render Loop { glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glEnable(GL_BLEND); GLint err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); //glColor4ub(255,0,0,255); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); // saveOpenGLState(width,height);//m_glutScreenWidth,m_glutScreenHeight); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); err = glGetError(); assert(err==GL_NO_ERROR); err = glGetError(); assert(err==GL_NO_ERROR); glEnable(GL_BLEND); err = glGetError(); assert(err==GL_NO_ERROR); pCanvas->RenderCanvas(); // SwapBuffers( GetDC( g_pHWND ) ); } window->endRendering(); } window->closeWindow(); delete window; }