Jump to content
  • Advertisement
Sign in to follow this  
GAFO666

Problems with Sprite's SourceRect :/

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

Hey Guys,

 

Basicly I want to draw just a region of an Image and not the full one with its sprite smile.png

The normal way is pretty easy and the SourceRect is set to NULL for drawing the full image.

m_Imagepos.x = x;
m_Imagepos.y = y;
	

m_Imagesprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Imagesprite->Draw(m_Imagetexture, NULL, NULL, &m_Imagepos, 0xFFFFFFFF);
m_Imagesprite->End();

The image is e.g. 64x1024 in size.

And I want only draw the uppest part of it, lets say 64x64, based on the big image.

Thatfor I tried this:

RECT testrect;
testrect.left	= x;
testrect.top	= y;
testrect.right	= testrect.left + 64;
testrect.bottom = testrect.top + 64;

m_Imagesprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Imagesprite->Draw(m_Imagetexture, &testrect, NULL, &m_Imagepos, 0xFFFFFFFF);
m_Imagesprite->End();

By logic the sourcerect should define the region which has to be drawn or not ?

So what Im doing wrong here ? o.o

 

Here a Picture, so you can see what I mean:

zsskw9O.png

 

 

,greetings GAFO  smile.png

Edited by GAFO666

Share this post


Link to post
Share on other sites
Advertisement
You need to set the top/left coordinates in texture coordinates, not the location you want the sprite at. The sprite location is already catered for with m_ImagePos. For example:
RECT testrect;
testrect.left	= 0;
testrect.top	= 64;
testrect.right	= testrect.left + 64;
testrect.bottom = testrect.top + 64;

m_Imagesprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Imagesprite->Draw(m_Imagetexture, &testrect, NULL, &m_Imagepos, 0xFFFFFFFF);
m_Imagesprite->End();

Edit:

Also make sure to check that the actual texture surface is the size you expect it to have. As far as I remember D3DXLoadTexture may create a texture surface bigger than the original image. Edited by Endurion

Share this post


Link to post
Share on other sites

You need to set the top/left coordinates in texture coordinates, not the location you want the sprite at. The sprite location is already catered for with m_ImagePos. For example:

RECT testrect;
testrect.left	= 0;
testrect.top	= 64;
testrect.right	= testrect.left + 64;
testrect.bottom = testrect.top + 64;

m_Imagesprite->Begin(D3DXSPRITE_ALPHABLEND);
m_Imagesprite->Draw(m_Imagetexture, &testrect, NULL, &m_Imagepos, 0xFFFFFFFF);
m_Imagesprite->End();
Edit:

Also make sure to check that the actual texture surface is the size you expect it to have. As far as I remember D3DXLoadTexture may create a texture surface bigger than the original image.

 

oh thank you very much :D It works now :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!