Sign in to follow this  
gfaraj

2D Clipping for a GUI System

Recommended Posts

Hello, I am developing a GUI system for DirectX to be able to create GUIs very easily for my games. It is coming out quite nicely but it's missing something: clipping. I was thinking that I could use IDirect3DDevice8::SetViewPort to set the view port to the window rectangle, and that would be it, but it isn't working. Here is my code: D3DVIEWPORT8 oldv, newv; BEGlobalD3DDevice8->GetViewport(&oldv); newv.X = GetAbsoluteLeft(); newv.Y = GetAbsoluteTop(); newv.Width = Width; newv.Height = Height; newv.MinZ = 0; newv.MaxZ = 1.0; BEGlobalD3DDevice8->SetViewport(&newv); // draw stuff BEGlobalD3DDevice8->SetViewport(&oldv); Something is wrong, it draws nothing, I don't know. Has anyone done this before or know why this could be happening? Thanks a lot, George Faraj

Share this post


Link to post
Share on other sites
I'm using SetViewport and it works like a charm. Does SetViewport return an error when you set it?

Also, you should not set the viewport to a non-visible area (width or height=0). That will be rejected. In that case you ought to have a bool or another method telling nothing should be drawn.

And the viewport is not allowed to go outside the backbuffer. You have to clip it yourself in that case.

BTW, i'm using transformed vertices (RHW) for my GUI. I think using non-transformed will scale things down instead of clip.

Ah, and be careful with getviewport. It won't work on pure devices. But the default viewport is easy, it's just x,y to 0, with and height to backbuffer width and height and z 0.0f and 1.0f. So there's actually no need to call getviewport at all.

Share this post


Link to post
Share on other sites
Thanks for the reply!

Well, do you just use SetViewPort and nothing else? Now, I changed something and I'm actually getting stuff drawn, but everything scaled up and at a wrong position.

Width and Height never are 0 and the viewport does not go outside the backbuffer...

Actually, now that I think about it, it might be the non-transformed vertices... I'm not the one that actually draws the stuff, a friend of mine wrote those routines. He uses another matrix to draw stuff according to the current veiwport (just so he can draw stuff in multiple cameras).

Any idea on what I could do?

Thanks a lot,
George

Share this post


Link to post
Share on other sites
It depends what your plans are with the GUI. If it's always just lying on top (pure 2d) you might as well use transformed vertices.

If you plan to do neat 3d tricks you can't use them (or transform them yourself). In that case you also have to do the clipping yourself as the render output will be scaled into the viewport.

Share this post


Link to post
Share on other sites
I want the GUI to be 2d only. The thing is, I want it to be able to be rendered in multiple cameras (e.g a multiplayer game where screen is divided in 4). For that, I have to obviously transform the vertices.

I heard I could edit the Z values of my vertices so the Z-buffer would do the clipping for me... I will have to try that tomorrow.

Thanks

Share this post


Link to post
Share on other sites
I'm not using transformed vertices. Yeah, the splitting of the screen is currently being done by dividing the viewports.

I was thinking it was going to be viewport-in-viewport clipping. I have an idea of how it could be, but I don't know if it's going to work. I need it so the GUI scales down to each camera viewport, but not to the clip viewport. If I set the clip viewport, and I use non-transformed vertices, they will scale to the viewport right? That's the problem, I don't want them scaling to the clip viewport.

When you do your splitting, since you use transformed vertices, do you have to scale your stuff manually for the multiple cameras' viewports? Or how do you do it?

Share this post


Link to post
Share on other sites
Hmm.. i tried incrementing the Z values of the stuff I want in the clip region, but it doesn't work. It just draws everything like before... Strange..

Any ideas?

Share this post


Link to post
Share on other sites
Ah, it works now :D

The Z-buffer was disabled.. I enabled it, and I see that the clipping is working..

Thanks for the help Endurion.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this