Jump to content
  • Advertisement
Sign in to follow this  
jitterjaw

The right way to load a lot of 2d graphics

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

Hi all, I've been working on this 2d arcade for quite a while, most of my directx programming is based on the tutorial given in http://www.directxtutorial.com, so basicely Im using big sprite sheets for each character. The problem is, when there are more than 5 different characters on the screen the game becoms terribbly slow, my assumption is that, this is caused because of the way Im working with the graphics. My sprite sheets can be quite huge (4096X4096), and only about 40% of each page actually contains the sprite images and the rest is blank (due to the requierment of the sprite sheet height and width to be a power of 2). My questions: 1. Is there a better way to load 2d graphics ? 2. Can I just break down the sprite sheet to smaller images and by that save memory space ? 3. Can there be any other reason for the slowing down ? (cause I think its cache related, due to the huge sprite sheets....) Thanks ya all, JitterJaw

Share this post


Link to post
Share on other sites
Advertisement
A 4096X4096X32bpp texture is 64MB without mipmaps, and about 85MB with. Five of those will be over 300MB. Unless you have a 512MB video card it'll be swapping textures in and out of video memory every frame. Since they are big texture uploading them will be slow.

Suggestions:

- Make the textures smaller. If only 40% is used a 4096x2048 should be big enough. Non square textures aren't a problem on any card that supports 4096 wide textures.

- I'd recommend that each sheet should only contain one animation. That way if an animation isn't currently being used it won't need to be in video memory. Uploading a smaller texture to video memory will also be quicker.

- Try using DXT5 compression on the textures. That will make them four times smaller in memory, and decompression happens in hardware. The DirectX Texture Tool that comes with the SDK can be used to compress them. DXT1 can be used instead to get them half as small again for any textures that don't use alpha.

Share this post


Link to post
Share on other sites
Rather than guessing what the problem is, you might want to profile a couple of frames with PIX and see which calls take the most time.

Quote:
only about 40% of each page actually contains the sprite images

How many positions per sheet (separate "tiles") do you have? Can you pack them more efficiently? Can you get more efficient by packing more than one character's animation into a single sheet and rendering characters sharing a sheet sequentially to avoid reloading?

Quote:
Can there be any other reason for the slowing down ?

A PIX profile could tell you that.

Share this post


Link to post
Share on other sites
Quote:
Original post by Adam_42
Suggestions:

- Make the textures smaller. If only 40% is used a 4096x2048 should be big enough. Non square textures aren't a problem on any card that supports 4096 wide textures.

- Try using DXT5 compression on the textures. That will make them four times smaller in memory, and decompression happens in hardware. The DirectX Texture Tool that comes with the SDK can be used to compress them. DXT1 can be used instead to get them half as small again for any textures that don't use alpha.

Hi and thanks for the replay, I have questions regarding your suggestions :
1. How can I load non square textures ? when I try doing so, they get stretched to a square (using DX 9).
2. how do I use this DXT5 compression ?
Sorry for bringing it back from the archives...
Jitter Jaw

Share this post


Link to post
Share on other sites
Use D3DXCreateTextureFromFileEx, and specify D3DX_DEFAULT_NONPOW2 for the Width and Height. That link contains information on the other arguments if you want more details.

I've used the following successfully:

D3DXCreateTextureFromFileEx(
pDevice,
TEXT("texture.jpg"),
D3DX_DEFAULT_NONPOW2,
D3DX_DEFAULT_NONPOW2,
1,
0,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
0,
NULL,
NULL,
&pTexture
);

Share this post


Link to post
Share on other sites
A 4096x2048 texture should load just fine without using D3DX_DEFAULT_NONPOW2. You can call GetDesc() on the texture to check it's dimensions.

My guess would be that the rendering code needs some adjustment as the texture coordinates still run from 0-1 in each dimension.

As for creating a DXT5 texture, just run the "DirectX Texture Tool" that comes with the DirectX SDK, load in your uncompressed texture, and save it out as a compressed .DDS file.

Alternatively just pass D3DFMT_DXT5 instead of D3DFMT_UNKNOWN to D3DXCreateTextureFromFileEx(). Doing the compression at load time will be slow though.

Share this post


Link to post
Share on other sites
Quote:
Original post by Maarten Baert
Why do you need that many sprites? Can't you use textured primitives or something similar instead?

Can you elaborate on textured primitives ? what do you mean by that ?
I need a lot of sprites because I have a lot of different characters, each character has its own sprite sheet.

Share this post


Link to post
Share on other sites
Aren't the characters too big or maybe they have too many animation frames? (Like more than 64x64 in size and more than ~10 fps for every animation)

Share this post


Link to post
Share on other sites
Quote:
Original post by snake5
Aren't the characters too big or maybe they have too many animation frames? (Like more than 64x64 in size and more than ~10 fps for every animation)


Hmm... Its an interesting question, but the I feel that the characters aren't too big, even though they are bigger than 64x64, and some animations are longer than 10 frames. But the rest is quite basic, I dont feel that this kind of ancient 2d graphics should burden modern graphic adapters and directx 10, cause thinking about it similar games also existed in the times of the super Nintendo :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!