Archived

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

kiiwee

[Q]Creating surfaces of flexible size in D3DX8.0!

Recommended Posts

I ask your contend for my short English... I wanted to create textures those width and height are not power of 2, but I failed by using D3DXCreateTexture(). In D3DX8.0,we can use only textures as surface,can''t create flexible textures(those are not power of 2). That causes memory waste. When I loaded 129x129 bitmap on texture surface, waste is about three times of needed memory. I''m 2D game progammer,so I must use bitmaps of various size as sprite. But in DirectX8.0, I can''t create textures except those size are power of 2. That''s big problem to me. Do I return to 7.0? Is that word "combine" means only "contain" unchanged DirectDraw7.0 in Direct3D8.0? Are they force us to use DirectDraw of previous version when we make 2D game? I don''t think so, Microsoft DirectX team might think about flexibility when they combined DirectDraw and Direct3D. I want to use D3DX8.0 library in my application,but I consider to return previous version of DirectX cause of memory waste. How can I load and blit 2D sprites not wasting memory away in 8.0? Please tell me...

Share this post


Link to post
Share on other sites
Since many cards require texture dimension to be a power of two, and you need sprites that are not a power of two, try putting several sprites into a single texture. For example, if you use 32x32 tiles, you can put 16 of these into one 128x128 texture. You can also do this with irregularly sized sprites. Just change the u and v texture coordinates of your vertices, so each square references the appropriate part of the texture. Consider the following texture:

1 2 2 3
1 2 2 4
1 2 2 4

Sprite one is represented by 1''s, and sprite two by 2''s, etc. The texture coordinates for 1 go from 0.0, 0.0 to 0.25, 1.0. For 2, they are 0.25, 0.0 to 0.5, 1.0. etc. You may still have some wasted space in each texture, but its usually worth the trade off, because you get free alpha and texture blending effects, as well as rotation shearing and scaling effects by using the 3d hardware.

Share this post


Link to post
Share on other sites
There are reasons for the whole power of two thing...

In addition to combining sprites, you may want to size sprites at design time to fit this constraint. The example you give about 129x129 textures is correct, but do you *really* need 129x129 (vs. 128x128)? If you''re worried about wasted memory, a 129x129 bitmap might waste memory in any case because of alignment issues.

Another advantage to combining textures - less texture switching. If you have lots of little sprites, it may really help to place them in one larger texture.

Consideration of bitmap size at design time is never a bad thing, even if this were easier. This problem is fairly easy to work around.

Share this post


Link to post
Share on other sites
If your doing pure 2D, then use DirectDraw in DirectX7. DirectDraw7 wasnt updated in DX8 because it is already perfect. 2D textures(called surfaces in 2D) can be any size and 2D blitting is extremely fast even on old video cards. Otherwise, if your gonna do 2D with a 3D api, then do as the others above suggested.

Possibility

Share this post


Link to post
Share on other sites