Jump to content
  • Advertisement
Sign in to follow this  
Pseelo

[SlimDX] Texture.FromFile question

This topic is 3609 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I use sprites to draw images. I load a texture and simply use sprite.Draw method. I think that something's wrong with the Texture.FromFile method. Sometimes textures are exactly the same as viewed in an image browser, but sometimes they are stretched in height and/or width (two times larger). That's even worse now. I've just completed a tooltip background for my app and the image is not only twice as high as the original, but there are also two horizontal lines at the top of if, which I surely didn't draw. The image was created in Photoshop 7 and exported via Save for Web. The slice I'm talking about looks like this. the top of a tooltip The question is: what can I do to load textures correctly - in other words to be 100% sure that the effect in my app is the same as in an image browser soft? [Edited by - Pseelo on November 30, 2008 5:00:07 AM]

Share this post


Link to post
Share on other sites
Advertisement
Some older hardware had a requirement that textures have dimensions that are power-of-two. Newer hardware usually supports non-power-of-two textures, but sometimes has limitations on what you can do with them.

The easiest way to avoid this effectively, would be to create the textures at power-of-two dimensions. That is, if your texture is 230x470, make is 256x512, and leave the rest of it blank. Then, in your application, you'll need to somehow know the texture's actual size, and pass that value to the Sprite's Draw method, and only the "real" part of the texture will be used.

Another option you have is to leave textures at their current size, and ask DX to try and load them as non-power-of-two textures. You request this by passing a special value for the texture width and height (I don't have the SDK docs here, but it should be in the documentation somewhere). If you do this, results should probably be good on most hardware you'll encounter, but with older hardware, this might fail or cause other issues.

While the second method doesn't waste memory, I'd recommend you use the first, if possible, since it will keep things working on nearly any hardware, with no special-case paths. Of course, if you have many textures that are 513 pixels long, memory waste might quickly become an issue.

Hope this helps.

Share this post


Link to post
Share on other sites
Hi.
Thanks for the clue, Sirob.
I made some experiments with the power-of-two images and my conslusions are:
- the tooltip with the canvas resized to 256x256 (from 238x42) is drawn correctly;
- there are some images I have that are drawn correctly having strange resolutions (non-pow2) (e.g. 60x59), so there is no 100% rule that only "power-of-two" images are ok.

OK. Maybe I just started from the wrong side.
Let's say I want to display a 2D image in DirectX. What else can I use except a textured sprite?

And can anybody solve the Texture.FromFile problem? Or is it really like Sirob suspects - there is no guarantee that images which at least one dimension is not a power of two will be displayed correctly?

// edit:
I've just read some articles about power-of-two textures. Hence the next question - how to read texture from file and giving its real resolution not to be stretched to the closest power of 2 (by means of SlimDX, of course - I see how it can be done with the pure DirectX)?

Regards.
Chris.

[Edited by - Pseelo on November 30, 2008 4:03:20 PM]

Share this post


Link to post
Share on other sites
OK. Two things.

First - I wrote that some images wasn't stretched. That's obviously not true. I took a closer look at them and found out they were resized actually, but the change was too small to recognize (60 pixels to 64 pixels). So it is now clear to me, that my hardware accepts only power-of-two textures and I stick to this rule.

Second - I don't see any way to pass resolution parameters to the Texture.FromFile method, but the solution is simple. I just load all slices stacked up in one big power-of-two texture and draw them passing the source rectangle parameter. I suppose that closes my newbie circular thinking - one more time I've reinvented the wheel, huh?

Thank you for your help, Sirob.
Chris.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!