DirectX Texture Sizes

so I found that my graphics card automatically resizes textures to 2, which is usually not a problem, but I only need to display part of my texture and at the same time have dimensions that were resized to ...

for example: I load an image of 370x300 pixels in my texture and try to draw it using 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 was automatically changed (in this case) to 512x512, I see only part of my original texture.

The question is, is there a function or something that I can call to find the dimensions of my texture? (I tried looking for this, but always get weird shit about objects and HSL or something like that)

+4
source share
1 answer

You can get file information using this call:

 D3DXIMAGE_INFO info; D3DXGetImageInfoFromFile(file_name, &info); 

Although, knowing the initial size of the texture, you still get its size at boot time. This will obviously affect the quality of the texture. Resizing the texture doesn't really matter when you apply it on the grid (it will be resized anyway), but this can be a problem for drawing sprites. To get around this, I could suggest creating a surface by loading it through the D3DXLoadSurfaceFromFile , and then copying it into a β€œpow2” sized texture.

And offtopic: are you definitely sure about the capabilities of your card? Your do card may actually support arbitrary texture sizes, but you are using D3DXCreateTextureFromFile() , which uses pow2 values ​​through deafult. To avoid this, try using the advanced version of this procedure:

 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 texture is non-pow2 you upload the file as is. If the hardware is not able to process it, and the method will not work.

+3
source

Source: https://habr.com/ru/post/1392055/


All Articles