Jump to content
  • Advertisement
Sign in to follow this  
NeverKnovvsbestt

Drawing Textures

This topic is 4627 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 have been having problems trying to draw a loaded textrue from file. I think the problem is origination in my createTexture function. Here are my methods: IDirect3DTexture9* DirectXManager::createTexture(int width, int height) { IDirect3DTexture9 *texture; HRESULT hResult; hResult = lpd3dDevice->CreateTexture( width, height, 0, 0, D3DFMT_X8R8G8B8, D3DPOOL_DEFAULT, &texture, NULL); if(FAILED(hResult)) return NULL; return texture; } IDirect3DTexture9* DirectXManager::loadTextureFromFile(char* filePath) { HRESULT hResult; D3DXIMAGE_INFO d3dxImageInfo; hResult = D3DXGetImageInfoFromFile(filePath, &d3dxImageInfo); if(FAILED(hResult)) return NULL; IDirect3DTexture9 *texture = createTexture( d3dxImageInfo.Width, d3dxImageInfo.Height); hResult = D3DXCreateTextureFromFile(lpd3dDevice, filePath, &texture); if(FAILED(hResult)) return NULL; return texture; } bool DirectXManager::drawTexture( IDirect3DTexture9 *texture, int srcX, int srcY, int srcW, int srcH, int dstX, int dstY, int dstW, int dstH) { HRESULT hResult; LPD3DXSPRITE sprite; hResult = D3DXCreateSprite(lpd3dDevice, &sprite); RECT srcRect; srcRect.bottom = srcY + srcH; srcRect.left = srcX; srcRect.right = srcX + srcW; srcRect.top = srcH; D3DXVECTOR3 centerVector( (FLOAT)(dstX + (dstW / 2)), (FLOAT)(dstY + (dstH / 2)), 0); D3DXVECTOR3 positionVector((FLOAT)dstX, (FLOAT)dstY, 0); hResult = sprite->Begin(D3DXSPRITE_ALPHABLEND); if(FAILED(hResult)) return NULL; hResult = sprite->Draw( texture, &srcRect, ¢erVector, &positionVector, 0xFFFFFFFF); if(FAILED(hResult)) return NULL; hResult = sprite->End(); if(FAILED(hResult)) return NULL; return true; } any suggestions?

Share this post


Link to post
Share on other sites
Advertisement
one thing to look out for is relative paths. tis a common "gotcha" with D3DX. if you pass "texture.bmp" or "textures/texture.bmp" to your loadTextureFromFile function, that texture better be in the current directory, which isn't necessarily your program directory (things like common dialogs can change the current directory). tis always best to provide a full path to the LoadTextureFromFile function. otherwise, tis looks ok. you should put some error statements in there or some error logging to see where it fails.

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!