Title / Description
Code #include <iostream> #include <SDL.h> #include <SDL_opengl.h> #include <CEGUI/CEGUI.h> #include <CEGUI/RendererModules/OpenGL/GLRenderer.h> #include <CEGUI/XMLParserModules/Expat/XMLParser.h> #include <CEGUI/ImageCodecModules/DevIL/ImageCodec.h> int main(int, char**) { /*************************************** * Init SDL ***************************************/ if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ std::cout << "SDL_Init Error: " << SDL_GetError() << std::endl; SDL_Quit(); return 1; } SDL_Window* p_window = SDL_CreateWindow("Test window", 100, 100, 640, 480, SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL); if (!p_window) { std::cerr << "failed to set up window." << std::endl; SDL_Quit(); return 2; } SDL_ShowCursor(0); SDL_Renderer* p_sdl_renderer = SDL_CreateRenderer(p_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); if (!p_sdl_renderer) { SDL_DestroyWindow(p_window); SDL_Quit(); std::cerr << "Faield to set up renderer." << std::endl; return 3; } /*************************************** * Init CEGUI ***************************************/ //CEGUI::OpenGLRenderer& renderer = CEGUI::OpenGLRenderer::bootstrapSystem(); CEGUI::OpenGLRenderer& renderer = CEGUI::OpenGLRenderer::create(); CEGUI::DefaultResourceProvider* p_provider = new CEGUI::DefaultResourceProvider(); CEGUI::ExpatParser* p_xml_parser = new CEGUI::ExpatParser(); CEGUI::DevILImageCodec* p_imgcodec = new CEGUI::DevILImageCodec(); CEGUI::System::create(renderer, p_provider, p_xml_parser, p_imgcodec, NULL); p_provider->setResourceGroupDirectory("schemes", "/usr/share/cegui-0/schemes/"); p_provider->setResourceGroupDirectory("imagesets", "/usr/share/cegui-0/imagesets/"); p_provider->setResourceGroupDirectory("fonts", "/usr/share/cegui-0/fonts/"); p_provider->setResourceGroupDirectory("layouts", "/usr/share/cegui-0/layouts/"); p_provider->setResourceGroupDirectory("looknfeels", "/usr/share/cegui-0/looknfeel/"); p_provider->setResourceGroupDirectory("lua_scripts", "/usr/share/cegui-0/lua_scripts/"); /* Now tell each of CEGUI’s resource-consuming classes (the "*Manager" classes) * which group of the filesystem provider to ask for its stuff. */ CEGUI::ImageManager::setImagesetDefaultResourceGroup("imagesets"); CEGUI::Font::setDefaultResourceGroup("fonts"); CEGUI::Scheme::setDefaultResourceGroup("schemes"); CEGUI::WidgetLookManager::setDefaultResourceGroup("looknfeels"); CEGUI::WindowManager::setDefaultResourceGroup("layouts"); CEGUI::ScriptModule::setDefaultResourceGroup("lua_scripts"); CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme"); CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-12.font"); CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-12"); CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); // Tell CEGUI how large our Window is. Forget this and you’ll never see anything. CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(640, 480)); CEGUI::WindowManager& wmgr = CEGUI::WindowManager::getSingleton(); CEGUI::Window* p_cegui_rootwin = wmgr.createWindow("DefaultWindow", "root"); CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(p_cegui_rootwin); CEGUI::FrameWindow* p_testframe = static_cast<CEGUI::FrameWindow*>(wmgr.createWindow("TaharezLook/FrameWindow", "testWindow")); p_testframe->setPosition(CEGUI::UVector2(CEGUI::UDim(0.25, 0.0), CEGUI::UDim(0.25, 0.0f))); p_testframe->setSize(CEGUI::USize(CEGUI::UDim(0.5f, 0.0f), CEGUI::UDim(0.5f, 0.0f))); p_testframe->setText("Hello, World!"); p_cegui_rootwin->addChild(p_testframe); glClearColor(0, 0, 0, 255); SDL_Surface* p_image = SDL_LoadBMP("../hello.bmp"); SDL_Texture* p_imgtexture = SDL_CreateTextureFromSurface(p_sdl_renderer, p_image); SDL_FreeSurface(p_image); p_image = NULL; /*************************************** * Main loop ***************************************/ bool quit = false; SDL_Event evt; while (!quit) { // Grab all events from the queue while (SDL_PollEvent(&evt)) { if (evt.type == SDL_QUIT) { quit = true; } else { std::cout << "Unknown event received." << std::endl; } } SDL_RenderClear(p_sdl_renderer); SDL_RenderCopy(p_sdl_renderer, p_imgtexture, NULL, NULL); SDL_RenderPresent(p_sdl_renderer); SDL_GLContext context = SDL_GL_CreateContext(p_window); glClear(GL_COLOR_BUFFER_BIT); CEGUI::System::getSingleton().renderAllGUIContexts(); SDL_GL_SwapWindow(p_window); SDL_GL_DeleteContext(context); } /*************************************** * Cleanup ***************************************/ CEGUI::System::destroy(); CEGUI::OpenGLRenderer::destroy(renderer); delete p_imgcodec; delete p_xml_parser; delete p_provider; SDL_DestroyTexture(p_imgtexture); SDL_DestroyRenderer(p_sdl_renderer); SDL_DestroyWindow(p_window); SDL_Quit(); return 0; }
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code