Jump to content
  • Advertisement
Sign in to follow this  
justin12343

texture not loading correctly

This topic is 3068 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 draw frames from a strip loaded, but it draws more than 1 frame. Each frame is 64X64, but 3 frames are squished together in a 64x64 rectangle. loading:
[SOURCE]
switch (player_index)
    {
        case 0:
        player_sprite_dir="img/sonic.png";
        break;
        case 1:
        player_sprite_dir="img/tails.png";
        break;
        case 2:
        player_sprite_dir="img/knuckles.png";
        break;
    }
    D3DXIMAGE_INFO d3dxImageInfo;

    D3DXGetImageInfoFromFile(player_sprite_dir, &d3dxImageInfo);
    player_sprite_width=d3dxImageInfo.Width;
    player_sprite_height=d3dxImageInfo.Height;

	D3DXCreateTextureFromFileEx( D3DDEVICE9,
                                 player_sprite_dir,
                                 player_sprite_width,
                                 player_sprite_height,
                                 1,
                                 D3DPOOL_DEFAULT,
                                 D3DFMT_UNKNOWN,
                                 D3DPOOL_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
                                 &d3dxImageInfo,
                                 NULL,
                                 &player_texture );


    D3DDEVICE9->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	D3DDEVICE9->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
    D3DXCreateSprite( D3DDEVICE9, &player_sprite );
[/SOURCE]
RECT:
[SOURCE]    
    RECT srcRect;
    srcRect.top    = 0;
    srcRect.left   = player_image_index*64;
    srcRect.bottom = srcRect.top+64;
    srcRect.right  = srcRect.left+64;
[/SOURCE]
Do I have to turn something extra on or is it just user error? [Edited by - justin12343 on February 19, 2010 3:23:36 PM]

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Do I have to turn something extra on or is it just user error?

Can't tell from the code you posted as there's no code for the actual drawing.
Quote:
3 frames are squished together

"Squished" is a rather untechnical term. Can you describe in a bit more detail what you're trying to display and what is looks like? Along with the code, maybe an image?

Your rectangle for accessing frames 0, 1 and 2 could work for accessing the individual parts of a 192x64 image. Need to see how you draw them.

Share this post


Link to post
Share on other sites
Also, please use the "source" or "code" tags when posting source code so that it gets proper formatting. See the FAQ.

Share this post


Link to post
Share on other sites
Also, please use the "source" or "code" tags when posting source code so that it gets proper formatting. See the FAQ.

Share this post


Link to post
Share on other sites
here's the drawing part:


D3DXVECTOR3 vCenter( 0.5f, 0.5f, 0.0f );
D3DXVECTOR3 vPosition( x, y, z );

player_sprite->Begin( D3DXSPRITE_ALPHABLEND );

player_sprite->Draw( player_texture,
&srcRect,
&vCenter,
&vPosition,
D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

player_sprite->End();







It's supposed to draw a what frame player_image_index is set to (player_image_index=0 then draw the first frame).

For some reason it does this:
screen shot

[Edited by - justin12343 on February 21, 2010 11:26:28 AM]

Share this post


Link to post
Share on other sites
In your draw call, leave the center position NULL and change just the position. I'm still not sure what you want the result to look like, but you can play around with vPosition.

player_sprite->Draw( player_texture, &srcRect, NULL, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
In your draw call, leave the center position NULL and change just the position. I'm still not sure what you want the result to look like, but you can play around with vPosition.

player_sprite->Draw( player_texture, &srcRect, NULL, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );


that didn't work, it's still drawing 3 frames together in the quad.

I trying to get it look like this:
screen shot
,Instead of this:
screen shot

Share this post


Link to post
Share on other sites
Are you trying to draw three separate images, each of which is 64x64, in three separate locations? If so, vertically or horizontally?

If 3 separate images, vertically:

D3DXVECTOR3 pos(0,player_image_index*64,0);
sprite->Draw(texture,NULL,NULL,&pos,D3DCOLOR..);

If that doesn't work, draw just one of the textures and try to determine where the problem is.

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!