Jump to content
  • Advertisement

Archived

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

WoX

Dx8 is a mess

This topic is 6203 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 trying to do a 2d rts game in directx8. I''ve started to do blits after reading the article 2d with Directx8 that I found here at gamedev. The problem is that it goes way too slow when I try to blit more then a hundred 40*40 tiles... it even go slow in 16bit mode!! I thought it was because I locked/unlocked the vertexbuffer once/screen update, but when I try to only lock once in the whole program it _still_ go slow. Here''s my drawing code: // this function is called for every object I wanna draw RenderPanel(float x, float y, IDirect3DTexture8 *Texture, float rotation) { D3DXMATRIX Position, Rotation, Result; D3DXMatrixTranslation(&Position, x, y, 0.0f); D3DXMatrixRotationZ(&Rotation,float(rotation/RAD)); Result = Rotation * Position; pd3dDevice->SetTransform(D3DTS_WORLD, &Result); pd3dDevice->SetTexture(0, Texture); pd3dDevice->SetVertexShader(D3DFVF_PANELVERTEX); pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2); } in the beginning of the program I set the color,position and the texture coordinates of the vertices (4 vertices) why the heck does it go so slow please help

Share this post


Link to post
Share on other sites
Advertisement
Oh sorry I forgot, the computer I''m testing this on have the following specs:
1,33 Ghz AMD Athlon
256 RAM
Matrox Millenium G400 32Mb gfx card

Share this post


Link to post
Share on other sites
How big are the textures?

Try to minimize texture switches - if you can render several pieces with one texture, do so. Also, you may want to place several pieces in the same buffer. Also, don''t set the vertex shader any more often than you need to.

There are lots of little places to optimize here. The article outlines the basic idea, but there are lots of places to tweak when scaling up.

Share this post


Link to post
Share on other sites
Thanks for the tip CrazedGenius but it would be too messed up code if I tried to optimize the texture usage. I''m using a tile class that contains a pointer to a texture. it would slow down even more if I started checking all the tiles for textures that''s alike...

MatrixCubed: It would be great if you could e-mail it
thomas.woxberg@spray.se
Can''t figure out any other way to move the panels except for moving vertex by vertex. And it said in the article 2d rendering with Directx8 that it was a bad idea to do that. So I used matrix translations instead.

Share this post


Link to post
Share on other sites
Create a texture manager.

when you load a texture the texture manager will go through a list a previously loaded textures, if it finds it return the pointer to the texture, if not load it and then return the new pointer.

The texture manager is responsible for freeing the textures.

there that was easy.

D.V.

Carpe Diem

Edited by - DeltaVee on November 20, 2001 2:03:53 PM

Share this post


Link to post
Share on other sites
G''day!

The reason it''s running so slowly is that you are drawing each tile individually. It''s horribly inefficient. 3D hardware works well with batches.

1)Set your Vertex shader at the beginning of your drawing loop, not every time you draw a tile. It''s not a HUGE performance hit, but it doesn''t need to be done.

2)Make a large vertex buffer, lock it once at the beginning of the frame (or only when it changes, even better) and write out the vertex information yourself.

3)Combine your tiles into a larger texture page and use tu/tv offsets in your vertices to choose your tiles. Combined with #2, this will allow you to draw (potentially) an entire screen worth of tiles with a single draw call.


Stay Casual,

Ken
Drunken Hyena

Share this post


Link to post
Share on other sites
yeah thanks for the great hints everyone, especially DrunkenHyena, too tired to try them out now though, but they seem very reasonable. Goodnight...

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!