I would like to display a text (e.g. name of character) above the character in 3D game?
E.g. in FPS game I would like to display a player's name above him.
What should I use to make it happen?
Probably I need to use some static text, to which I can transfer a matrix, or position vector?
Thank you very much.
How to display some text above character in 3D game?
Moderators: CEGUI MVP, CEGUI Team
How to display some text above character in 3D game?
Last edited by Emtec on Sun Jun 14, 2015 23:10, edited 2 times in total.
Re: How to display some text over character in 3D game?
Why do you wanna use a matrix? Do you want to have the text appear in the scene of your 3D game, so that it will be rotated, perspectively distorted etc? In this case the question is if the text should face the direction which the character is facing, in which case you might sometimes not be able to read that text. Typically in games you wanna displace the text without such transformations and without perspective and having it just facing you like a billboard. Is that what you want?
CrazyEddie: "I don't like GUIs"
Re: How to display some text above character in 3D game?
Yes it is. I want to display text above character (player) simple 2D text, without rotation. It would be good if it will be take into account distance between e.g. "camera" and other character - if the character is far the text would be small if the character is neer the text would be quite big. Thanks.
Last edited by Emtec on Sun Jun 14, 2015 23:11, edited 2 times in total.
Re: How to display some text over character in 3D game?
That's something CEGUI can't know. You have to know where the text needs to be placed. CEGUI naturally cannot have information of any kind about your "3D game".
In order to get the right position for CEGUI you need to know the size of the Label or StaticText and calculate that in. Also you will have to project the 3D position to screen space coordinates. This can be done on the CPU if you know the model view projection matrix. Simply do the perspective divide and get the result to screen space. This is a pretty standard transformation like the GPU does it. You will get the pixel coordinates on the screen and this can be used for the positioning.
All of this is not a CEGUI problem, but rather a problem of finding out the screen position. Once you know it everything should be relatively clear if you know how CEGUi windows are positioned and aligned (find out more about window positioning by using CEED for example)
In order to get the right position for CEGUI you need to know the size of the Label or StaticText and calculate that in. Also you will have to project the 3D position to screen space coordinates. This can be done on the CPU if you know the model view projection matrix. Simply do the perspective divide and get the result to screen space. This is a pretty standard transformation like the GPU does it. You will get the pixel coordinates on the screen and this can be used for the positioning.
All of this is not a CEGUI problem, but rather a problem of finding out the screen position. Once you know it everything should be relatively clear if you know how CEGUi windows are positioned and aligned (find out more about window positioning by using CEED for example)
CrazyEddie: "I don't like GUIs"
Re: How to display some text above character in 3D game?
Generally as I wrote in previous post I would like to write 2D test, which will be displyed above the characters (e.g. mobs). The problem is that this text have to take into account that some other character or some object can be in front of character, where text is displayed, so this text should be cut, because in front of the text there is some other character (mob, or some object). E.g. link below:
https://www.google.pl/search?q=l2+dialo ... B800%3B600
In this picture we can see that some text is cut, because of fact that in front of this text there is something.
At the beginig CEGUI accept a projectioMatrixm ViewMatrix and WorldMatrix (methods: SetProjectionMatrix setViewMatrix setWorldMatrix), so I think that CEGUI can take into account what is in front of something and behind something.
Thanks very much.
https://www.google.pl/search?q=l2+dialo ... B800%3B600
In this picture we can see that some text is cut, because of fact that in front of this text there is something.
At the beginig CEGUI accept a projectioMatrixm ViewMatrix and WorldMatrix (methods: SetProjectionMatrix setViewMatrix setWorldMatrix), so I think that CEGUI can take into account what is in front of something and behind something.
Thanks very much.
Last edited by Emtec on Sun Jun 14, 2015 23:14, edited 2 times in total.
Re: How to display some text over character in 3D game?
Please send an image link, the google image search might not help as I get different results and the first results do not show what you mean.
CEGUI renders to the FBO that is bound, this means that the Depth buffer of that FBO (used for 3D rendering previously) could be used. However, opposite to waht you seem to believe, CEGUI might ignore the depth values and not consider them.
Anyways, please first show a proper image reference, so that I understand what you wanna do regarding the cut-off.
Regarding the sizing: this is difficult because CEGUI 0.8.X does not allow to change Font sizes dynamically, and you would have to create an atlas for ever font size, not really a nice thing to do. You could render the text to a FBO (RTT) and then simply use that RTT texture to display the quad. The quad could simply be sized according to how you want.
CEGUI renders to the FBO that is bound, this means that the Depth buffer of that FBO (used for 3D rendering previously) could be used. However, opposite to waht you seem to believe, CEGUI might ignore the depth values and not consider them.
Anyways, please first show a proper image reference, so that I understand what you wanna do regarding the cut-off.
Regarding the sizing: this is difficult because CEGUI 0.8.X does not allow to change Font sizes dynamically, and you would have to create an atlas for ever font size, not really a nice thing to do. You could render the text to a FBO (RTT) and then simply use that RTT texture to display the quad. The quad could simply be sized according to how you want.
CrazyEddie: "I don't like GUIs"
Re: How to display some text above character in 3D game?
I realized that CEGUI renders to the binded FBO and that is great
.
I would like draw the text not only on the first plan, but also some distance from the screen, in such way that objects, which are on the scene could cover part of this text (CEGUI can using even data from depth buffer).
As I wrote earlier CEGUI uses view matrix and projection matrix (void CEGUI::OpenGLRenderer::setViewProjectionMatrix ( const mat4Pimpl * viewProjectionMatrix ) ) and that's why I think that it is possible.
However I cannot find function (option), which allow to display text on 3D scene (even text using coordinate 'z').
Actually I use DefaultWindow class (method setText("")) to display text in 2D and I have no idea how to display text in 3D...
Here is example of desired effect (from AOC):


I would like draw the text not only on the first plan, but also some distance from the screen, in such way that objects, which are on the scene could cover part of this text (CEGUI can using even data from depth buffer).
As I wrote earlier CEGUI uses view matrix and projection matrix (void CEGUI::OpenGLRenderer::setViewProjectionMatrix ( const mat4Pimpl * viewProjectionMatrix ) ) and that's why I think that it is possible.
However I cannot find function (option), which allow to display text on 3D scene (even text using coordinate 'z').
Actually I use DefaultWindow class (method setText("")) to display text in 2D and I have no idea how to display text in 3D...
Here is example of desired effect (from AOC):

Last edited by Emtec on Sun Jun 14, 2015 23:09, edited 1 time in total.
Re: How to display some text over character in 3D game?
However I cannot find function (option), which allow to display text on 3D scene (even text using coordinate 'z').
What do you expect? That you call a function like CEGUI::Renderer::displayTextIn3D() and then it just works magically?

The feature you want is not possible to do in CEGUI in the way you describe it. CEGUI not supposed to be rendered "inside" your 3D scene, it is an overlay. A regular GUI. That is how it is designed. Instead you should just render the text directly as billboards placed into your 3D scene, because that is what they are in your case: billboards. Not GUI elements. This is exactly what you wanna do.
Let me explain why CEGUI won't do it for you. It is true that you can set a viewProjection matrix. But this is not enough. You need to have knowledge about the rendering process in order to get the results you want. I won't teach this here. But I can explain you what goes on in CEGUI. Basically you need to know how to transform windows to your game's world space before you apply view space and clip space transformations. The GeometryBuffer's setTranslation method defines the translation and would allow (in theory) to translate the window to the right world space position. So this directly affects the model matrix (d_matrix). But you cant call the translate function directly since CEGUI internally uses it to position windows. And even if, it wouldn't solve your rotation issues. This is all just not the right approach to do things and I also do not see how we would support this in the future, it seems unlikely that this would happen.
CrazyEddie: "I don't like GUIs"
Re: How to display some text above character in 3D game?
This is exactly what I expected.
Of course not really in magically way...
I am not sure if you understand me correctly.
To render 3D text (without rotation) there is nothing more required (expect coordinates).
At least CEGUI has infomation about view projection matrix and as you said before CEGUI uses the actual binded FBO, which has got depth buffer, so it has all required information.
Having information about 3D position in world space, view projection matrix and the depth buffer there is no problem to render text in 3D (it is simple billboard rendering with enabled depth text).
If CEGUI does not support that feature - it is a pity, I will have to implement it on my own.
That was the answer what I was looking for.
Thanks for dispel my doubts and for your comprehensive answer.
#This text should be displayed above the character, like in the picture.
Of course not really in magically way...
I am not sure if you understand me correctly.
To render 3D text (without rotation) there is nothing more required (expect coordinates).
At least CEGUI has infomation about view projection matrix and as you said before CEGUI uses the actual binded FBO, which has got depth buffer, so it has all required information.
Having information about 3D position in world space, view projection matrix and the depth buffer there is no problem to render text in 3D (it is simple billboard rendering with enabled depth text).
If CEGUI does not support that feature - it is a pity, I will have to implement it on my own.
That was the answer what I was looking for.
Thanks for dispel my doubts and for your comprehensive answer.
#This text should be displayed above the character, like in the picture.
Re: How to display some text above character in 3D game?
You are right that billboard rendering is theoretically possible (you could just make the view matrix in a way the text will still face you, so no rotation) but the problem is that you also want to transform this into your 3D world as well. The view matrix is for ALL objects though, so even if you baked the model matrix into it, it would only work for all models the same way (resulting in the same size etc), but what you want is that it changes per character. So we would need a model matrix per window, which has to also consider the window's vertex coordinates (you could easily find them out by debugging and then based on that make the right transforms as you can ask a window about its dimensions, and this is essentially what affects the window).
In version 1.0 (default branch) I added a custom matrix which was needed for SVG rendering. This one could do that, but I recommend against using the unstable branch (default) and even with that in existance I cannot assure you that the approach works, because I havent personally tested it. I wouldn't want to misguide you. There might be something I still have not considered that is required in the process.
In version 1.0 (default branch) I added a custom matrix which was needed for SVG rendering. This one could do that, but I recommend against using the unstable branch (default) and even with that in existance I cannot assure you that the approach works, because I havent personally tested it. I wouldn't want to misguide you. There might be something I still have not considered that is required in the process.
CrazyEddie: "I don't like GUIs"
Who is online
Users browsing this forum: No registered users and 8 guests