DirectX9 Texture of arbitrary size (non 2^n)

丶灬走出姿态 提交于 2019-12-11 14:17:49

问题


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:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/1187157/directx9-texture-of-arbitrary-size-non-2n

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!