Skip to main content
GameDev.net gamedev.net
🔒 Locked

Using D3D for Sprites

Started by Kosmo Mar 20, 2003 at 11:03 AM 0 replies 600+ views
Original Post
Kosmo
Kosmo

I am making 2D space shooter and need some help on using D3D. My engine is now able to draw single textures loaded from png files and it creates separate texture for each object. Currently I have class CVisible which is then added to every class which needs to have a texture.

Problem: What kind of structure I should use to get as painlesly as possible multitexturing, animated textures and fast rendering. D3DSprite class is out of question I think, because it lacks in possibilities. Should I load all textures in initialization and then just point each objects LPDIRECT3DTEXTURE9 to right one? Animated textures are created by allocating multiple textures and then rotated between them if I am right? Should I just load them from separate png-files or is there some more clever method (mng?) doing this. Or should one texture contain all the frames and then change the u and v values? Speed is the issue in this code, so how should I make the rendering loop faster:
        
vidw_Device->Clear( 0, NULL, D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

vidw_Device->BeginScene();

SetupCamera(); 
SetupPerspective(); // I use D3DXMatrixOrthoLH


// RenderBackGround();


// and for each object I call Visible->Render which does the 

// following

  	D3DXMATRIX rotation, translation, transformation;
	D3DXMatrixRotationZ(&rotation, parent->GetRotation());
	D3DXMatrixTranslation(&translation, pos.x, pos.y, 0);
	D3DXMatrixMultiply(&transformation, &rotation,&translation);
	device->SetTransform(D3DTS_WORLD, &transformation);
	device->SetStreamSource(0, vertexBuffer, 0, sizeof(ge_vertex_t));
	device->SetVertexShader(NULL);
	device->SetFVF(D3DFVF_CUSTOMVERTEX);
	device->SetTexture(0, texture);
	device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


vidw_Device->EndScene();

vidw_Device->Present( NULL, NULL, NULL, NULL);
      
So if you could point me to some resources or give suggestions how to optimize this piece of code. And final question, I am planning to use screen sized sprite to draw the background and then just modify the u & v values of it to get moving background image... is that any good method or are there better ones out there. Huh, there's a bunch of questions and problems, I am pretty sure I could handle most of them by myself, but it is just so frustrating after 10 hours work to realize that there were so much better ways to do that. Vikke Matikainen "He who asks a questions is a fool for five minutes, he who doesn't stays fool for lifetime." - Old Chinese proverb [edited by - kosmo on March 21, 2003 9:24:44 PM]
Vikke Matikainen

Topic Locked

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

Sign in to reply to this topic.