Solved

Finding the Width of a DirectX 9 Texture

Posted on 2004-04-05
4
1,091 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Where to Market / Sell your Game. 2 733
Tetris download for windows 7 17 167
Recording what a camera sees for future playback. 5 40
Fibonacci challenge 11 108
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now