Sign in to follow this  
NeverKnovvsbestt

Drawing Textures

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
yadango    567
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

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