SFML test without tabs
C++
code posted
by
Quintus
created at 15 Mar 12:51
Edit
|
Back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
#include <SFML/Window.hpp> #include <SFML/Graphics.hpp> #include <SFML/OpenGL.hpp> #include <CEGUI/CEGUI.h> #include <CEGUI/RendererModules/OpenGL/GLRenderer.h> //#include <CEGUI/ImageCodecModules/DevIL/ImageCodec.h> int main(int argc, char* argv[]) { sf::Window window(sf::VideoMode(800, 600), "SFML test"); //sf::CircleShape shape(100.0f); //shape.setFillColor(sf::Color::Green); sf::Clock clock; CEGUI::OpenGLRenderer& cegui_renderer = CEGUI::OpenGLRenderer::create(CEGUI::Sizef(800, 600)); cegui_renderer.enableExtraStateSettings(true); CEGUI::System::create(cegui_renderer); // setup resource directories CEGUI::DefaultResourceProvider* rp = static_cast<CEGUI::DefaultResourceProvider*>(CEGUI::System::getSingleton().getResourceProvider()); rp->setResourceGroupDirectory("schemes", "../datafiles/schemes/"); rp->setResourceGroupDirectory("imagesets", "../datafiles/imagesets/"); rp->setResourceGroupDirectory("fonts", "../datafiles/fonts/"); rp->setResourceGroupDirectory("layouts", "../datafiles/layouts/"); rp->setResourceGroupDirectory("looknfeels", "../datafiles/looknfeel/"); rp->setResourceGroupDirectory("lua_scripts", "../datafiles/lua_scripts/"); rp->setResourceGroupDirectory("schemas", "../datafiles/xml_schemas/"); // set default resource groups 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"); // load TaharezLook scheme and DejaVuSans-10 font CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme", "schemes"); CEGUI::FontManager::getSingleton().createFromFile("DejaVuSans-10.font"); // set default font and cursor image and tooltip type CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultFont("DejaVuSans-10"); CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow"); CEGUI::System::getSingleton().getDefaultGUIContext().setDefaultTooltipType("TaharezLook/Tooltip"); window.setMouseCursorVisible(false); window.setVerticalSyncEnabled(true); window.setActive(); 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, 0), CEGUI::UDim(0, 0))); p_testframe->setSize(CEGUI::USize(CEGUI::UDim(0, 300), CEGUI::UDim(0, 300))); p_testframe->setText("Hello, World!"); p_cegui_rootwin->addChild(p_testframe); /*glEnable(GL_DEPTH_TEST); glDepthMask(GL_TRUE); glClearDepth(1.0f); glDisable(GL_LIGHTING); glViewport(0, 0, window.getSize().x, window.getSize().y); glMatrixMode(GL_PROJECTION); glLoadIdentity(); GLfloat ratio = static_cast<float>(window.getSize().x) / window.getSize().y; glFrustum(-ratio, ratio, -1.f, 1.f, 1.f, 500.f); glEnable(GL_TEXTURE_2D);*/ CEGUI::OpenGLRenderer* renderer = static_cast<CEGUI::OpenGLRenderer*>(CEGUI::System::getSingleton().getRenderer()); bool running = true; while (running) { sf::Event event; while (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { running = false; } else if (event.type == sf::Event::Resized) { CEGUI::System::getSingleton().notifyDisplaySizeChanged(CEGUI::Sizef(static_cast<float>(event.size.width), static_cast<float>(event.size.height))); glViewport(0, 0, event.size.width, event.size.height); } else if (event.type == sf::Event::MouseMoved) { CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(static_cast<float>(event.mouseMove.x), static_cast<float>(event.mouseMove.y)); } } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); //CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse(time_elapsed); sf::Time elapsed = clock.restart(); CEGUI::System::getSingleton().injectTimePulse(elapsed.asSeconds()); CEGUI::System::getSingleton().getDefaultGUIContext().injectTimePulse(elapsed.asSeconds()); renderer->beginRendering(); CEGUI::System::getSingleton().renderAllGUIContexts(); renderer->endRendering(); // Hear any SFML-graphics-based stuff would need to be placed // between window.pushGLStates() and window.popGLStates(). window.display(); } window.close(); return 0; } |
4.87 KB in 5 ms with coderay