Title / Description
Code #include <iostream> #include <SDL.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_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; } 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; /*************************************** * 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(); 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/"); CEGUI::System::create(renderer, p_provider, p_xml_parser, p_imgcodec, NULL); /* 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"); /*************************************** * 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); CEGUI::System::getSingleton().renderAllGUIContexts(); } /*************************************** * Cleanup ***************************************/ 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