GUI Objects

Started by
6 comments, last by Sik_the_hedgehog 7 years, 8 months ago

Hello folks,

I'm trying to render a super simple GUI object (like a square that "overlaps" the actual game scene). A GUI object should always stay on screen, overlapping any other object and, most important, must stand still where it is.

How can I achieve so?

I think a solution could be to render the object without setting up the zbuffer. So that object will always appear on screen. But I'm not sure that it would work. Also, I would need to create another device context to achieve so.

Another solution could be to manually edit the view matrix so the object stands still in place. But is it even possible?

I know the "best" solution is to use an external library, but I would like to avoid it. Also, I don't really need it. I just need a simple square that overlaps the game scene anyway.

Thanks in advance.

Advertisement
Rendering without a depth test seems like the simplest solution.

Yeah, you need to do these things:

  1. Not use the depth buffer
  2. Use a different projection matrix (2D instead of 3D)
  3. Render it after the 3D scene (so it's on top of it)

That's the simplest way to render UI elements. And of course undo all that when you start rendering 3D again the next frame!

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.
GUI is often simple enough that rendering in order is all that is necessary. So any sort of sorting or graph based technique is helpful here.

Yeah, you need to do these things:

  1. Not use the depth buffer
  2. Use a different projection matrix (2D instead of 3D)
  3. Render it after the 3D scene (so it's on top of it)

That's the simplest way to render UI elements. And of course undo all that when you start rendering 3D again the next frame!

That's what I meant! Now:

1. Ho do I "turn off" the depth buffer? Because, I'm setting it up as soon as I initalize the D3D device.

2. Sorry, what is it? XD

Thanks for answers.

1. Ho do I "turn off" the depth buffer? Because, I'm setting it up as soon as I initalize the D3D device.

You can turn it off and on at will by specifying a new depth stencil state:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb205074(v=vs.85).aspx

(set DepthEnable to FALSE in the D3D11_DEPTH_STENCIL_DESC)

1. Ho do I "turn off" the depth buffer? Because, I'm setting it up as soon as I initalize the D3D device.

You can turn it off and on at will by specifying a new depth stencil state:

https://msdn.microsoft.com/en-us/library/windows/desktop/bb205074(v=vs.85).aspx

(set DepthEnable to FALSE in the D3D11_DEPTH_STENCIL_DESC)

2nd EDIT: I've found the jigsaw I was missing: https://msdn.microsoft.com/en-us/library/windows/desktop/bb205074(v=vs.85).aspx

I will, eventually, update later. Thanks for help. :)

Right, by turn off I meant temporarily disabling it (no depth test, no writes to depth buffer), not getting rid of the buffer ^_^;

Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

This topic is closed to new replies.

Advertisement