Solved

Finding the Width of a DirectX 9 Texture

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

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
Comment Utility
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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

743 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

15 Experts available now in Live!

Get 1:1 Help Now