Mild success, outstanding issues in making CEGUI work on iOS

For help with general CEGUI usage:
- Questions about the usage of CEGUI and its features, if not explained in the documentation.
- Problems with the CMAKE configuration or problems occuring during the build process/compilation.
- Errors or unexpected behaviour.

Moderators: CEGUI MVP, CEGUI Team

cheshirekow
Just popping in
Just popping in
Posts: 8
Joined: Tue Apr 03, 2012 21:36

Mild success, outstanding issues in making CEGUI work on iOS

Postby cheshirekow » Tue Apr 10, 2012 22:01

I'm trying to port a simple game to iOS, and I'm having some trouble getting CEGUI to work. I'm hoping that spending the time get CEGUI to work will be less than spending the time to come up with another GUI Solution.

This is what my game is supposed to look like (linux build): http://youtu.be/rrs_-a_WnZY
This is what it looks like when I run it on the iOS simulator: http://youtu.be/fWp7qRYm3J4

Note there's an unrelated issue in that a LINE_LIST is being interpreted as a LINE_STRIP (i.e. the grid lines are connected by diagonals), so please ignore this when watching the videos.

So it seems that to some extent CEGUI is working on iOS, but there are some problems with the OGRE Renderer. I've been looking at the OGRE Renderer code and I can't seem to figure out what the issue is. It appears as though the render target for CEGUI is a small subset of the Ogre window target. Furthermore, it seems that the camera projection is off (the image is streched and rotated).

My first thought was that perhaps the dimensions of the window target change during the life cycle of the iPhone app and that CEGUI is initialized when it is in a different state then it is during most of the runtime. However, I've tried to adding a call to

Code: Select all

mRenderer->setDefaultRootRenderTarget(*mWindow);


at every frame (just to see if it gets new information into the CEGUI ogre renderer). Note that mRenderer is a CEGUIOgreRenderer and mWindow is an Ogre::RenderWindow which extends Ogre::RenderTarget.

From looking at the code:

CEGUIOgreRenderer.cpp

Code: Select all

//----------------------------------------------------------------------------//
void OgreRenderer::beginRendering()
{
    if ( !d_pimpl->d_previousVP )
    {
        d_pimpl->d_previousVP = d_pimpl->d_renderSystem->_getViewport();
        if ( d_pimpl->d_previousVP && d_pimpl->d_previousVP->getCamera() )
            d_pimpl->d_previousProjMatrix =
                d_pimpl->d_previousVP->getCamera()->getProjectionMatrixRS();
    }

    d_pimpl->d_defaultRoot->getRenderTarget().activate();
    initialiseRenderStateSettings();

    if (d_pimpl->d_makeFrameControlCalls)
        d_pimpl->d_renderSystem->_beginFrame();
}

//----------------------------------------------------------------------------//
void OgreRenderer::endRendering()
{
    if (d_pimpl->d_makeFrameControlCalls)
        d_pimpl->d_renderSystem->_endFrame();

    d_pimpl->d_defaultRoot->getRenderTarget().deactivate();

    if ( d_pimpl->d_previousVP )
    {
        d_pimpl->d_renderSystem->_setViewport(d_pimpl->d_previousVP);
   
        if ( d_pimpl->d_previousVP->getCamera() )
        {
            d_pimpl->d_renderSystem->_setProjectionMatrix(
                d_pimpl->d_previousProjMatrix);
            d_pimpl->d_renderSystem->_setViewMatrix(
                d_pimpl->d_previousVP->getCamera()->getViewMatrix());
        }
        d_pimpl->d_previousVP = 0;
        d_pimpl->d_previousProjMatrix = Ogre::Matrix4::IDENTITY;
    }
}


It appears that the CEGUIOgreRenderer gets a pointer to the viewport from the Ogre::RenderSystem and uses the projection matrix from that to render the images. This seems to me like it should render the CEGUI correctly then since my scene is rendered correctly. Is there anyone who has more experience with the CEGUIOgreRenderer that can point me in the right direction here?

User avatar
Kulik
CEGUI Team
Posts: 1382
Joined: Mon Jul 26, 2010 18:47
Location: Czech Republic
Contact:

Re: Mild success, outstanding issues in making CEGUI work on

Postby Kulik » Wed Apr 11, 2012 08:04

I would try OpenGLES renderer instead and hook it into Ogre's render loop. The issue probably comes from CEGUI Ogre renderer using low level prefixed calls.

cheshirekow
Just popping in
Just popping in
Posts: 8
Joined: Tue Apr 03, 2012 21:36

Re: Mild success, outstanding issues in making CEGUI work on

Postby cheshirekow » Mon Apr 16, 2012 19:35

Ok, it took a while but I finally got the current mercurial branch to build for iOS and the simulator. In order to understand how to use the OpenGLES renderer correctly, I'm attempting to replicate Demo6, but I'm having some trouble.

I figured the easiest thing to do was start with the apple iOS openGL application template, so that's what I've done. The template is a simple application which draws a cube once using OpenGLES and then again using OpenGLES2 shaders. The camera is animated to rotate around the cubes.

There's a class called "ViewController" which I figure is the appropriate place to tap into. It has a method called setupGL where it defines the geometry for the cube. I added to the class a member variable which is an instance of my DemoApplication class. Then when the ViewController initializes openGL, I initialize CEGUI. (It is my intent that when the ViewController update's, I will also update the demo application, but I haven't gotten there yet).

This approach not seem to work correctly as it leads to "GL ERROR: 0x0502" being printed to the console during the following line of objective c code (Apple internal API, I wish I knew what all it did... but I can guess based on normal opengl render loops).

In any case, if I initialize CEGUI here, the cube does not draw anymore (and all I see is a gray background). Any idea where the appropriate place to initialize CEGUI would be using this GLES template?

Code: Select all

// Render the object with GLKit
    [self.effect prepareToDraw];


Ok here is my DemoCode:

DemoApplication.h

Code: Select all

//
//  DemoApplication.h
//  CEGUIDemo6
//
//  Created by Josh  Bialkowski on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#ifndef CEGUIDemo6_DemoApplication_h
#define CEGUIDemo6_DemoApplication_h

#include "CEGUI/CEGUI.h"

class DemoApplication
{
    public:
        DemoApplication();
        ~DemoApplication();
   
        void initCEGUI();
        void destroyCEGUI();
        void update(float tpf);
   
protected:
    void initialiseResourceGroupDirectories();
    void initialiseDefaultResourceGroups();
   
    bool initialiseSample();
   
    // helper methods
    void createDemoWindows(CEGUI::Window* root);
    void initDemoEventWiring(CEGUI::Window* root);
   
    // event handlers
    bool handleQuit(const CEGUI::EventArgs& e);
    bool handleAddColumn(const CEGUI::EventArgs& e);
    bool handleDeleteColumn(const CEGUI::EventArgs& e);
    bool handleAddRow(const CEGUI::EventArgs& e);
    bool handleDeleteRow(const CEGUI::EventArgs& e);
    bool handleSetItem(const CEGUI::EventArgs& e);
    bool handleSelectChanged(const CEGUI::EventArgs& e);
    bool handleSelectModeChanged(const CEGUI::EventArgs& e);
    bool handleContentsChanged(const CEGUI::EventArgs& e);
};



#endif



DemoApplication.cpp

Code: Select all

//
//  DemoApplication.cpp
//  CEGUIDemo6
//
//  Created by Josh  Bialkowski on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#include <iostream>
#include "DemoApplication.h"
#include "CEGUIDummyLogger.h"
#include "CEGUI/CEGUI.h"
#include "CEGUI/RendererModules/OpenGLES/Renderer.h"

DemoApplication::DemoApplication()
{
   
}


DemoApplication::~DemoApplication()
{
   
}




void DemoApplication::initCEGUI()
{
    CEGUI::DummyLogger* logger = new CEGUI::DummyLogger();
   
    CEGUI::Sizef size(768,1024);
   
    CEGUI::OpenGLESRenderer::bootstrapSystem(size);
    initialiseResourceGroupDirectories();
    initialiseDefaultResourceGroups();
    initialiseSample();
    std::cerr << "Finished initializing CEGUI" << std::endl;
}



void DemoApplication::initialiseResourceGroupDirectories()
{
    std::cerr << "initializing resource groups" << std::endl;

    // initialise the required dirs for the DefaultResourceProvider
    CEGUI::DefaultResourceProvider* rp =
        static_cast<CEGUI::DefaultResourceProvider*>
            (CEGUI::System::getSingleton().getResourceProvider());

    const char* dataPathPrefix = "/Users/josh/dev/root/iPhoneSimulator/usr/share/CEGUI";
    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);   
   
   
    /*
    rp->setResourceGroupDirectory("schemes",        "media/schemes");
    rp->setResourceGroupDirectory("imagesets",      "media/imagesets");
    rp->setResourceGroupDirectory("fonts",          "media/fonts");
    rp->setResourceGroupDirectory("layouts",        "media/layouts");
    rp->setResourceGroupDirectory("looknfeels",     "media/looknfeel");
    rp->setResourceGroupDirectory("lua_scripts",    "media/lua_scripts");
    rp->setResourceGroupDirectory("schemas",        "media/xml_schemas");
    rp->setResourceGroupDirectory("animations",     "media/animations");
    */
   
   
}


void DemoApplication::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");
}



void DemoApplication::destroyCEGUI()
{
   
}



void DemoApplication::update(float tpf)
{
    CEGUI::System::getSingleton().renderAllGUIContexts();
}




bool DemoApplication::initialiseSample()
{
    std::cerr << "initializing sample" << std::endl;

    using namespace CEGUI;
   
    // we will use of the WindowManager.
    WindowManager& winMgr = WindowManager::getSingleton();
   
    // load scheme and set up defaults
    SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
    System::getSingleton().getDefaultGUIContext().getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
    FontManager::getSingleton().createFromFile("DejaVuSans-10.font");
   
    // load an image to use as a background
    ImageManager::getSingleton().addFromImageFile("BackgroundImage", "GPN-2000-001437.png");
   
    // here we will use a StaticImage as the root, then we can use it to place a background image
    Window* background = winMgr.createWindow("TaharezLook/StaticImage", "root_wnd");
    // set position and size
    background->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
    background->setSize(USize(cegui_reldim(1), cegui_reldim( 1)));
    // disable frame and standard background
    background->setProperty("FrameEnabled", "false");
    background->setProperty("BackgroundEnabled", "false");
    // set the background image
    background->setProperty("Image", "BackgroundImage");
    // install this as the root GUI sheet
    System::getSingleton().getDefaultGUIContext().setRootWindow(background);
   
    // do demo stuff
    createDemoWindows(background);
    initDemoEventWiring(background);
   
    // success!
    return true;
}



/*************************************************************************
 Create the windows and widgets for the demo
 *************************************************************************/
void DemoApplication::createDemoWindows(CEGUI::Window* root)
{
    using namespace CEGUI;
    ListboxTextItem* itm;
   
    WindowManager& winMgr = WindowManager::getSingleton();
   
    // create the main list.
    MultiColumnList* mcl = static_cast<MultiColumnList*>(winMgr.createWindow("TaharezLook/MultiColumnList", "MainList"));
    root->addChild(mcl);
    mcl->setPosition(UVector2(cegui_reldim(0.01f), cegui_reldim( 0.1f)));
    mcl->setSize(USize(cegui_reldim(0.5f), cegui_reldim( 0.8f)));
   
    // create frame window for control panel
    FrameWindow* fwnd = static_cast<FrameWindow*>(winMgr.createWindow("TaharezLook/FrameWindow", "ControlPanel"));
    root->addChild(fwnd);
    fwnd->setPosition(UVector2(cegui_reldim(0.53f), cegui_reldim( 0.03f)));
    fwnd->setMaxSize(USize(cegui_reldim(1.0f), cegui_reldim( 1.0f)));
    fwnd->setSize(USize(cegui_reldim(0.44f), cegui_reldim( 0.94f)));
    fwnd->setText("Demo 6 - Control Panel");
   
    // create combo-box.
    Combobox* cbbo = static_cast<Combobox*>(winMgr.createWindow("TaharezLook/Combobox", "SelModeBox"));
    fwnd->addChild(cbbo);
    cbbo->setPosition(UVector2(cegui_reldim(0.04f), cegui_reldim( 0.06f)));
    cbbo->setSize(USize(cegui_reldim(0.66f), cegui_reldim( 0.33f)));
    //cbbo->setSortingEnabled(true);
   
    // populate combobox with possible selection modes
    const CEGUI::Image* sel_img = &ImageManager::getSingleton().get("TaharezLook/MultiListSelectionBrush");
    itm = new ListboxTextItem("Full Row (Single)", 0);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Row (Multiple)", 1);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Column (Single)", 2);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Full Column (Multiple)", 3);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Single Cell (Single)", 4);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Single Cell (Multiple)", 5);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Column (Single)", 6);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Column (Multiple)", 7);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    ListboxTextItem* pStore = itm;
    itm = new ListboxTextItem("Nominated Row (Single)", 8);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    itm = new ListboxTextItem("Nominated Row (Multiple)", 9);
    itm->setSelectionBrushImage(sel_img);
    cbbo->addItem(itm);
    cbbo->setReadOnly(true);
    // Now change the text to test the sorting
    pStore->setText("Abracadabra");
    //cbbo->setSortingEnabled(false);
    cbbo->setSortingEnabled(true);
    //cbbo->handleUpdatedListItemData();
   
    // column control section
    Window* st = winMgr.createWindow("TaharezLook/StaticText", "ColumnPanel");
    fwnd->addChild(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.12f)));
    st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Column Control");
    st->setProperty("VertFormatting", "TopAligned");
   
    Window* label = winMgr.createWindow("TaharezLook/StaticText", "Label1");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("ID Code:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label2");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Width:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label3");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Caption:");
   
    PushButton* btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "AddColButton"));
    st->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Add");
   
    Editbox* ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColIDBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
    ebox->setText("Test -- ");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColWidthBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "NewColTextBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
    //ebox->setValidationString(".*");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label4");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("ID Code:");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "DelColIDBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "DelColButton"));
    st->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
    btn->setSize(USize(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
    btn->setText("Delete Column");
   
    // Row control box
    st = winMgr.createWindow("TaharezLook/StaticText", "RowControl");
    fwnd->addChild(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.38f)));
    st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Row Control");
    st->setProperty("VertFormatting", "TopAligned");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label5");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Col ID:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label6");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.55f), cegui_reldim( 0.12f)));
    label->setText("Item Text:");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "RowColIDBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "RowTextBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.55f), cegui_reldim( 0.2f)));
    //ebox->setValidationString(".*");
   
    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "AddRowButton"));
    st->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Add");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label7");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Row Idx:");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "DelRowIdxBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "DelRowButton"));
    st->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.67f)));
    btn->setSize(USize(cegui_reldim(0.4f), cegui_reldim( 0.2f)));
    btn->setText("Delete Row");
   
    // set item box
    st = winMgr.createWindow("TaharezLook/StaticText", "SetItemPanel");
    fwnd->addChild(st);
    st->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.65f)));
    st->setSize(USize(cegui_reldim(0.96f), cegui_reldim( 0.25f)));
    st->setText("Item Modification");
    st->setProperty("VertFormatting", "TopAligned");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label8");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Row Idx:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label9");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Col ID:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "Label10");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.2f)));
    label->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.12f)));
    label->setText("Item Text:");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemRowBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemIDBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.23f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.2f), cegui_reldim( 0.2f)));
    //ebox->setValidationString("\\d*");
   
    ebox = static_cast<Editbox*>(winMgr.createWindow("TaharezLook/Editbox", "SetItemTextBox"));
    st->addChild(ebox);
    ebox->setPosition(UVector2(cegui_reldim(0.44f), cegui_reldim( 0.32f)));
    ebox->setSize(USize(cegui_reldim(0.36f), cegui_reldim( 0.2f)));
    //ebox->setValidationString(".*");
   
    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "SetItemButton"));
    st->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.81f), cegui_reldim( 0.32f)));
    btn->setSize(USize(cegui_reldim(0.15f), cegui_reldim( 0.2f)));
    btn->setText("Set");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "RowCount");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.55f)));
    label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Row Count:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "ColCount");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.67f)));
    label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Column Count:");
   
    label = winMgr.createWindow("TaharezLook/StaticText", "SelCount");
    st->addChild(label);
    label->setProperty("FrameEnabled", "false");
    label->setProperty("BackgroundEnabled", "false");
    label->setPosition(UVector2(cegui_reldim(0.02f), cegui_reldim( 0.79f)));
    label->setSize(USize(cegui_reldim(1.0f), cegui_reldim( 0.12f)));
    label->setText("Current Selected Count:");
   
    btn = static_cast<PushButton*>(winMgr.createWindow("TaharezLook/Button", "QuitButton"));
    fwnd->addChild(btn);
    btn->setPosition(UVector2(cegui_reldim(0.25f), cegui_reldim( 0.93f)));
    btn->setSize(USize(cegui_reldim(0.50f), cegui_reldim( 0.05f)));
    btn->setText("Quit This Demo!");
}


void DemoApplication::initDemoEventWiring(CEGUI::Window* root)
{
    using namespace CEGUI;
   
    // subscribe handler that adds a new column
    root->getChild("ControlPanel/ColumnPanel/AddColButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleAddColumn, this));
   
    // subscribe handler that deletes a column
    root->getChild("ControlPanel/ColumnPanel/DelColButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleDeleteColumn, this));
   
    // subscribe handler that adds a new row
    root->getChild("ControlPanel/RowControl/AddRowButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleAddRow, this));
   
    // subscribe handler that deletes a row
    root->getChild("ControlPanel/RowControl/DelRowButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleDeleteRow, this));
   
    // subscribe handler that sets the text for an existing item
    root->getChild("ControlPanel/SetItemPanel/SetItemButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleSetItem, this));
   
    // subscribe handler that quits the application
    root->getChild("ControlPanel/QuitButton")->
    subscribeEvent(PushButton::EventClicked, Event::Subscriber(&DemoApplication::handleQuit, this));
   
    // subscribe handler that processes a change in the 'selection mode' combobox
    root->getChild("ControlPanel/SelModeBox")->
    subscribeEvent(Combobox::EventListSelectionAccepted, Event::Subscriber(&DemoApplication::handleSelectModeChanged, this));
   
    // subscribe handler that processes a change in the item(s) selected in the list
    root->getChild("MainList")->
    subscribeEvent(MultiColumnList::EventSelectionChanged, Event::Subscriber(&DemoApplication::handleSelectChanged, this));
   
    // subscribe handler that processes a change in the list content.
    root->getChild("MainList")->
    subscribeEvent(MultiColumnList::EventListContentsChanged, Event::Subscriber(&DemoApplication::handleContentsChanged, this));
}

bool DemoApplication::handleQuit(const CEGUI::EventArgs&)
{
    // event was handled
    return true;
}

bool DemoApplication::handleAddColumn(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to the widgets that contain details about the column to add
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColIDBox"));
    Editbox* widthbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColWidthBox"));
    Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/NewColTextBox"));
   
    // get ID for new column
    CEGUI::uint id = atoi(idbox->getText().c_str());
    // get width to use for new column (in pixels)
    float width = atof(widthbox->getText().c_str());
    // get column label text
    String text = textbox->getText();
   
    // re-set the widget contents
    idbox->setText("");
    widthbox->setText("");
    textbox->setText("");
   
    // ensure a minimum width of 10 pixels
    if (width < 10.0f)
        width = 10.0f;
   
    // finally, add the new column to the list.
    mcl->addColumn(text, id, cegui_absdim(width));
   
    // event was handled.
    return true;
}

bool DemoApplication::handleDeleteColumn(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to the widgets that contain details about the column to delete
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/ColumnPanel/DelColIDBox"));
   
    // obtain the id of the column to be deleted
    CEGUI::uint id = atoi(idbox->getText().c_str());
   
    // attempt to delete the column, ignoring any errors.
    CEGUI_TRY
    {
        mcl->removeColumnWithID(id);
    }
    CEGUI_CATCH (InvalidRequestException)
    {}
   
    // reset the delete column ID box.
    idbox->setText("");
   
    // event was handled.
    return true;
}

bool DemoApplication::handleAddRow(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to the widgets that contain details about the row to add
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/RowColIDBox"));
    Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/RowTextBox"));
   
    // get the ID of the initial column item to set
    CEGUI::uint id = atoi(idbox->getText().c_str());
    // get the text that is to be set initially into the specified column of the new row
    String text = textbox->getText();
   
    // reset input boxes
    idbox->setText("");
    textbox->setText("");
   
    // construct a new ListboxTextItem with the required string
    ListboxTextItem* item = new ListboxTextItem(text);
    // set the selection brush to use for this item.
    item->setSelectionBrushImage("TaharezLook/MultiListSelectionBrush");
   
    // attempt to add a new row, using the new ListboxTextItem as the initial content for one of the columns
    CEGUI_TRY
    {
        mcl->addRow(item, id);
    }
    // something went wrong, so cleanup the ListboxTextItem
    CEGUI_CATCH (InvalidRequestException)
    {
        delete item;
    }
   
    // event was handled.
    return true;
}

bool DemoApplication::handleDeleteRow(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to the widgets that contain details about the row to delete.
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Editbox* idxbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/RowControl/DelRowIdxBox"));
   
    // get index of row to delete.
    CEGUI::uint idx = atoi(idxbox->getText().c_str());
   
    // attempt to delete the row, ignoring any errors.
    CEGUI_TRY
    {
        mcl->removeRow(idx);
    }
    CEGUI_CATCH (InvalidRequestException)
    {}
   
    // clear the row index box
    idxbox->setText("");
   
    // event was handled.
    return true;
}

bool DemoApplication::handleSetItem(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to the widgets that contain details about the item to be modified
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Editbox* idbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemIDBox"));
    Editbox* rowbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemRowBox"));
    Editbox* textbox = static_cast<Editbox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SetItemTextBox"));
   
    // get ID of column to be affected
    CEGUI::uint id = atoi(idbox->getText().c_str());
    // get index of row to be affected
    CEGUI::uint row = atoi(rowbox->getText().c_str());
    // get new text for item
    String text = textbox->getText();
   
    // reset input boxes
    idbox->setText("");
    rowbox->setText("");
    textbox->setText("");
   
    // create a new ListboxTextItem using the new text string
    ListboxTextItem* item = new ListboxTextItem(text);
    // set the selection brush to be used for this item.
    item->setSelectionBrushImage("TaharezLook/MultiListSelectionBrush");
   
    // attempt to set the new item in place
    CEGUI_TRY
    {
        mcl->setItem(item, id, row);
    }
    // something went wrong, so cleanup the ListboxTextItem.
    CEGUI_CATCH (InvalidRequestException)
    {
        delete item;
    }
   
    // event was handled.
    return true;
}

bool DemoApplication::handleSelectChanged(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // Get access to the list
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
   
    // update the selected count
    std::string tmp("Current Selected Count: ");
   
    char buff[16];
    sprintf(buff, "%d", mcl->getSelectedCount());
   
    tmp += buff;
   
    static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/SelCount")->setText(tmp);
   
    // event was handled.
    return true;
}

bool DemoApplication::handleSelectModeChanged(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to list
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    // get access to the combobox
    Combobox* combo = static_cast<Combobox*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SelModeBox"));
   
    // find the selected item in the combobox
    ListboxItem* item = combo->findItemWithText(combo->getText(), 0);
   
    // set new selection mode according to ID of selected ListboxItem
    if (item)
    {
        switch (item->getID())
        {
            case 0:
                mcl->setSelectionMode(MultiColumnList::RowSingle);
                break;
               
            case 1:
                mcl->setSelectionMode(MultiColumnList::RowMultiple);
                break;
               
            case 2:
                mcl->setSelectionMode(MultiColumnList::ColumnSingle);
                break;
               
            case 3:
                mcl->setSelectionMode(MultiColumnList::ColumnMultiple);
                break;
               
            case 4:
                mcl->setSelectionMode(MultiColumnList::CellSingle);
                break;
               
            case 5:
                mcl->setSelectionMode(MultiColumnList::CellMultiple);
                break;
               
            case 6:
                mcl->setSelectionMode(MultiColumnList::NominatedColumnSingle);
                break;
               
            case 7:
                mcl->setSelectionMode(MultiColumnList::NominatedColumnMultiple);
                break;
               
            case 8:
                mcl->setSelectionMode(MultiColumnList::NominatedRowSingle);
                break;
               
            case 9:
                mcl->setSelectionMode(MultiColumnList::NominatedRowMultiple);
                break;
               
            default:
                mcl->setSelectionMode(MultiColumnList::RowSingle);
                break;
               
        }
    }
   
    // event was handled.
    return true;
}

bool DemoApplication::handleContentsChanged(const CEGUI::EventArgs& args)
{
    using namespace CEGUI;
   
    // get access to required widgets
    MultiColumnList* mcl = static_cast<MultiColumnList*>(static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("MainList"));
    Window* colText = static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/ColCount");
    Window* rowText = static_cast<const WindowEventArgs&>(args).window->getRootWindow()->getChild("ControlPanel/SetItemPanel/RowCount");
   
    std::string tmp;
    char buff[16];
   
    // update the column count
    tmp = "Current Column Count: ";
    sprintf(buff, "%d", mcl->getColumnCount());
    tmp += buff;
    colText->setText(tmp);
   
    // update the row count
    tmp = "Current Row Count: ";
    sprintf(buff, "%d", mcl->getRowCount());
    tmp += buff;
    rowText->setText(tmp);
   
    // event was handled.
    return true;
}



ViewController.h

Code: Select all

//
//  ViewController.h
//  CEGUIDemo6
//
//  Created by Josh  Bialkowski on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <GLKit/GLKit.h>

@interface ViewController : GLKViewController

@end



ViewController.mm

Code: Select all

//
//  ViewController.m
//  CEGUIDemo6
//
//  Created by Josh  Bialkowski on 4/16/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"
#import "DemoApplication.h"
#include <iostream>

#define BUFFER_OFFSET(i) ((char *)NULL + (i))

// Uniform index.
enum
{
    UNIFORM_MODELVIEWPROJECTION_MATRIX,
    UNIFORM_NORMAL_MATRIX,
    NUM_UNIFORMS
};
GLint uniforms[NUM_UNIFORMS];

// Attribute index.
enum
{
    ATTRIB_VERTEX,
    ATTRIB_NORMAL,
    NUM_ATTRIBUTES
};

GLfloat gCubeVertexData[216] =
{
    // Data layout for each line below is:
    // positionX, positionY, positionZ,     normalX, normalY, normalZ,
    0.5f, -0.5f, -0.5f,        1.0f, 0.0f, 0.0f,
    0.5f, 0.5f, -0.5f,         1.0f, 0.0f, 0.0f,
    0.5f, -0.5f, 0.5f,         1.0f, 0.0f, 0.0f,
    0.5f, -0.5f, 0.5f,         1.0f, 0.0f, 0.0f,
    0.5f, 0.5f, -0.5f,          1.0f, 0.0f, 0.0f,
    0.5f, 0.5f, 0.5f,         1.0f, 0.0f, 0.0f,
   
    0.5f, 0.5f, -0.5f,         0.0f, 1.0f, 0.0f,
    -0.5f, 0.5f, -0.5f,        0.0f, 1.0f, 0.0f,
    0.5f, 0.5f, 0.5f,          0.0f, 1.0f, 0.0f,
    0.5f, 0.5f, 0.5f,          0.0f, 1.0f, 0.0f,
    -0.5f, 0.5f, -0.5f,        0.0f, 1.0f, 0.0f,
    -0.5f, 0.5f, 0.5f,         0.0f, 1.0f, 0.0f,
   
    -0.5f, 0.5f, -0.5f,        -1.0f, 0.0f, 0.0f,
    -0.5f, -0.5f, -0.5f,       -1.0f, 0.0f, 0.0f,
    -0.5f, 0.5f, 0.5f,         -1.0f, 0.0f, 0.0f,
    -0.5f, 0.5f, 0.5f,         -1.0f, 0.0f, 0.0f,
    -0.5f, -0.5f, -0.5f,       -1.0f, 0.0f, 0.0f,
    -0.5f, -0.5f, 0.5f,        -1.0f, 0.0f, 0.0f,
   
    -0.5f, -0.5f, -0.5f,       0.0f, -1.0f, 0.0f,
    0.5f, -0.5f, -0.5f,        0.0f, -1.0f, 0.0f,
    -0.5f, -0.5f, 0.5f,        0.0f, -1.0f, 0.0f,
    -0.5f, -0.5f, 0.5f,        0.0f, -1.0f, 0.0f,
    0.5f, -0.5f, -0.5f,        0.0f, -1.0f, 0.0f,
    0.5f, -0.5f, 0.5f,         0.0f, -1.0f, 0.0f,
   
    0.5f, 0.5f, 0.5f,          0.0f, 0.0f, 1.0f,
    -0.5f, 0.5f, 0.5f,         0.0f, 0.0f, 1.0f,
    0.5f, -0.5f, 0.5f,         0.0f, 0.0f, 1.0f,
    0.5f, -0.5f, 0.5f,         0.0f, 0.0f, 1.0f,
    -0.5f, 0.5f, 0.5f,         0.0f, 0.0f, 1.0f,
    -0.5f, -0.5f, 0.5f,        0.0f, 0.0f, 1.0f,
   
    0.5f, -0.5f, -0.5f,        0.0f, 0.0f, -1.0f,
    -0.5f, -0.5f, -0.5f,       0.0f, 0.0f, -1.0f,
    0.5f, 0.5f, -0.5f,         0.0f, 0.0f, -1.0f,
    0.5f, 0.5f, -0.5f,         0.0f, 0.0f, -1.0f,
    -0.5f, -0.5f, -0.5f,       0.0f, 0.0f, -1.0f,
    -0.5f, 0.5f, -0.5f,        0.0f, 0.0f, -1.0f
};

@interface ViewController () {
    GLuint _program;
   
    GLKMatrix4 _modelViewProjectionMatrix;
    GLKMatrix3 _normalMatrix;
    float _rotation;
   
    GLuint _vertexArray;
    GLuint _vertexBuffer;
   
    DemoApplication app;
}
@property (strong, nonatomic) EAGLContext *context;
@property (strong, nonatomic) GLKBaseEffect *effect;

- (void)setupGL;
- (void)tearDownGL;

- (BOOL)loadShaders;
- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file;
- (BOOL)linkProgram:(GLuint)prog;
- (BOOL)validateProgram:(GLuint)prog;
@end

@implementation ViewController

@synthesize context = _context;
@synthesize effect = _effect;

- (void)viewDidLoad
{
    [super viewDidLoad];
   
    self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];

    if (!self.context) {
        NSLog(@"Failed to create ES context");
    }
   
    GLKView *view = (GLKView *)self.view;
    view.context = self.context;
    view.drawableDepthFormat = GLKViewDrawableDepthFormat24;
   
    [self setupGL];
}

- (void)viewDidUnload
{   
    [super viewDidUnload];
   
    [self tearDownGL];
   
    if ([EAGLContext currentContext] == self.context) {
        [EAGLContext setCurrentContext:nil];
    }
   self.context = nil;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc. that aren't in use.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}

- (void)setupGL
{
    [EAGLContext setCurrentContext:self.context];
       
    [self loadShaders];

   
    self.effect = [[GLKBaseEffect alloc] init];
    self.effect.light0.enabled = GL_TRUE;
    self.effect.light0.diffuseColor = GLKVector4Make(1.0f, 0.4f, 0.4f, 1.0f);

   
    glEnable(GL_DEPTH_TEST);
   
    glGenVertexArraysOES(1, &_vertexArray);
    glBindVertexArrayOES(_vertexArray);
   

    glGenBuffers(1, &_vertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(gCubeVertexData), gCubeVertexData, GL_STATIC_DRAW);
   

    glEnableVertexAttribArray(GLKVertexAttribPosition);
    glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0));
    glEnableVertexAttribArray(GLKVertexAttribNormal);
    glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12));
   

    glBindVertexArrayOES(0);
   
    //----------NOTE CEGUI INITIALIZATION HERE----------
    app.initCEGUI();
   
}

- (void)tearDownGL
{
    //app.destroyCEGUI();
   
    [EAGLContext setCurrentContext:self.context];
   
    glDeleteBuffers(1, &_vertexBuffer);
    glDeleteVertexArraysOES(1, &_vertexArray);
   
    self.effect = nil;
   
    if (_program) {
        glDeleteProgram(_program);
        _program = 0;
    }
}

#pragma mark - GLKView and GLKViewController delegate methods

- (void)update
{


    float aspect = fabsf(self.view.bounds.size.width / self.view.bounds.size.height);
    GLKMatrix4 projectionMatrix = GLKMatrix4MakePerspective(GLKMathDegreesToRadians(65.0f), aspect, 0.1f, 100.0f);
   
    self.effect.transform.projectionMatrix = projectionMatrix;
   
    GLKMatrix4 baseModelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -4.0f);
    baseModelViewMatrix = GLKMatrix4Rotate(baseModelViewMatrix, _rotation, 0.0f, 1.0f, 0.0f);
   
    // Compute the model view matrix for the object rendered with GLKit
    GLKMatrix4 modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, -1.5f);
    modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f);
    modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);


    self.effect.transform.modelviewMatrix = modelViewMatrix;
   
    // Compute the model view matrix for the object rendered with ES2
    modelViewMatrix = GLKMatrix4MakeTranslation(0.0f, 0.0f, 1.5f);
    modelViewMatrix = GLKMatrix4Rotate(modelViewMatrix, _rotation, 1.0f, 1.0f, 1.0f);
    modelViewMatrix = GLKMatrix4Multiply(baseModelViewMatrix, modelViewMatrix);
   

    _normalMatrix = GLKMatrix3InvertAndTranspose(GLKMatrix4GetMatrix3(modelViewMatrix), NULL);
   
    _modelViewProjectionMatrix = GLKMatrix4Multiply(projectionMatrix, modelViewMatrix);
   
    _rotation += self.timeSinceLastUpdate * 0.5f;
   

    //app.update(self.timeSinceLastUpdate);
}

- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect
{
 
    glClearColor(0.65f, 0.65f, 0.65f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
    glBindVertexArrayOES(_vertexArray);

    // Render the object with GLKit
    [self.effect prepareToDraw];

    glDrawArrays(GL_TRIANGLES, 0, 36);
   

    // Render the object again with ES2
    /*
    glUseProgram(_program);
   
    glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m);
    glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m);
   
    glDrawArrays(GL_TRIANGLES, 0, 36);
    */
}

#pragma mark -  OpenGL ES 2 shader compilation

- (BOOL)loadShaders
{
    GLuint vertShader, fragShader;
    NSString *vertShaderPathname, *fragShaderPathname;
   
    // Create shader program.
    _program = glCreateProgram();
   
    // Create and compile vertex shader.
    vertShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"vsh"];
    if (![self compileShader:&vertShader type:GL_VERTEX_SHADER file:vertShaderPathname]) {
        NSLog(@"Failed to compile vertex shader");
        return NO;
    }
   
    // Create and compile fragment shader.
    fragShaderPathname = [[NSBundle mainBundle] pathForResource:@"Shader" ofType:@"fsh"];
    if (![self compileShader:&fragShader type:GL_FRAGMENT_SHADER file:fragShaderPathname]) {
        NSLog(@"Failed to compile fragment shader");
        return NO;
    }
   
    // Attach vertex shader to program.
    glAttachShader(_program, vertShader);
   
    // Attach fragment shader to program.
    glAttachShader(_program, fragShader);
   
    // Bind attribute locations.
    // This needs to be done prior to linking.
    glBindAttribLocation(_program, ATTRIB_VERTEX, "position");
    glBindAttribLocation(_program, ATTRIB_NORMAL, "normal");
   
    // Link program.
    if (![self linkProgram:_program]) {
        NSLog(@"Failed to link program: %d", _program);
       
        if (vertShader) {
            glDeleteShader(vertShader);
            vertShader = 0;
        }
        if (fragShader) {
            glDeleteShader(fragShader);
            fragShader = 0;
        }
        if (_program) {
            glDeleteProgram(_program);
            _program = 0;
        }
       
        return NO;
    }
   
    // Get uniform locations.
    uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX] = glGetUniformLocation(_program, "modelViewProjectionMatrix");
    uniforms[UNIFORM_NORMAL_MATRIX] = glGetUniformLocation(_program, "normalMatrix");
   
    // Release vertex and fragment shaders.
    if (vertShader) {
        glDetachShader(_program, vertShader);
        glDeleteShader(vertShader);
    }
    if (fragShader) {
        glDetachShader(_program, fragShader);
        glDeleteShader(fragShader);
    }
   
    return YES;
}

- (BOOL)compileShader:(GLuint *)shader type:(GLenum)type file:(NSString *)file
{
    GLint status;
    const GLchar *source;
   
    source = (GLchar *)[[NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil] UTF8String];
    if (!source) {
        NSLog(@"Failed to load vertex shader");
        return NO;
    }
   
    *shader = glCreateShader(type);
    glShaderSource(*shader, 1, &source, NULL);
    glCompileShader(*shader);
   
#if defined(DEBUG)
    GLint logLength;
    glGetShaderiv(*shader, GL_INFO_LOG_LENGTH, &logLength);
    if (logLength > 0) {
        GLchar *log = (GLchar *)malloc(logLength);
        glGetShaderInfoLog(*shader, logLength, &logLength, log);
        NSLog(@"Shader compile log:\n%s", log);
        free(log);
    }
#endif
   
    glGetShaderiv(*shader, GL_COMPILE_STATUS, &status);
    if (status == 0) {
        glDeleteShader(*shader);
        return NO;
    }
   
    return YES;
}

- (BOOL)linkProgram:(GLuint)prog
{
    GLint status;
    glLinkProgram(prog);
   
#if defined(DEBUG)
    GLint logLength;
    glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
    if (logLength > 0) {
        GLchar *log = (GLchar *)malloc(logLength);
        glGetProgramInfoLog(prog, logLength, &logLength, log);
        NSLog(@"Program link log:\n%s", log);
        free(log);
    }
#endif
   
    glGetProgramiv(prog, GL_LINK_STATUS, &status);
    if (status == 0) {
        return NO;
    }
   
    return YES;
}

- (BOOL)validateProgram:(GLuint)prog
{
    GLint logLength, status;
   
    glValidateProgram(prog);
    glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &logLength);
    if (logLength > 0) {
        GLchar *log = (GLchar *)malloc(logLength);
        glGetProgramInfoLog(prog, logLength, &logLength, log);
        NSLog(@"Program validate log:\n%s", log);
        free(log);
    }
   
    glGetProgramiv(prog, GL_VALIDATE_STATUS, &status);
    if (status == 0) {
        return NO;
    }
   
    return YES;
}

@end


And finally my error log

Code: Select all

********************************************************************************
* Important:                                                                   *
*     To get support at the CEGUI forums, you must post _at least_ the section *
*     of this log file indicated below.  Failure to do this will result in no  *
*     support being given; please do not waste our time.                       *
********************************************************************************
********************************************************************************
* -------- START OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM       -------- *
********************************************************************************
---- Version: 9999.0.0 (Build: Apr 16 2012 Static Debug Apple Mac g++ 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.9.00) 32 bit) ----
---- Renderer module is: CEGUI::OpenGLESRenderer - Official OpenGLES based 2nd generation renderer module.  TextureTarget support is not available :( ----
---- XML Parser module is: CEGUI::TinyXMLParser - Official tinyXML based parser module for CEGUI ----
---- Image Codec module is: FreeImageCodec - FreeImage based image codec ----
---- Scripting module is: None ----
********************************************************************************
* -------- END OF ESSENTIAL SECTION TO BE POSTED ON THE FORUM         -------- *
********************************************************************************

---- Begining CEGUI System initialisation ----
[CEGUI::ImageManager] Singleton created (0x7b276b0)
[CEGUI::ImageManager] Registered Image type: BasicImage
CEGUI::FontManager singleton created. (0x7b27f50)
CEGUI::WindowFactoryManager singleton created
CEGUI::WindowManager singleton created (0x7e69a50)
CEGUI::SchemeManager singleton created. (0x7e69a90)
CEGUI::GlobalEventSet singleton created. (0x7e699a0)
CEGUI::AnimationManager singleton created (0x7e699c0)
CEGUI::WidgetLookManager singleton created. (0x7d3aab0)
CEGUI::WindowRendererManager singleton created (0x7d3ab10)
CEGUI::RenderEffectManager singleton created (0x7d3be70)
Created WindowFactory for 'DefaultWindow' windows.
WindowFactory for 'DefaultWindow' windows added. (0x7d3c510)
Created WindowFactory for 'DragContainer' windows.
WindowFactory for 'DragContainer' windows added. (0x7d3c6f0)
Created WindowFactory for 'ScrolledContainer' windows.
WindowFactory for 'ScrolledContainer' windows added. (0x7d3c840)
Created WindowFactory for 'ClippedContainer' windows.
WindowFactory for 'ClippedContainer' windows added. (0x7d3c8e0)
Created WindowFactory for 'CEGUI/PushButton' windows.
WindowFactory for 'CEGUI/PushButton' windows added. (0x7d3cb00)
Created WindowFactory for 'CEGUI/RadioButton' windows.
WindowFactory for 'CEGUI/RadioButton' windows added. (0x7939a30)

      ---- snip ----


WindowFactory for 'VerticalLayoutContainer' windows added. (0x793c5b0)
Created WindowFactory for 'GridLayoutContainer' windows.
WindowFactory for 'GridLayoutContainer' windows added. (0x793c700)
CEGUI::System singleton created. (0x7b270c0)
---- CEGUI System initialisation completed ----

initializing resource groups
initializing sample
Started creation of Scheme from XML specification:
---- CEGUI GUIScheme name: TaharezLook
Finished creation of GUIScheme 'TaharezLook' via XML file. (0x7d3ccf0)
---- Begining resource loading for GUI scheme 'TaharezLook' ----
[ImageManager] Started creation of Imageset from XML specification:
[ImageManager] ---- CEGUI Imageset name: TaharezLook
[ImageManager] ---- Source texture file: TaharezLook.png
[ImageManager] ---- Source texture resource group: (Default)
[ImageManager] Created image: 'TaharezLook/ClientBrush' (0x7b33150) of type: BasicImage

      ---- snip ----


[ImageManager] Created image: 'TaharezLook/TreeListOpened' (0x7b3b1a0) of type: BasicImage
Started creation of Font from XML specification:
---- CEGUI font name: DejaVuSans-10
----       Font type: FreeType
----     Source file: DejaVuSans.ttf in resource group: (Default)
---- Real point size: 10
Successfully loaded 3045 glyphs
Finished creation of Font 'DejaVuSans-10' via XML file. (0x8adb200)
===== Falagard 'root' element: look and feel parsing begins =====
---> Start of definition for widget look 'TaharezLook/Label'.
-----> Adding PropertyDefiniton. Name: NormalTextColour Default Value: FFFFFFFF
-----> Adding PropertyDefiniton. Name: DisabledTextColour Default Value: FFDDDDDD
-----> Adding PropertyDefiniton. Name: VertFormatting Default Value: CentreAligned
-----> Adding PropertyDefiniton. Name: HorzFormatting Default Value: CentreAligned
-----> Start of definition for imagery section 'Label'.
-------> Text component definition...
-----< End of definition for imagery section 'Label'.
-----> Start of definition for imagery for state 'Enabled'.
-------> Start of definition of new imagery layer, priority: 0

      ---- snip ----


-----< End of definition for imagery section 'CloseTreeButton'.
-----> Start of definition for imagery for state 'Enabled'.
-------> Start of definition of new imagery layer, priority: 0
---------> Layer references imagery section 'frame'.
-------< End of definition of imagery layer.
-----< End of definition for imagery for state 'Enabled'.
-----> Start of definition for imagery for state 'Disabled'.
-------> Start of definition of new imagery layer, priority: 0
---------> Layer references imagery section 'frame'.
-------< End of definition of imagery layer.
-----< End of definition for imagery for state 'Disabled'.
---< End of definition for widget look 'TaharezLook/Tree'.
===== Look and feel parsing completed =====
No window renderer factories specified for module 'CEGUICoreWindowRendererSet' - adding all available factories...
Created WindowRendererFactory for 'Core/Button' WindowRenderers.
WindowRendererFactory 'Core/Button' added. (0x7bdf8f0)
Created WindowRendererFactory for 'Core/Default' WindowRenderers.
WindowRendererFactory 'Core/Default' added. (0x7bdf990)
Created WindowRendererFactory for 'Core/Editbox' WindowRenderers.
WindowRendererFactory 'Core/Editbox' added. (0x7bdfa30)
Created WindowRendererFactory for 'Core/FrameWindow' WindowRenderers.

      ---- snip ----


WindowRendererFactory 'Core/Titlebar' added. (0x794d8e0)
Created WindowRendererFactory for 'Core/ToggleButton' WindowRenderers.
WindowRendererFactory 'Core/ToggleButton' added. (0x794da30)
Created WindowRendererFactory for 'Core/Tooltip' WindowRenderers.
WindowRendererFactory 'Core/Tooltip' added. (0x794d730)
Created WindowRendererFactory for 'Core/ItemListbox' WindowRenderers.
WindowRendererFactory 'Core/ItemListbox' added. (0x794dc30)
Created WindowRendererFactory for 'Core/Tree' WindowRenderers.
WindowRendererFactory 'Core/Tree' added. (0x794de50)
Creating falagard mapping for type 'TaharezLook/Label' using base type 'DefaultWindow', window renderer 'Core/Default' Look'N'Feel 'TaharezLook/Label' and RenderEffect ''. (0xbfffaba0)
Creating falagard mapping for type 'TaharezLook/Button' using base type 'CEGUI/PushButton', window renderer 'Core/Button' Look'N'Feel 'TaharezLook/Button' and RenderEffect ''. (0xbfffaba0)
Creating falagard mapping for type 'TaharezLook/Checkbox' using base type 'CEGUI/ToggleButton', window renderer 'Core/ToggleButton' Look'N'Feel 'TaharezLook/Checkbox' and RenderEffect ''. (0xbfffaba0)

      ---- snip ----

Assigning the window renderer 'Core/Scrollbar' to the window '__auto_vscrollbar__'
Assigning LookNFeel 'TaharezLook/VerticalScrollbar' to window '__auto_vscrollbar__'.
Window '__auto_thumb__' of type 'TaharezLook/VerticalScrollbarThumb' has been created. (0x8b41a00)
Assigning the window renderer 'Core/Button' to the window '__auto_thumb__'
Assigning LookNFeel 'TaharezLook/VerticalScrollbarThumb' to window '__auto_thumb__'.
MinSize resulted in an absolute pixel size of height larger than what MaxSize resulted in
Window '__auto_decbtn__' of type 'TaharezLook/ImageButton' has been created. (0x8b42000)
Assigning the window renderer 'Core/Button' to the window '__auto_decbtn__'
Assigning LookNFeel 'TaharezLook/ImageButton' to window '__auto_decbtn__'.
Window '__auto_incbtn__' of type 'TaharezLook/ImageButton' has been created. (0x8b42600)
Assigning the window renderer 'Core/Button' to the window '__auto_incbtn__'
Assigning LookNFeel 'TaharezLook/ImageButton' to window '__auto_incbtn__'.
MinSize resulted in an absolute pixel size of height larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of height larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of height larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of height larger than what MaxSize resulted inMinSize resulted in an absolute pixel size of width larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of width larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of width larger than what MaxSize resulted in
MinSize resulted in an absolute pixel size of width larger than what MaxSize resulted in
Window 'QuitButton' of type 'TaharezLook/Button' has been created. (0x8b42c00)
Assigning the window renderer 'Core/Button' to the window 'QuitButton'
Assigning LookNFeel 'TaharezLook/Button' to window 'QuitButton'.
Finished initializing CEGUI
2012-04-16 15:26:02.428 CEGUIDemo6[72025:fb03] GL ERROR: 0x0502

User avatar
CrazyEddie
CEGUI Project Lead
Posts: 6760
Joined: Wed Jan 12, 2005 12:06
Location: England
Contact:

Re: Mild success, outstanding issues in making CEGUI work on

Postby CrazyEddie » Mon Apr 30, 2012 07:45

It is likely something like the CEGUI GLES renderer modifying states, settings, bindings or what have you during its render call that cause the subsequent 'other' rendering (i.e. the cube) to fail. Either this or some GLES vs GLES 2 issue (or some combination)

CE.

williamxhero
Just popping in
Just popping in
Posts: 1
Joined: Mon Sep 28, 2009 05:55

Re: Mild success, outstanding issues in making CEGUI work on

Postby williamxhero » Wed Sep 19, 2012 08:07

Hi cheshirekow, have you solved the problem of the CeGUI/Ogre on iOS rotated and Clipped incorrectly problem?


Return to “Help”

Who is online

Users browsing this forum: No registered users and 19 guests