[Solved] CEGUI custom rendering

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

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

[Solved] CEGUI custom rendering

Postby andrewfeng123 » Sun Nov 12, 2017 15:19

My goal is to draw a child window separately so that i can draw things in between the rendering process of GUI
my draw function looks something like this

Code: Select all

GetRenderer()->beginRendering();

Child->setVisible(0);                     //make it invisible first so that <Parent> doesn't draw it
Context->draw();                         //draw the context that contains <Parent>

/*
    draw stuff from my game
*/
Child->setVisible(1);
Child->activate();
Child->render();                         //doesn't draw anything

GetRenderer()->endRendering();


I also tried to draw Parent with the same method but without the disabling, nothing's on the screen.

I must be using Window::render() wrong and I can't find any information in the docs or in src that helps.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: CEGUI custom rendering

Postby Ident » Sun Nov 12, 2017 16:42

What is Child? What is Context?
(I can guess but I dont wanna guess wrong)

What speaks against doing your rendering by rendering to a texture and then using this texture as image for a Generic/Image widget in CEGUI for example?
CrazyEddie: "I don't like GUIs"

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Sun Nov 12, 2017 20:20

I apologize for not making things clear,
Parent and Child are CEGUI::Window s,
Context is the CEGUI::GUIContext that contains Child and Parent.
Parent contains Child as a child window.

I want to separate the rendering of Parent and Child. RTT doesn't seem to do that because it draws the whole GUIContext.

That's why I was thinking about calling the CEGUI::Window::render().
Is such approach feasible in CEGUI?

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: CEGUI custom rendering

Postby Ident » Sun Nov 12, 2017 20:38

Your overall goal with this is unclear to me. Can you please explain what you want to render in what way and most of all how it should look?
CrazyEddie: "I don't like GUIs"

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Sun Nov 12, 2017 22:22

Okay, I need to draw my own content on top of the Parent window but beneath the Child window. The thing I want to draw is essentially a mask, that way the Child window looks special.

Imagine you are playing a game, a warning pops up and everything except for the warning window gets darker? I want that.

If you still don't get it. Here's the full story.

I have implemented a wrapper class for CEGUI::Window, lets call it "WidgetWindow".
A WidgetWindow is given a specific task and will return a specific value before its destruction.
One example would be the "Do you want to exit the game?" which returns true/false.
Another example would be the ColorPicker which collects user's input and returns 3 int values.

The reason I did this instead of using CEED to create a window and ... is that I need to be able to use these WidgetWindows from anywhere of the game. I don't want to copy and paste it to everywhere every time I need it...

Back to the story.

So I have the WidgetWindow which contains a CEGUI::Window.
My idea is that when a button is clicked, I attatch the WidgetWindow to the root CEGUI::Window so that It can receive user input from the root window's CEGUI::GUIContext without doing all the Inject input crap twice every frame.

There should be no problem if I only want that, but I also want to add some visual effects when some special kind of WidgetWindow is called.
Here's an example I found on the information superhighway.
Image

I know I can add it in the CEED editor but that means I need to added to every .layout file (StartMenu, GameScreen, Settings...). That's just not flexible so I want to do it on my side.

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Thu Nov 16, 2017 21:38

So does anyone know if Window::render() works? Or is there anything I need to call with it for it to work?

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: CEGUI custom rendering

Postby Ident » Thu Nov 16, 2017 21:43

andrewfeng123 wrote:So does anyone know if Window::render() works? Or is there anything I need to call with it for it to work?

Sorry, I was busy these last days. I am going to reply to you tomorrow or saturday. This topic is something that requires me to look more into code before I can give a good answer, and I had no time yet due to my employment and other duties.
CrazyEddie: "I don't like GUIs"

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Thu Nov 16, 2017 22:11

Ident wrote:
andrewfeng123 wrote:So does anyone know if Window::render() works? Or is there anything I need to call with it for it to work?

Sorry, I was busy these last days. I am going to reply to you tomorrow or saturday. This topic is something that requires me to look more into code before I can give a good answer, and I had no time yet due to my employment and other duties.


Thanks man ! I thought you forgot or something, please take your time!

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Sat Nov 18, 2017 14:56

Window::render() needs to be followed by a Window::getTargetRenderingSurface().draw()

however, this only works if the window has a RenderingSurface, from what I've tested, this only works for the root window of a context. (Since the root window is a DefaultWindow in CEED)

SO I TRIED--
A. Adding a RenderingSurface to the WidgetWindow by Window::setRenderingSurface(), the window successfully drew but it doesn't seem to take any input (no reaction, buttons freeze)

B. Adding a DefaultWindow to the .layout file of my WidgetWindow, the window also succesfully drew but this time... the DefaultWindow acts like a invisible barrier that blocks input to all other windows behind it...

Both attempts failed :x

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: CEGUI custom rendering

Postby Ident » Sun Nov 19, 2017 20:53

Do I understand correctly that all you want is to "shadow" everything in the background of a dialog that requires input?

I think what you did is way too complicated for this, CEGUI can do these things easily without you having to dig into any rendering logic here. What you want to make is a window with relative size w:1 h:1 (fullscreen) that is a sibling of all the other windows you got attached to your root. This window shall be on top (we get to that later) and will shadow everything. By default a fullscreen window that is on top will steal away all input, so be careful when you follow the instructions i wrote below.

Here is how a hierarchy could for example look:

Code: Select all

CEGUI Root
|___ SomeWindow1
|___ SomeWindow2
|           |___ Text1
|        ....
|
|___NewWindowWithShadowingEffect (add this whenever is needed and remove it when it isnt needed)
            |___ DialogRootWindow


Now how to setup NewWindowWithShadowingEffect :
e.g. use a Generic/Image with an Image that is a 1x1 black pixel with alpha=1. Now you got this set up and attached it to your root window you should see all black. If not, maybe the window order isnt right, set it to AlwaysOnTop=true just to be sure. Set the window's alpha value to whatever you like in order to make it less black. Now this solution is simple and dynamic so you can easily change this at setup/runtime.

You still have to take care of your DialogRootWindowthough. You will attach this to this new shadowing-window so we can make that it will not be shadowed and also so it fits the whole input order. It will inherit the alpha by default. Change it so it doesnt inherit the alpha from the shadowing window by putting its "InheritAlpha" value to false. This will also mean that you can just attach windows normally and unchanged to your DialogRootWindow and their alpha will still not be affected by the alpha of NewWindowWithShadowingEffect, as DialogRootWindow already caught it and has the default alpha value itself.

To get rid of the shadow you can just detach NewWindowWithShadowingEffect which logically also detaches the dialog.

I hope this works for you, if not please tell me where you are stuck.
CrazyEddie: "I don't like GUIs"

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Mon Nov 20, 2017 23:30

Thanks for your elegant solution! Lemme try that out.

I will post the full solution after I finish just in case.

User avatar
Ident
CEGUI Team
Posts: 1998
Joined: Sat Oct 31, 2009 13:57
Location: Austria

Re: CEGUI custom rendering

Postby Ident » Tue Nov 21, 2017 07:38

The hierarchy was messed up in my post due to formatting, please check again as I now put it in code tags.
CrazyEddie: "I don't like GUIs"

andrewfeng123
Just popping in
Just popping in
Posts: 20
Joined: Sat Sep 02, 2017 20:28

Re: CEGUI custom rendering

Postby andrewfeng123 » Fri Dec 01, 2017 15:57

The goal is achieved!

I simply created a layout file with StaticImage, set alwaysOnTop = true;

I load this layout at the beginning and set it to invisible. Whenever I need a WidgetWindow that requires the shadow, I set the StaticImage to visible and add the WidgetWindow::window to the StaticImage as a Child.


Return to “Help”

Who is online

Users browsing this forum: No registered users and 4 guests