Dx8 is a mess

Started by
6 comments, last by WoX 22 years, 5 months ago
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
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

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.
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
Probably because you''re using a whack of matrix translations to render 2D sprites.

If you would like my Sprite3D class, I can email it to you. It does a pretty great render speed, and is fairly customizeable.




MatrixCubed
http://MatrixCubed.cjb.net






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.
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
D.V.Carpe Diem
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
Stay Casual,KenDrunken Hyena
yeah thanks for the great hints everyone, especially DrunkenHyena, too tired to try them out now though, but they seem very reasonable. Goodnight...

This topic is closed to new replies.

Advertisement