Sign in to follow this  

texture not loading correctly

This topic is 2857 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
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
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
Previous post:
Quote:
draw just one of the textures and try to determine where the problem is ... sprite->Draw(texture,NULL,NULL,&pos,D3DCOLOR..);

This results in all 3 separate images rendering together when called for just a single index?

Share this post


Link to post
Share on other sites

This topic is 2857 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this