Jump to content
  • Advertisement
Sign in to follow this  
LycaonX

DirectX Sprite Class gotcha? Getting stretched textures

This topic is 3669 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

I've got a 360x1152 bitmap (borrowed from the game Continuum) that I'm using to dabble in 2D. According to the tooltip on the Draw method of the Sprite class: Parameters: srcTexture: A Microsoft.DirectX.Direct3D.Texture object that represents the sprite texture. srcRectangle: A System.Drawing.Rectangle object that indicates the portion of the source texture to use for the sprite. Specify System.Drawing.Rectangle.Empty to use the entire source image for the sprite. center: A Microsoft.DirectX.Vector3 structure that identifies the center of the sprite. A value of (0,0,0) indicates the upper-left corner. position: A Microsoft.DirectX.Vector3 structure that identifies the position of the sprite. A value of (0,0,0) indicates the upper-left corner. color: A System.Drawing.Color structure. The color and alpha channels are modulated by this value. The System.Drawing.Color value maintains the original source color and alpha data. And here's the code:
Dim src As New Rectangle(0, 0, 36, 36)
Dim dst As New Vector3(512, 384, 0)
Dim cntr As New Vector3(18, 18, 0)

m_Sprite.Begin(SpriteFlags.None)
m_Sprite.Draw(m_Texture, src, cntr, dst, Color.White)
m_Sprite.End()
Each ship frame is 36x36, and my source rectangle reflects that. However, when I .Draw the sprite section to the screen, it draws what appears to be a 32x32 section of the source texture instead of 36x36, as seen here: example image As you might be able to see, it's missing the rest of the texture on the right and bottom side, as if it's being stretched bigger than the destination rectangle. I actually opened the image above in Paint and it's definitely 36x36, so the class is drawing the texture to the destination rectangle. I have not set up any camera-related matrices yet (world, view, projection). Is my problem a bug in the Sprite class, a misunderstanding of the parameters on my part, or my failure to set up proper camera matrices? [Edited by - LycaonX on November 26, 2008 4:37:15 PM]

Share this post


Link to post
Share on other sites
Advertisement
When you load in your texture you'll need to specify that you don't want it stretched to a power-of-2 size. Some older GPU's don't support non-power-of-2 textures, so they may get stretched anyway.

Also...it looks like you're using Managed DirectX. FYI, Managed DirectX is no longer supported or updated. You may want to check out the XNA Framework (which on the PC provides a wrapper for D3D9), or the community-supported SlimDX which wraps both D3D9 and D3D10.

Share this post


Link to post
Share on other sites
Thanks a ton, that was the problem :)

And yep, I'm messing with MDX. I just haven't bothered to check out XNA yet.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!