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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
|
/***********************************************************************
created: Sat Nov 05 2011
author: Paul D Turner <paul@cegui.org.uk>
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2011 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "CEGUI/RendererModules/OpenGLES/Renderer.h"
#include "CEGUI/CEGUI.h"
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <GLES/egl.h>
#include <GLES/gl.h>
// Include last to avoid the total fail that is the definition of things
// like None, True and False as macros from affecting the other headers.
#include <X11/Xlib.h>
#include <X11/keysym.h>
//----------------------------------------------------------------------------//
// setup default-default path
#ifndef CEGUI_SAMPLE_DATAPATH
#define CEGUI_SAMPLE_DATAPATH "../datafiles"
#endif
// environment variable that overrides the location of the datafiles
#define DATAPATH_VAR_NAME "CEGUI_SAMPLE_DATAPATH"
//----------------------------------------------------------------------------//
void initialiseResourceGroupDirectories();
void initialiseDefaultResourceGroups();
const char* getDataPathPrefix();
//----------------------------------------------------------------------------//
int main(int argc, char* argv[])
{
// Create X11 window.
Display* dpy = XOpenDisplay(0);
int scn = DefaultScreen(dpy);
Window wnd = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
50, 50, 480, 320, 1,
BlackPixel(dpy, scn),
WhitePixel(dpy, scn));
XSelectInput(dpy, wnd, StructureNotifyMask |
PointerMotionMask |
ButtonPressMask | ButtonReleaseMask |
KeyPressMask | KeyReleaseMask);
XMapWindow(dpy, wnd);
XEvent evt;
while (true)
{
XNextEvent(dpy, &evt);
if (evt.type == MapNotify)
break;
}
// EGL setup
EGLDisplay egldpy = eglGetDisplay(EGL_DEFAULT_DISPLAY);
EGLint majVer, minVer;
eglInitialize(egldpy, &majVer, &minVer);
EGLint attrs[] =
{
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_NONE
};
EGLConfig config;
EGLint numconfigs;
eglChooseConfig(egldpy, attrs, &config, 1, &numconfigs);
EGLSurface surface =
eglCreateWindowSurface(egldpy, config, (NativeWindowType)wnd, 0);
EGLContext ctx = eglCreateContext(egldpy, config, 0, 0);
eglMakeCurrent(egldpy, surface, surface, ctx);
eglBindAPI(EGL_OPENGL_ES_API);
// basic gl state setup;
glViewport(0, 0, 480, 320);
glClearColor(0.2, 0.2, 0.2, 1);
// CEGUI setup
CEGUI::OpenGLESRenderer::bootstrapSystem();
initialiseResourceGroupDirectories();
initialiseDefaultResourceGroups();
CEGUI::SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
CEGUI::System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
CEGUI::WindowManager& winMgr(CEGUI::WindowManager::getSingleton());
CEGUI::Window* root = winMgr.createWindow("DefaultWindow", "root");
CEGUI::Window* fw = root->createChild("TaharezLook/FrameWindow");
fw->setPosition(CEGUI::UVector2(CEGUI::UDim(0.25, 0), CEGUI::UDim(0.25, 0)));
fw->setSize(CEGUI::USize(CEGUI::UDim(0.5, 0), CEGUI::UDim(0.5, 0)));
fw->setText("OpenGL ES 1 Test");
CEGUI::System::getSingleton().getDefaultGUIContext().setRootWindow(root);
// Main looop
bool running = true;
while (running)
{
while (XPending(dpy))
{
XNextEvent(dpy, &evt);
switch (evt.type)
{
case KeyPress:
{
int kspkcr;
KeySym* ks = XGetKeyboardMapping(dpy, evt.xkey.keycode, 1, &kspkcr);
if (ks[0] == XK_Escape)
running = false;
break;
}
case MotionNotify:
CEGUI::System::getSingleton().getDefaultGUIContext().injectMousePosition(evt.xmotion.x, evt.xmotion.y);
break;
case ButtonPress:
{
CEGUI::MouseButton btn;
if (evt.xbutton.button == Button1)
btn = CEGUI::LeftButton;
else if (evt.xbutton.button == Button2)
btn = CEGUI::RightButton;
else
break;
CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonDown(btn);
break;
}
case ButtonRelease:
{
CEGUI::MouseButton btn;
if (evt.xbutton.button == Button1)
btn = CEGUI::LeftButton;
else if (evt.xbutton.button == Button2)
btn = CEGUI::RightButton;
else
break;
CEGUI::System::getSingleton().getDefaultGUIContext().injectMouseButtonUp(btn);
break;
}
}
}
glClear(GL_COLOR_BUFFER_BIT);
CEGUI::System::getSingleton().renderAllGUIContexts();
eglSwapBuffers(egldpy, surface);
}
// cleanup
CEGUI::OpenGLESRenderer::destroySystem();
eglMakeCurrent(egldpy, 0, 0, 0);
eglDestroyContext(egldpy, ctx);
eglDestroySurface(egldpy, surface);
eglTerminate(dpy);
eglReleaseThread();
XCloseDisplay(dpy);
return 0;
}
//----------------------------------------------------------------------------//
void initialiseResourceGroupDirectories()
{
// initialise the required dirs for the DefaultResourceProvider
CEGUI::DefaultResourceProvider* rp =
static_cast<CEGUI::DefaultResourceProvider*>
(CEGUI::System::getSingleton().getResourceProvider());
const char* dataPathPrefix = getDataPathPrefix();
char resourcePath[PATH_MAX];
// for each resource type, set a resource group directory
sprintf(resourcePath, "%s/%s", dataPathPrefix, "schemes/");
rp->setResourceGroupDirectory("schemes", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "imagesets/");
rp->setResourceGroupDirectory("imagesets", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "fonts/");
rp->setResourceGroupDirectory("fonts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "layouts/");
rp->setResourceGroupDirectory("layouts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "looknfeel/");
rp->setResourceGroupDirectory("looknfeels", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "lua_scripts/");
rp->setResourceGroupDirectory("lua_scripts", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "xml_schemas/");
rp->setResourceGroupDirectory("schemas", resourcePath);
sprintf(resourcePath, "%s/%s", dataPathPrefix, "animations/");
rp->setResourceGroupDirectory("animations", resourcePath);
}
//----------------------------------------------------------------------------//
void initialiseDefaultResourceGroups()
{
// set the default resource groups to be used
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::AnimationManager::setDefaultResourceGroup("animations");
// setup default group for validation schemas
CEGUI::XMLParser* parser = CEGUI::System::getSingleton().getXMLParser();
if (parser->isPropertyPresent("SchemaDefaultResourceGroup"))
parser->setProperty("SchemaDefaultResourceGroup", "schemas");
}
//----------------------------------------------------------------------------//
const char* getDataPathPrefix()
{
static char dataPathPrefix[PATH_MAX];
char* envDataPath = 0;
// get data path from environment var
envDataPath = getenv(DATAPATH_VAR_NAME);
// set data path prefix / base directory. This will
// be either from an environment variable, or from
// a compiled in default based on original configure
// options
if (envDataPath != 0)
strcpy(dataPathPrefix, envDataPath);
else
strcpy(dataPathPrefix, CEGUI_SAMPLE_DATAPATH);
return dataPathPrefix;
}
//----------------------------------------------------------------------------//
|