Sign in to follow this  
Sagito

DX GUI - Getting an image resolution

Recommended Posts

Hi... I'm trying to create a GUI/menu system in my DirectX 9.0c application, and I would like to load image files to the interface. That is relatively easy to do using sprites, but I wanted the image file object to throw mouse-over events and to do so, I need to know it's upper-left corner and the image dimensions. Is there any way in DirectX or in Windows API that retrieve these informations about an image, or will I have to create a parser for each and every image file type I want to read? Thanks in advance...

Share this post


Link to post
Share on other sites
You can get the resolution of the back buffer from the IDirect3DDevice*, get the back buffer surface and then the surface details. You can get the size of a texture the same way.

As a word of advice, don't specify the position of controls in pixels, do it in percent accross the screen, then convert the mouse position. This is for the internal representation of pixels BTW, in script files you can specify how you want, so long as you convert. You can deal with differentresolutions more easily this way.

Share this post


Link to post
Share on other sites

Thanks for the quick reply... =)

It worked perfectly. This is what I've done, based on what you said:

 
IDirect3DTexture9* test;
D3DXCreateTextureFromFile(device, L"test.bmp", &test);
D3DSURFACE_DESC descriptor;
test->GetLevelDesc(0, &descriptor);
cout << descriptor.Width << ", " << descriptor.Width << endl;



With which image file types does this work with, btw?

Once again, thanks for your answer, it really helped a lot... (^^,)

Share this post


Link to post
Share on other sites
Quote:
DX SDK Article about D3DXCreateTextureFromFile
This function supports the following file formats: .bmp, .dds, .dib, .hdr, .jpg, .pfm, .png, .ppm, and .tga. See D3DXIMAGE_FILEFORMAT.


The SDK Docmentation is your friend. Use it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this