Archived

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

Craazer

is there a way to clip drawed texture? (ID3DXSprite)

Recommended Posts

Hi, setting the source rectangle as Draw()''s parameter ins''t an option if you scale the texture. So do you know any ways to clip using ID3DXSprite''s draw method? I''m using the summer SDK.

Share this post


Link to post
Share on other sites
Set a new viewport to the area you want to clip and then when you''re doing rendering just reset the viewport to its original state.

Share this post


Link to post
Share on other sites
It is a common missconception that changing the viewport alone will allow you to cull away pixels (which is what you're asking basically). To cull pixels by changing the viewport would also require you to manipulate your projection matrix.

An easier way to accomplish this is to use SetScissorRect. First make sure that your card supports this functionality. If it does, then I would imagine this is exactly what you're looking for. This function allows you to define a 2D rectangle in screen space to confine your drawing to. Any pixels outside this 2D rectangle will not be calculated. The coordinates for the rectangle work like standard windows coordinates. (0,0)==(left, top), and (width,height)==(right, bottom).

Also make sure you enable scissor testing by calling SetRenderState.

neneboricua

[edited by - neneboricua19 on March 23, 2004 7:33:56 PM]

Share this post


Link to post
Share on other sites
quote:
Original post by Zorbfish
Set a new viewport to the area you want to clip and then when you''re doing rendering just reset the viewport to its original state.


That requires ending and starting the scene multiple times before the present and the scaling goes wild.


To neneboricua:

Oh the scissor test, I had tested it earlier and now its confirmed, my radeon doesnt suport it.

Share this post


Link to post
Share on other sites
quote:
Original post by DrunkenHyena
quote:
Original post by Craazer

That requires ending and starting the scene multiple times before the present


No it doesn''t. You need *1* BeginScene and *1* EndScene per frame.


Stay Casual,

Ken
Drunken Hyena


I dont understand how...

Share this post


Link to post
Share on other sites
quote:
Original post by neneboricua19
It is a common missconception that changing the viewport alone will allow you to cull away pixels (which is what you''re asking basically).


I apologize for my misinformation then. :/ Learn something new everyday I guess. SetScissorRect is DX9 specific isn''t it? Is there an equivalent in version 8?

I''d look it up myself but I don''t have my help files right in front of me and msdn updated their docs to DX9.

Share this post


Link to post
Share on other sites
To Zorbfish:
My graphics card doesn't suport the scissor test so it doesnt seem to be good method to use... I dunno if installing latests drivers would fix that?
Surely I would test that if they would work at all... (lot of lag comes whit them)

Anyway I think, its new feature in 9.0 becose theres some talk about new renderstate options (as shown below).

heres the stuff you need to use it:

// Methods

HRESULT IDirect3DDevice9::SetScissorRect(CONST RECT* pRect);
HRESULT IDirect3DDevice9::GetScissorRect(RECT* pRect);

// New RenderState, values are TRUE or FALSE

D3DRS_SCISSORTESTENABLE

// New hardware cap

D3D9CAPS.RasterCaps -> D3DPRASTERCAPS_SCISSORTEST;

//The default scissor rectangle is the full viewport.








Yet about the clipping.
So what about that projection matrix?
I actualy use D3D for 2D purposes only and im not good whit matrixes, but if somebody can give me some words to look from the SDKs docs it would be great.

[edited by - Craazer on March 26, 2004 7:40:50 PM]

Share this post


Link to post
Share on other sites
Sorry for raisin this post but I still strugle whit clipping.

I found SetClipStatus(); but that works only whit software draw operations.

Then there is SetClipPlane(DWORD Index,const float *pPlane); but I have no idea what comes as index and pPlane.. sure I read what doc said but I think that this is more like 3D clipping wich I dont know nothing about.

And I was reading about the Projection Transformation and the matrix wich lead me to this code:


D3DXMATRIX matrix;

RECT rect = {0,0,300,300};

D3DXMatrixPerspectiveOffCenterLH(&matrix,
rect.left,rect.right,rect.top,rect.bottom,-1,1);

pD3DDevice->SetTransform(D3DTS_PROJECTION,&matrix);




But that clips everything, any tips?

Share this post


Link to post
Share on other sites
I was looking into this, and I found a great source right in the SDK (at least in version 8 I don''t know if it''s the same, or even in version 9). It''s called Clip Mirror and it demonstrates how to use clip planes.

Basically since you''re doing 2D you''d just make your clip rectangle out of the 4 planes just like in the example. I haven''t tried it myself yet...

Good luck.

Share this post


Link to post
Share on other sites