//----------------------------------------------------------------------------//
bool CEGuiBaseApplication::execute(SamplesFrameworkBase* sampleApp)
{
    d_sampleApp = sampleApp;

    if (!d_renderer)
        throw CEGUI::InvalidRequestException("CEGuiBaseApplication::run: "
            "Base application subclass did not create Renderer!");

    // start up CEGUI system using objects created in subclass constructor.
    CEGUI::System::create(*d_renderer, d_resourceProvider, 0, d_imageCodec);

    // initialise resource system
    initialiseResourceGroupDirectories();
    initialiseDefaultResourceGroups();

    const CEGUI::Rectf scrn(CEGUI::Vector2f(0, 0), d_renderer->getDisplaySize());

    // setup for FPS value
    d_FPSGeometry = &d_renderer->createGeometryBuffer();
    d_FPSGeometry->setClippingRegion(scrn);
    positionFPS();

    // setup for spinning logo
    d_logoGeometry = &d_renderer->createGeometryBuffer();
    d_logoGeometry->setPivot(CEGUI::Vector3f(91.5f, 44.5f, 0));
    positionLogo();

    // create logo imageset and draw the image (we only ever draw this once)
    CEGUI::ImageManager::getSingleton().addFromImageFile("cegui_logo",
                                                         "logo.png");
    CEGUI::ImageManager::getSingleton().get("cegui_logo").render(
        *d_logoGeometry, CEGUI::Rectf(0, 0, 183, 89), 0, CEGUI::ColourRect(0xFFFFFFFF));

    // clearing this queue actually makes sure it's created(!)
    CEGUI::System::getSingleton().getDefaultGUIContext().clearGeometry(CEGUI::RQ_OVERLAY);

    // subscribe handler to render overlay items
    CEGUI::System::getSingleton().getDefaultGUIContext().
        subscribeEvent(CEGUI::RenderingSurface::EventRenderQueueStarted,
            CEGUI::Event::Subscriber(&CEGuiBaseApplication::sampleBrowserOverlayHandler,
                                     this));

    // subscribe handler to reposition logo when window is sized.
    CEGUI::System::getSingleton().subscribeEvent(
        CEGUI::System::EventDisplaySizeChanged,
        CEGUI::Event::Subscriber(&CEGuiBaseApplication::resizeHandler,
        this));

    const CEGUI::Rectf& area(CEGUI::System::getSingleton().getRenderer()->
                             getDefaultRenderTarget().getArea());
    d_sampleApp->setApplicationWindowSize(static_cast<int>(area.getWidth()),
                                          static_cast<int>(area.getHeight()));

    run();

    cleanup();
    destroyWindow();

    return true;
}
//----------------------------------------------------------------------------//
bool CEGuiBaseApplication::init(SampleBrowserBase* sampleApp,
  const CEGUI::String& logFile, const CEGUI::String& dataPathPrefixOverride)
{
    d_sampleApp = sampleApp;

    if (!d_renderer)
        throw CEGUI::InvalidRequestException("CEGuiBaseApplication::run: "
            "Base application subclass did not create Renderer!");

    // start up CEGUI system using objects created in subclass constructor.
    CEGUI::System::create(*d_renderer, d_resourceProvider, 0, d_imageCodec, 0,
                          "", logFile);

    // initialise resource system
    initialiseResourceGroupDirectories(dataPathPrefixOverride);
    initialiseDefaultResourceGroups();

    const CEGUI::Rectf scrn(glm::vec2(0, 0), d_renderer->getDisplaySize());

    // create logo imageset and draw the image (we only ever draw this once)
    CEGUI::ImageManager::getSingleton().addBitmapImageFromFile("cegui_logo",
                                                         "logo.png");

    CEGUI::Image& ceguiLogo = CEGUI::ImageManager::getSingleton().get("cegui_logo");

    ImageRenderSettings imgRenderSettings(
        CEGUI::Rectf(0, 0, 183, 89));

    auto ceguiLogoGeomBuffers = ceguiLogo.createRenderGeometry(
        imgRenderSettings);

    d_logoGeometry.insert(d_logoGeometry.end(), ceguiLogoGeomBuffers.begin(),
        ceguiLogoGeomBuffers.end());

    // initial position update of the logo
    updateLogoGeometry();
    // setup for spinning logo
    updateLogoGeometryRotation();

    // clearing this queue actually makes sure it's created(!)
    CEGUI::System::getSingleton().getDefaultGUIContext().clearGeometry(CEGUI::RQ_OVERLAY);

    // subscribe handler to render overlay items
    CEGUI::System::getSingleton().getDefaultGUIContext().
        subscribeEvent(CEGUI::RenderingSurface::EventRenderQueueStarted,
            CEGUI::Event::Subscriber(&CEGuiBaseApplication::sampleBrowserOverlayHandler,
                                     this));

    // subscribe handler to reposition logo when window is sized.
    CEGUI::System::getSingleton().subscribeEvent(
        CEGUI::System::EventDisplaySizeChanged,
        CEGUI::Event::Subscriber(&CEGuiBaseApplication::resizeHandler,
        this));

    const CEGUI::Rectf& area(CEGUI::System::getSingleton().getRenderer()->
                             getDefaultRenderTarget().getArea());
    d_sampleApp->setApplicationWindowSize(static_cast<int>(area.getWidth()),
                                          static_cast<int>(area.getHeight()));

    return true;
}
Example #3
0
//----------------------------------------------------------------------------//
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;
}