[SOLVED] Render a specific GUI context

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

addictgamer
Just popping in
Just popping in
Posts: 10
Joined: Wed Oct 30, 2013 16:46

[SOLVED] Render a specific GUI context

Postby addictgamer » Wed Oct 30, 2013 17:30

For the last two weeks, I've been racking my head over trying to render CEGUI to multiple windows (actual windows, not widgets) -- using SFML 2.0, if that's relevant.

I've tried many things to get CEGUI to render interface to multiple windows, but in the end, it renders to only one window, whichever one I last activated the OpenGL viewport of. I believe that is because of:

Code: Select all

CEGUI::System::getSingleton().renderAllGUIContexts();

Which is rendering all GUIContexts at once to the currently active OpenGL viewport (which is odd, since at least the default GUI context should be rendering to the OpenGL context that was active when I bootstrapped its OpenGL renderer -- at least that should be happening according to the wiki).

Therefore, I believe the solution to the problem is something like this:

Code: Select all

for (std::vector<GUIContext_wrapper* >::iterator iter = contexts.begin(); iter != contexts.end(); ++iter)
{
   (*iter)->sfml_window->setActive(); //This sets the current OpenGL viewpoint to the target window.
   CEGUI::GUIContext& context = (*iter)->cegui_gui_context;

   //Draw the GUI context here.
}

Which would explicitly render each GUI context to the desired OpenGL viewport as opposed to CEGUI rendering to whatever it happens upon in renderAllGUIContexts().

I looked at the API reference and tried:

Code: Select all

for (std::vector<GUIContext_wrapper* >::iterator iter = contexts.begin(); iter != contexts.end(); ++iter)
{
   (*iter)->sfml_window->setActive(); //This sets the current OpenGL viewpoint to the target window.
   CEGUI::GUIContext& context = (*iter)->cegui_gui_context;

   context.draw();
}

But that doesn't work. CEGUI doesn't render anything and any rendering I do with OpenGL or SFML is very glitchy.

I tried combining the context.draw() with renderAllGUIContexts():

Code: Select all

for (std::vector<GUIContext_wrapper* >::iterator iter = contexts.begin(); iter != contexts.end(); ++iter)
{
   (*iter)->sfml_window->setActive(); //This sets the current OpenGL viewpoint to the target window.
   CEGUI::GUIContext& context = (*iter)->cegui_gui_context;

   context.draw();
}
CEGUI::System::getSingleton().renderAllGUIContexts();

No go. CEGUI renders now, but it's still only to one window. Rendering with OpenGL or SFML is very glitchy, again.

I remembered I read:
The created Renderer will use the current OpenGL viewport as it's
default surface size.

in the API documentation about the bootstrap function for the OpenGL Renderer, so I set the current OpenGL viewport where I created the renderer and GUI context to the viewport I want it to render to:

Code: Select all

wrapper.window->setActive();

wrapper.cegui_renderer = &CEGUI::OpenGLRenderer::create();

wrapper.cegui_gui_context = &CEGUI::System::getSingleton().createGUIContext(wrapper.cegui_renderer->getDefaultRenderTarget());
[code]

I know the GUI contexts see the right OpenGL viewport because:
[code]
std::cout << "Context size: " << context.getSurfaceSize() << "\n";

Outputs each context's target window's size, not the size of any other window.

Therefore, I conclude that neither ideas I had, nor any of the other countless things I've tried while browsing the forums, wiki, and API reference, are the solution.

In conclusion, how do I tell a CEGUI::GUIContext to render itself to the OpenGL viewport I want?
Last edited by addictgamer on Wed Oct 30, 2013 18:48, edited 1 time in total.

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

Re: Render a specific GUI context

Postby Kulik » Wed Oct 30, 2013 18:02

Hi,
I suspect you need to call d_renderer->beginRendering() which will do something (tm) to the OpenGL state machine.

You can see the exact renderAllGUIContexts code in https://bitbucket.org/cegui/cegui/src/e ... ult#cl-419

Also look into CEGUI::OpenGLRenderer::enableExtraStateChanges (I hope I got the method name right). It could be that the OpenGL state you are leaving to CEGUI is not in the expected state. This is a hard to solve issue because we can't know which state it is in and we can't reset everything because that would waste performance.

EDIT:
Something like this should work

Code: Select all

for (std::vector<GUIContext_wrapper* >::iterator iter = contexts.begin(); iter != contexts.end(); ++iter)
{
   (*iter)->sfml_window->setActive(); //This sets the current OpenGL viewpoint to the target window.

   d_renderer->beginRendering();
   CEGUI::GUIContext& context = (*iter)->cegui_gui_context;

   context.draw();
   d_renderer->endRendering();
}


If all the GUIContext have a screen target surface.

addictgamer
Just popping in
Just popping in
Posts: 10
Joined: Wed Oct 30, 2013 16:46

Re: Render a specific GUI context

Postby addictgamer » Wed Oct 30, 2013 18:47

Thanks, CEGUI now renders to multiple windows!

For anybody's future reference:

Code: Select all

for (std::vector<GUIContext_wrapper* >::iterator iter = contexts.begin(); iter != contexts.end(); ++iter)
{
   (*iter)->sfml_window->setActive(); //This sets the current OpenGL viewpoint to the target window.

   (*iter)->cegui_renderer->beginRendering();
   CEGUI::GUIContext& context = (*iter)->cegui_gui_context;

   context.draw();
   (*iter)->cegui_renderer->endRendering();
}

That's how my specific code looks now.


Return to “Help”

Who is online

Users browsing this forum: Bing [Bot] and 35 guests