History

new package cegui

Quintus committed 13 years ago

Commit 17fb2b71 parent 9e2b2fd3 files · +155 −0Browse files

Showing the changes to src/cegui-test.cpp (1 of 3 files). Show all

Unified · Split

src/cegui-test.cpp+96−0
@@ -0,0 +1,96 @@
1/*
2 * This file is part of MXE.
3 * See index.html for further information.
4 */
5
6/*************************************************
7 * CEGUI demo program. This creates an OpenGL window
8 * and makes CEGUI draw an "in-game" window into it.
9 ************************************************/
10
11#include <GL/freeglut.h>
12#include <CEGUI/CEGUI.h>
13#include <CEGUI/RendererModules/OpenGL/CEGUIOpenGLRenderer.h>
14
15// We’re lazy
16using namespace CEGUI;
17
18// Prototypes
19void main_loop();
20
21// Main program entry point
22int main(int argc, char* argv[])
23{
24 // Initialize OpenGL
25 glutInit(&argc, argv);
26 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
27 glutInitWindowSize(640, 480);
28
29 // Create the default GL context to have CEGUI draw upon
30 int window_id = glutCreateWindow("Test");
31
32 // Initialize CEGUI (will automatically use the default GL context)
33 OpenGLRenderer& renderer = OpenGLRenderer::bootstrapSystem();
34
35 // Tell CEGUI where to find its resources
36 DefaultResourceProvider* p_provider = static_cast<DefaultResourceProvider*>(System::getSingleton().getResourceProvider());
37 p_provider->setResourceGroupDirectory("schemes", "../share/CEGUI/schemes");
38 p_provider->setResourceGroupDirectory("imagesets", "../share/CEGUI/imagesets");
39 p_provider->setResourceGroupDirectory("fonts", "../share/CEGUI/fonts");
40 p_provider->setResourceGroupDirectory("layouts", "../share/CEGUI/layouts");
41 p_provider->setResourceGroupDirectory("looknfeels", "../share/CEGUI/looknfeel");
42 p_provider->setResourceGroupDirectory("lua_scripts", "../share/CEGUI/lua_scripts");
43 p_provider->setResourceGroupDirectory("schemas", "../share/CEGUI/xml_schemas");
44 p_provider->setResourceGroupDirectory("animations", "../share/CEGUI/animations");
45
46 // Map the resource request to our provider
47 Imageset::setDefaultResourceGroup("imagesets");
48 Font::setDefaultResourceGroup("fonts");
49 Scheme::setDefaultResourceGroup("schemes");
50 WidgetLookManager::setDefaultResourceGroup("looknfeels");
51 WindowManager::setDefaultResourceGroup("layouts");
52 ScriptModule::setDefaultResourceGroup("lua_scripts");
53 AnimationManager::setDefaultResourceGroup("animations");
54 XMLParser* p_parser = System::getSingleton().getXMLParser();
55 // For the Xerces parser, set the XML schemas resource
56 if (p_parser->isPropertyPresent("SchemaDefaultResourceGroup"))
57 p_parser->setProperty("SchemaDefaultResourceGroup", "schemas");
58
59 // Configure the default window layouting
60 SchemeManager::getSingleton().create("TaharezLook.scheme");
61 System::getSingleton().setDefaultMouseCursor("TaharezLook", "MouseArrow");
62
63 // Create the hypothetical CEGUI root window
64 Window* p_root_window = WindowManager::getSingleton().createWindow("DefaultWindow", "root");
65 System::getSingleton().setGUISheet(p_root_window);
66
67 // Create an actual framed window we can look onto
68 FrameWindow* p_frame_window = static_cast<FrameWindow*>(WindowManager::getSingleton().createWindow("TaharezLook/FrameWindow", "testWindow"));
69 p_root_window->addChildWindow(p_frame_window);
70 p_frame_window->setPosition(UVector2(UDim(0.25f, 0), UDim(0.25f, 0)));
71 p_frame_window->setSize(UVector2(UDim(0.5f, 0), UDim(0.5f, 0)));
72 p_frame_window->setText("Hello World!");
73
74 // Enter main loop
75 main_loop();
76
77 // Clean up OpenGL
78 glutDestroyWindow(window_id);
79}
80
81/* Main loop for processing events, etc. For a real application,
82 * you definitely want to replace while(true) with checking a
83 * proper termination condition. Note all drawing operations take
84 * place on an invisible auxiliary buffer until you call glutSwapBuffers(),
85 * which paints the entire auxiliary buffer onto the screen.
86 */
87void main_loop()
88{
89 while(true) {
90 glutMainLoopEvent(); // Process events
91 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear the window background to a single color
92 glFlush();
93 System::getSingleton().renderGUI(); // Tell CEGUI to render all its stuff
94 glutSwapBuffers(); // Put the auxiliary rendering buffer onto the screen and make the screen the new auxiliary buffer.
95 }
96}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t