Solved

Finding the Width of a DirectX 9 Texture

Posted on 2004-04-05
4
1,096 Views
Last Modified: 2013-12-08
I've written a graphics engine for a 2d game using the DirectX 9 'Sprite' system.
I simply need to know how to find the widths of strangely dimensioned textures during runtime (eg 80x60, 400x120, etc...)
0
Comment
Question by:TimNyborg
  • 2
  • 2
4 Comments
 
LVL 1

Expert Comment

by:Croow
ID: 10767309

It sounds like you can solve this with the GetLevelDesc method.

LPDIRECT3DTEXTURE9 pTexture;

      D3DSURFACE_DESC desc;
      pTexture->GetLevelDesc(0,&desc);
      int width = desc.Width;
      int height = desc.Height;


The D3DSURFACE_DESC structure has a lot of other members, but I doubt they'd be very helpful to you.

Good luck
0
 

Author Comment

by:TimNyborg
ID: 10770109
I've tried that method, but level 0's width and height are converted to powers of 2, equal to or greater than the original dimensions

ie 40x80 becomes 64x128
Is there
0
 

Author Comment

by:TimNyborg
ID: 10770145
whoops

*Is there a way to keep the original size? As far as I can tell, the textures are being expanded to meet 2^n sizes, but that doesn't matter when you go to draw them as sprites, because the extra area is transparent

I just need to find the centers of the actual original image so I can place image on top
0
 
LVL 1

Accepted Solution

by:
Croow earned 125 total points
ID: 10770451
Well then give this a try ...


      if(SUCCEEDED(D3DXCreateTextureFromFile(pDevice,pSrcFile,&pTexture)))
            bTexLoaded = true;

       D3DXIMAGE_INFO info;
       hr = D3DXGetImageInfoFromFile(pSrcFile,&info);

       int width = info.Width;
       int height = info.Height;
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question