OpenGLRenderTarget and PROJECTION_MATRIX

For help with anything that CEGUI doesn't offer straight out-of-the-box, e.g.:
- Implementation of new features, such as new Core classes, widgets, WindowRenderers, etc. ...
- Modification of any existing features for specific purposes
- Integration of CEGUI in new engines or frameworks and writing of new plugins (Renderer, Parser, ...) or modules

Moderators: CEGUI MVP, CEGUI Team

uelkfr
Not too shy to talk
Not too shy to talk
Posts: 34
Joined: Tue Dec 14, 2010 16:57

OpenGLRenderTarget and PROJECTION_MATRIX

Postby uelkfr » Tue Jan 04, 2011 18:18

First, some code from CEGuiOpenGLBaseApplication.cpp which is in samples/common/src

Code: Select all

void CEGuiOpenGLBaseApplication::reshape(int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
    CEGUI::System::getSingleton().
        notifyDisplaySizeChanged(CEGUI::Size((float)w,(float)h));
}

Why this code is needed? The only line that plays role here is the last line there are notifyDisplaySizeChanged() called. Because in OpenGLRenderTarget's code glViewport() and glMatrixMode() is overwritten.

Second, using Rotation property of any window makes window drag moving impossible. I tried to play with it using my own GL_PROJECTION matrix setup, but since its overwritten by CEGUI I had to stop. I don't want to make custom changes to CEGUI, because they will be lost after upgrading/porting to next version :) And I dunno how to change it, because I'm not matrixes and linear algebra specialist :) But it would be useful to declare a flag d_isUserDefinedMatrix in RenderTarget, so a user could setup own GL_PROJECTION matrix before renderGUI().
helper to newbies

"i help you, dear newbie
but nobody helps me!"

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

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Postby Kulik » Wed Jan 05, 2011 09:47

I think the right way to fix this is to make transform and rotation more powerful. The current problem is that MouseCursor isnt' in the GUISheet (or that is what I recall from my experiments). Also you can't play with the rotation pivot much because positions are 2D only (I proposed 3D coords for everything with Z not being used for 2D stuff but nobody liked that). The custom matrix is also possible but CEGUI doesn't implement any matrices as of now so the patch would need to be larger than you probably imagine.

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

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Postby Kulik » Thu Jan 06, 2011 12:38

follow up note: As CE suggested on IRC channel, notifyDisplaySizeChanged doesn't touch the GL context. The base app is just doing what every GL app should be doing. Sure it isn't necessary in this case but it would be if the app was doing something other than just drawing UI.

uelkfr
Not too shy to talk
Not too shy to talk
Posts: 34
Joined: Tue Dec 14, 2010 16:57

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Postby uelkfr » Mon Jan 17, 2011 13:18

Yes. But it should be separate function then.

Code: Select all

void CEGuiOpenGLBaseApplication::setupMatrixes()
{
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 50.0);
    glMatrixMode(GL_MODELVIEW);
}

void CEGuiOpenGLBaseApplication::reshape(int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h);
    setupMatrixes();
    CEGUI::System::getSingleton().
        notifyDisplaySizeChanged(CEGUI::Size((float)w,(float)h));
}

void CEGuiOpenGLBaseApplication::drawFrame(void)
{
    CEGUI::System& guiSystem = CEGUI::System::getSingleton();
    // do time based updates
    int thisTime = glutGet(GLUT_ELAPSED_TIME);
    float elapsed = static_cast<float>(thisTime - d_lastFrameTime);
    d_lastFrameTime = thisTime;
    // inject the time pulse
    guiSystem.injectTimePulse(elapsed / 1000.0f);
    // update fps fields
    doFPSUpdate();

    // update logo rotation
    static float rot = 0.0f;
    d_logo_geometry->setRotation(CEGUI::Vector3(rot, 0, 0));
    rot += 180.0f * (elapsed / 1000.0f);
    if (rot > 360.0f)
        rot -= 360.0f;

    // do rendering for this frame.
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
   
    setupMatrixes();
    draw(); // virtual func
    guiSystem.renderGUI();
...
helper to newbies

"i help you, dear newbie
but nobody helps me!"


Return to “Modifications / Integrations / Customisations”

Who is online

Users browsing this forum: No registered users and 0 guests