Jump to content
  • Advertisement
Sign in to follow this  
onehitstudio

I need Help: sprite in Direct3D

This topic is 3766 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 wrote some code to create a animation of a sprite (as a texture). I had a problem, when i use this sprite, my program runs exactly IMG :http://img103.imageshack.us/img103/8052/sprite4ba9.png this is source code for this sprite : (Media Fire) Link :http://www.mediafire.com/?qvcwzjb619x BUT when i use this srpite, it runs uncorrect: IMG :http://img440.imageshack.us/img440/9387/76167347jg8.png you can change "main.cpp" in previous source code by this "main.cpp" Link :http://www.mediafire.com/?hze4lgvxznu What wrong ? Ah, you can change any sprite that I have in source folder. Only cavemen.tga is correct, another is uncorrect.

Share this post


Link to post
Share on other sites
Advertisement
I cant download your code right now, but i already seen the sprites,
and they are of different kind, the first its a matrix of frames and
the second only a row, you cant load as the same. Try load as a matrix
of 1xN frames, 1 its the row, and N your frames, in the first sprite
you have a 4x4.

Share this post


Link to post
Share on other sites
Thanks _Camus_, but i wrote code and don't care matrix or row.
First Sprite(128x128), i take fourth row with top pixel = 96 and num of frame = 4.
Second sprite(1920x128) i take top pixel = 0 and num of frame = 15.
Two of them show me animation, but second sprite such this pictures
IMG : http://img241.imageshack.us/img241/7333/81447288xd8.jpg

It makes me mad! Please take a look at my code. Download from Media Fire very fast.

[Edited by - onehitstudio on June 30, 2008 4:04:24 AM]

Share this post


Link to post
Share on other sites
It's likely because the second image is not a power of 2 size. All cards you'd care about these days can make non-pow2 textures, but have limitations (see the d3dcaps9 help on nonpow2conditional. Some cards have no limitations, but take a speed hit.

The simplest solution is to tell D3DX to create the texture with width and height of D3DX_DEFAULT_NONPOW2. The limitations imposed shouldn't really affect a 2D sprite system, so aside from a potential speed issue, it should be fine. In most cases the speed loss isn't important to a 2D app.

The optimal solution is to tell D3DX to create a pow2 texture, but not to scale the data. Use D3DXCreateTextureFromFileEx, and pass a filter of D3DX_FILTER_NONE. You should also pass an image info structure, which will be filled in with the original texture dimensions, before being rounded up. You can use GetLevelDesc on the texture, using a level 0, to find the size of the texture created if you need that for UV generation.

Share this post


Link to post
Share on other sites
Thanks Namethatnobodyelsetoo! Thanks so much!
Heh, I only change one line code such you said :
<--YOU-->
The optimal solution is to tell D3DX to create a pow2 texture, but not to scale the data. Use D3DXCreateTextureFromFileEx, and pass a filter of D3DX_FILTER_NONE. You should also pass an image info structure, which will be filled in with the original texture dimensions, before being rounded up. You can use GetLevelDesc on the texture, using a level 0, to find the size of the texture created if you need that for UV generation.
<--YOU-->
<--ME-->
D3DXCreateTextureFromFileEx(deviceDX,"5.png",1920,128,1,D3DUSAGE_AUTOGENMIPMAP,D3DFMT_A8R8G8B8,D3DPOOL_DEFAULT,D3DX_FILTER_NONE,0,0,NULL,NULL,&monster_texture);
<--ME-->

It worked correctly.
But Can you explain "a power of 2 size" for me a little?
This texture i created by Macromedia Firework, and maybe it not include correct dimension?
As you said, some texture (isn't real texture as concept). When insert it that use D3DXCreateTextureFromFile, it will be SCALED !!?
So, how to create a "real" texture ?
Hix, many questions. ^________^

Share this post


Link to post
Share on other sites
Quote:
Original post by onehitstudio
As you said, some texture (isn't real texture as concept). When insert it that use D3DXCreateTextureFromFile, it will be SCALED !!?
No, the extra space will be filled with black.

Quote:
Original post by onehitstudio
So, how to create a "real" texture ?
Hix, many questions. ^________^
When you create the texture, you need to make sure it's a power of two in width and height - E.g. a width of 1, 2, 4, 8, 16, 32, 64, 128, 256, etc. The texture doesn't need to be square (Although it's often a good idea if you can).

Share this post


Link to post
Share on other sites
Oh oh, the power of two -> 2^x.
I don't know that, sorry for my poor english.
So Exactly, D3DXCreateTextureFromFile(A) will read a texture file with "the power of two" RULE.
This is the reason when i test to show all of frame at the same time, it seems have a extra space such you said.
Thank you!

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.

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!