Page 1 of 1

OpenGLRenderTarget and PROJECTION_MATRIX

Posted: Tue Jan 04, 2011 18:18
by uelkfr
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().

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Posted: Wed Jan 05, 2011 09:47
by Kulik
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.

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Posted: Thu Jan 06, 2011 12:38
by Kulik
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.

Re: OpenGLRenderTarget and PROJECTION_MATRIX

Posted: Mon Jan 17, 2011 13:18
by uelkfr
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();
...