views:

277

answers:

2

Hi,

I'm relatively new to DirectX and have to work on an existing C++ DX9 application. The app does tracking on a camera images and displays some DirectDraw (ie. 2d) content. The camera has an aspect ratio of 4:3 (always) and the screen is undefined.

I want to load a texture and use this texture as a mask, so tracking and displaying of the content only are done within the masked area of the texture. Therefore I'd like to load a texture that has exactly the same size as the camera images.

I've done all steps to load the texture, but when I call GetDesc() the fields Width and Height of the D3DSURFACE_DESC struct are of the next bigger power-of-2 size. I do not care that the actual memory used for the texture is optimized for the graphics card but I did not find any way to get the dimensions of the original image file on the harddisk.

I do (and did, but with no success) search a possibility to load the image into the computers RAM only (graphicscard is not required) without adding a new dependency to the code. Otherwise I'd have to use OpenCV (which might anyway be a good idea when it comes to tracking), but at the moment I still try to avoid including OpenCV.

thanks for your hints, Norbert

+1  A: 

D3DXGetImageInfoFromFile may be what you are looking for.

I'm assuming you are using D3DX because I don't think Direct3D automatically resizes any textures.

CiscoIPPhone
A: 

D3DXCreateTextureFromFileEx with parameters 3 and 4 being

D3DX_DEFAULT_NONPOW2.

After that, you can use

D3DSURFACE_DESC Desc;
m_Sprite->GetLevelDesc(0, &Desc);

to fetch the height & width.

Chaoz
This will work if the device supports non-power of 2 sizes (nearly all do, as far as I know).
CiscoIPPhone
Well, older cards probably do not. But nearly all recent cards do.
Ricket
Actually the width and height will be in the D3DXIMAGE_INFO if you pass one as the __3rd last__ parameter to D3DXCreateTextureFromFileEx
bobobobo