Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Drawing Textures Problem
 Post Posted: January 29th, 2013, 2:22 am 
 

Joined: January 29th, 2013, 2:06 am
Posts: 2
I'm learning and trying 2D games development with DirectX and i'm having a little problem.

I've managed to read, create and draw textures with the types:
Code:
LPDIRECT3DDEVICE9 // for the D3D Device,
LPDIRECT3DTEXTURE9 // for textures,
LPD3DXSPRITE // for the Sprite used to draw the textures,
D3DXVECTOR3 // for X, Y and Z position 

And the functions:
Code:
D3DXCreateTextureFromFile( LPDIRECT3DDEVICE9 pDevice,LPCTSTR pSrcFile,
                           LPDIRECT3DTEXTURE9 *ppTexture ) // to create the textures,

D3DXCreateSprite( LPDIRECT3DDEVICE9 pDevice, LPD3DXSPRITE *ppSprite ) // to create the Sprites,

Begin( DWORD flags ) // to start drawing the sprite,

Draw( LPDIRECT3DTEXTURE9 pSrcTexture, CONST RECT *pSrcRect, D3DXVECTOR3 *center,
      CONST D3DVECTOR3 *pTranslation,  D3DCOLOR Color ) // to draw the sprite with a texture and other specifications,

End() // to finish drawing the sprite.

I'm calling the Begin, Draw and End functions between the BeginScene() (which goes after a Clear function) and EndScene() (which is followed by a Present function).

Everything is working fine, except for a little problem. The textures are being drawed bigger than their actual size. I'm not using any scale or matrix to change the textures size/position in the sprite drawing function, like described below:
Code:
     pSprite->Draw( pTexture, NULL, NULL, &pPosition, 0xFFFFFFFF );

I know that most of these functions and types were not covered on the tutorials yet, but i'd be glad if someone shared a solution for this problem.


Top 
 Profile  
 
 Post Posted: January 29th, 2013, 12:37 pm 
User avatar

Joined: April 22nd, 2012, 12:33 pm
Posts: 1485
Location: Finland
The function you use loads the images in sizes of multiples of 2. In other words it loads the closest next size from 2, 4, 8, 16,...128, 256, 512, 1024, etc

Use "D3DXCreateTextureFromFileEx" instead where you can give the exact size you want or use "D3DXDEFAULT" or something like that to get the size of the image automatically.

_________________
ʕ •ᴥ•ʔ


Top 
 Profile  
 
 Post Posted: January 29th, 2013, 3:44 pm 
 

Joined: January 29th, 2013, 2:06 am
Posts: 2
It works now! When i create the textures with D3DXCreateTextureFromFileEx, they are created with their original size.
Code:
       HRESULT hr = D3DXCreateTextureFromFileEx( pD3DDevice, L"pathtofile", D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2,
                                      D3DX_DEFAULT, 0, D3DFMT_FROM_FILE, D3DPOOL_DEFAULT, D3DX_DEFAULT,
                                      D3DX_DEFAULT, 0, NULL, NULL, pTexture );


Thanks! And sorry for my (bad) english.


Top 
 Profile  
 
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 3 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: