Archived

This topic is now archived and is closed to further replies.

Bretttido

How to set a clipping rectangle?

Recommended Posts

I''m creating a User Interface with custom-windows inside of my Direct3D8 application. When I render objects inside of the windows, I''d like to be able to set the clipping rect to THAT window so that items will be contained inside of the window. Does anyone know a way to accomplish this? So basically, I want to be able to render objects and only allow, for instance, the rectangle (100, 100, 240, 300) to be modified. I''ve been messing around with the GetRenderTarget and Locking surface RECTs, but am getting nowhere. -Brett

Share this post


Link to post
Share on other sites
Any ideas? I''m also thinking i could render the contents of each window to a texture and simply display the texture as a quad... though it seems that would result in a considerable drop in framerate sense some windows will have content that changes every frame. And I can imagine sending a texture to the video card every frame is costly.

Share this post


Link to post
Share on other sites
If you''re using d3d to render all your 2D and 3D stuff then you just need to set the viewport and directx will clip the triangles for you.

Set the viewport to your window...

D3DVIEWPORT8 viewport;
viewport.X = ?;
viewport.Y = ?;
viewport.Width = ?;
viewport.Height = ?;
viewport.MinZ = ?;
viewport.MaxZ = ?;
device->SetViewport(&viewport)

... render, and reset it to fullscreen or whatever. If your window goes offscreen you will need to clip the x,y, width and height coordinates to the display size, otherwise the call to SetViewport will fail.

An idea might be to use a stack implementation (pushing and popping viewport ''contexts'') for each window, sub window, button or control. I''ve done this for all my in-game tools and it works quite well.

Spoof

Share this post


Link to post
Share on other sites
Thanks spoof, that sounds like exactly what i want to do. I guess I did not really understand the viewport all that well.. i was thinking it affected the way 3d space is projected onto the screen. But now that i think about it, that''s what the projection matrix is for! Duh! I''ll try that out. Thanks again

Share this post


Link to post
Share on other sites
Yes, the viewport does affect the view and projection matrices, because they base some calculations on the viewport size and position. If you simply render after setting a smaller viewport then everything will usually get scaled down, or offset.

However, if you setup your viewMatrix and projMatrix correctly you can render to the fullsized display and just have the viewport clip away everything outside the window.

Share this post


Link to post
Share on other sites