Sign in to follow this  

Managing textured quads?

This topic is 4868 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

I'm going to use textured quads because I want to use sprites in '3d' space (billboards, basically). D3DXSprite is in screen space so it won't work. My question is about managing textured quads, it seems to me like it would be a lot of work to keep track of a quad for every sprite I have (hundreds). Is it a bad idea to use a single textured quad, then scale/rotate/translate it and apply the texture each time I draw? I don't want to deal with managing hundreds of quads in my vertex buffer. I basically want to set up the functionality of D3DXSPRITE but in world space, not screen space. My camera is stationary so I don't have to worry about rotating them to always face the camera. Any replies about how to deal with drawing a lot of sprites using textured quads in a way that's easy to manage are appreciated.

Share this post


Link to post
Share on other sites
As I understand it you want to call DrwaPrimitive and SetTexture as little as possible. I could be totaly off here, but I believe that your are better off (preformance wise) using a dynamic vertex buffer than changing your transforms and calling DrawPrimitive hundreds of times.

You may also want to combine your textures and use the texcords of your verts to place only a section of the texture on the quad. Of course this would require using more than one quad in your buffer. But should limit your calls to SetTexture.

Also take a closer look at Sprite (sorry, I'm from managed land). There is a Billboard flag that you can pass to Sprite.Begin and you can do 3D placement with SetWorldViewLH/RH and Draw instead of Draw2D. Sprite will also handle the texture splitting in a more intuitive way.

Hope that this helps.

Share this post


Link to post
Share on other sites
Quote:
Original post by xegoth
D3DXSprite is in screen space so it won't work.


pSprite->Begin( D3DXSPRITE_OBJECTSPACE );

// apply transforms or whatever as normal. not screen space anymore


pSprite->End();

Share this post


Link to post
Share on other sites
I've heard this mentioned before but haven't found anything in the docs about it.

m_pd3dxSprite->Begin( D3DXSPRITE_OBJECTSPACE );

error C2065: 'D3DXSPRITE_OBJECTSPACE' : undeclared identifier

I'm using DirectX 9, are there additional includes or something? My code works with D3DXSPRITE already but just in screen space.

EDIT: Okay my SDK docs are differen't than the online ones, I think maybe I need the summer update of the SDK or something, so I'm downloading it now :) hopefully this does the trick.

Share this post


Link to post
Share on other sites
Groovy I got it to work here's the fuction I use for drawing sprites now.


HRESULT DXEngine::DrawSprite( D3DXMATRIX matWorld, LPDIRECT3DTEXTURE9 pSrcTexture,
RECT *pSrcRect, DWORD dwFlags )
{

D3DXVECTOR3 trans(0,0,0), rcenter(0,0,0);

// Define the center of the texture. For rotation, and drawing at the center.
if(pSrcRect) {
trans.x -= rcenter.x = ((float)(pSrcRect->right - pSrcRect->left) / 2);
trans.y -= rcenter.y =((float)(pSrcRect->bottom - pSrcRect->top) / 2);
}

m_pd3dxSprite->SetTransform( &matWorld );
m_pd3dxSprite->Begin( D3DXSPRITE_OBJECTSPACE );

m_pd3dxSprite->Draw(m_pTexShip, pSrcRect, &rcenter, &trans, 0xFFFFFFFF );
m_pd3dxSprite->End();

return S_OK;

}

matWorld is the matrix for the sprite you want to draw. I really need to rename it though since it doesn't resemble blitting at all anymore :P Rotation may be totally screwed up with it though, I haven't played with that yet. :)

Share this post


Link to post
Share on other sites

This topic is 4868 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.

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