Norbert
Norbert

Reputation:

DirectX9 Texture of arbitrary size (non 2^n)

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

Upvotes: 0

Views: 2559

Answers (2)

Charles
Charles

Reputation: 2661

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.

Upvotes: 3

CiscoIPPhone
CiscoIPPhone

Reputation: 9477

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.

Upvotes: 1

Related Questions