directx texture dimensions

余生颓废 提交于 2019-12-22 09:37:41

问题


so I've discovered that my graphics card automatically resizes textures to powers of 2, which isn't usually a problem but I need to render only a portion of my texture and in doing so, must have the dimensions it has been resized to...

ex: I load a picture that is 370x300 pixels into my texture and try to draw it with a specific source rectangle

RECT test;
    test.left = 0;
    test.top = 0;
    test.right = 370;
    test.bottom = 300;

    lpSpriteHandler->Draw(
        lpTexture,
        &test,          // srcRect
        NULL,           // center
        NULL,            // position
        D3DCOLOR_XRGB(255,255,255)
        );

but since the texture has been automatically resized (in this case) to 512x512, I see only a portion of my original texture.

The question is, is there a function or something I can call to find the dimensions of my texture? (I've tried googling this but always get some weird crap about Objects and HSL or something)


回答1:


You may get file information by using this call:

D3DXIMAGE_INFO info;
D3DXGetImageInfoFromFile(file_name, &info);

Though, knowing the original texture size you'll still get it resized on load. This will obviously affect texture quality. Texture resizing is not a big deal when you apply it on mesh (it will get resized anyway) but for drawing sprites this could be a concern. To workaround this I could suggest creating a surface, loading it via D3DXLoadSurfaceFromFile and then copying it to a "pow2" sized texture.

And an offtopic: are you definitely sure about your card capabilities? May be in fact your card do support arbitrary texture sizes but you use D3DXCreateTextureFromFile() which by deafult enforces pow2 sizes. To avoid this try using extended version of this routine:

D3DTexture* texture;
D3DXCreateTextureFromFileEx(
    device, file_name, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT_NONPOW2, D3DX_DEFAULT, 0,
    D3DFMT_UNKNOWN, D3DPOOL_MANAGED, D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,
    &texture);

If your hardware suppors non-pow2 textures you'll get your file loaded as it is. If hardware is not able to handle it than method will fail.



来源:https://stackoverflow.com/questions/8942959/directx-texture-dimensions

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