Skip to main content
gamedev.net
🔒 Locked

D3DXSprite performance.

Started by Syranide 2 replies 800+ views
Original Post
Syranide
Syranide
I just recently tried this new D3DXSprite which has (apparently) superseded DirectDraw. But, as I'm always fond of speed, especially as I'm planning development on a rather simple game, but will require large amounts of "rectangles" to be drawn on the screen each frame. So of coarse I compared the performance, perhaps just for the fun. Drawing 64x32 squares 300 000/s (D3DX) 210 000/s (DD) Drawing 1280x1024 squares 500/s (D3DX) 1 200/s (DD) (Perhaps I should add that these are in no way fair tests) OK, to my real question then... I'm, as I said, new to this D3DX-thingy, so I searched the net for some good sample or help to start drawing sprites... not really that many (or at least not what I saw)... but I downloaded a sample and copied the D3DX code and tested some my self, but it didn't seem very well written... does anyone have any code or good site for me to check? (I don't care if it's lot of crap inbetween, I just want the "initialize"-procedure and some simple drawing code) (Aaaargh at Microsoft for not adding any D3DX-examples to the documentation, D3D they were very generous with though, or?)


Pipo DeClown
Pipo DeClown
I think you should go to websites in the Forum FAQ, like Drunken Hyena. He has great free cool useful tutorials! Another great method, I used it, is to look at the D3DX Reference in the SDK doc.
Take my advice: you'll learn more from a well structured reference (yes, in this case) than online tutorials.

And also, ID3DXSprite uses hardware for the 'complexer' calculations like Alpha Blending, so yes, ID3DXSprite is faster than DirectDraw. (99% sure). Of course if you are targetting at the poor homeless group with no videocards, then go for DirectDraw.
Syranide
Syranide
OK, I actually was a little unclear...

The question I actually had (I now see) was how to properly initialize the D3D device and set it up for fast/proper sprite rendering...

Like, why do I need the Zbuffer? And why did the sample set some strange parameters like lightning and such... it sets matrixperspectives, transform, renderstates, auto depth stencil.

It sets some sampler states too... why?!

I bet there are some options which would accelerate the drawing of only 2D slightly too?

... So how do I initialize D3D "properly" for rendering only sprites? (or just properly at all)


Tertsi
Tertsi
I suggest that you use the following renderstates + some extra states if you need:
	lpdevice->SetRenderState(D3DRS_LIGHTING, false);	lpdevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);	lpdevice->SetRenderState(D3DRS_ZENABLE, false);	lpdevice->SetRenderState(D3DRS_ZWRITEENABLE, false);	lpdevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);	lpdevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);	lpdevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);	//	Setup texture stages.		lpdevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);	lpdevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);	lpdevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);	lpdevice->SetVertexShader(NULL);//You can have it use these states without modifications like this:d3dxsprite->Begin(D3DXSPRITE_DONOTMODIFY_RENDERSTATE);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.