Jump to content
  • Advertisement

Archived

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

TrueKnight42

DirectX8 Clipping

This topic is 6150 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone, I am writing a 2D engine with DirectX8 and I am doing the tilemap stuff right now. I dont know much 3D math (which is why I''m doing a 2D engine! hehe) and I''m having a little trouble figuring out how to do clipping. I want to have a function I can call such as Screen->SetClip(64,64,500,500) to set the clipping window... Can anybody help me out?? Thanks in advance! (Sorry if this gets posted twice the gamedev server timed out when I pressed post the first time!)

Share this post


Link to post
Share on other sites
Advertisement

1) You can set the size of the surface drawn to in the D3DPRESENT_PARAMETERS which you pass to IDirect3D8::CreateDevice. You can also modify this with the IDirect3DDevice8::Reset call.

2) You use IDirect3DDevice8::SetViewport to specify the rectangle within that surface which gets drawn to. (After D3D transformation [the maths bit], x and y coordinates end up in the range -1 to 1, D3D then multiplies and scales them by the parameters set in the viewport). Setting the viewport would be the main part of your clipper code.

3) The Projection matrix determines how the x,y,z coordinates you pass to calls like DrawPrimitive get converted into the x,y coordinates in the -1 to 1 range handled above (interestingly enough the -1 to 1 range is called "**CLIP** space"). Most of what the projection matrix does is concerned with things like perspective - for a 2D engine, just use the D3DX functions to avoid the maths to set it up. Two useful parts the projection matrix has for your needs though is handling of the aspect ratio (scale in x and y directions and the ratio between the scales) and the offset for the coordinates. [D3DXMatrixPerspectiveOffCenterLH is probably the most suitable D3DX projection matrix generation function for your needs]

4) Some other calls like IDirect3DDevice8::Clear have rectangle parameters where you can specify the region to be operated on. [Beware though some graphics card drivers don''t like you clearing rectangles smaller than the screen with Clear]

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Sorry for possibly stating the obvious, but do you know about the ID3DX sprite interface of DX8? If you don''t want to make your own, use that.

Share this post


Link to post
Share on other sites
Thanks for the reply but I must admit that I''m still a bit lost. I have tried using SetViewport etc but it just scales my drawing and does not clip it. What I want is to be able to make my tilemap appear in only a 500x500 window in the middle of the screen or something like that. Is there no easy way to do this?? There has to be and I''m just too stupid to figure it out...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!