Jump to content
  • Advertisement
Sign in to follow this  
JuliusDegutis

DirectX 9 alternative way to draw image

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

Hello, maybe anybody could help with drawing images on screen? smile.png

 

Now using D3DXCreateTextureFromFileEx: loading LPDIRECT3DTEXTURE9 by file name, width and height. And later using texture with LPD3DXSPRITE.Draw(texture,rect,center,position,color). But if I change rect size, texture don't scale, just stretching in wrong way (https://www.dropbox.com/s/pn6920yar2o4kat/2013-09-25%2018_35_06-APPTITLE.png: normal image, increased width, increased height).

 

Am I doing something wrong? Maybe my way don't let change width/height after image is loaded? Maybe where is another way to draw images?

 

 

There is loading texture loading code:

	D3DXIMAGE_INFO d3dxImageInfo;
		if(FAILED(D3DXCreateTextureFromFileEx( 
			g_dxManager.GetDevice(),
			fileName.c_str(), 
			width, 
			height, 
			1,
			D3DPOOL_DEFAULT,
			D3DFMT_UNKNOWN,
			D3DPOOL_DEFAULT,
			D3DX_DEFAULT,
			D3DX_DEFAULT,
			D3DCOLOR_COLORVALUE(1.0f,0.0f,1.0f,1.0f), //ignores 255;0;255 - dark pink
			&d3dxImageInfo,
			NULL,
			&_texture)))
		{
			ErrorHandler::ShowError("Loading texture failed");
		}

and drawing code:

			_sprite->Draw( sprite->Texture()->Texture(),//LPDIRECT3DTEXTURE9 is loaded from method above
				&rect,
				&vCenter,
				&vPosition,
				D3DCOLOR_COLORVALUE(
				sprite->Texture()->TextureColor()._r,
				sprite->Texture()->TextureColor()._g,
				sprite->Texture()->TextureColor()._b,
				sprite->Texture()->TextureColor()._a));

Edited by Plutonium

Share this post


Link to post
Share on other sites
Advertisement

Hey I'm not seeing any of the images you mentioned. Generally speaking though, if you increase the size of the rect, the image will just stretch across the new surface since the tex-coords haven't changed. 

Share this post


Link to post
Share on other sites
This is indeed what is happening: ID3DXSprite::Begin sets the addressing mode to clamp. One could change this after Begin or use D3DXSPRITE_DONOTMODIFY_RENDERSTATE, but I don't recommend the latter since you would need to set all the necessary states for proper sprite rendering by hand now.

The culprit is elsewhere. Note that the rectangle parameter in ID3DXSprite::Draw is the source rectangle, i.e. you select a part from the texture. Set pSrcRect to NULL to select the whole texture.

If you want to scale (or arbitrarily transform) a sprite you need to use ID3DXSprite::SetTransform before calling Draw. Unfortunately it isn't as simple as telling a target rectangle.sad.png

Share this post


Link to post
Share on other sites

This is indeed what is happening: ID3DXSprite::Begin sets the addressing mode to clamp. One could change this after Begin or use D3DXSPRITE_DONOTMODIFY_RENDERSTATE, but I don't recommend the latter since you would need to set all the necessary states for proper sprite rendering by hand now.

The culprit is elsewhere. Note that the rectangle parameter in ID3DXSprite::Draw is the source rectangle, i.e. you select a part from the texture. Set pSrcRect to NULL to select the whole texture.

If you want to scale (or arbitrarily transform) a sprite you need to use ID3DXSprite::SetTransform before calling Draw. Unfortunately it isn't as simple as telling a target rectangle.sad.png

If setting renderstate, then nothing is rendered to screen, so as you recommended, I won't change it.

 

Whole idea is that I could increase only one object width/height, while others will be as was. This is for my map builder, that could put objects and change their size and position, then save to xml. Yep, I could leave it now as it's, because for editing will be ok, but thinking about future :)

 

This one implemented, but it changes all images on screen, without changing real width/height. So... Thanks, now I have zooming/rotation functions :D

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!