To fix the problem, you need to multiply the x and y positions of your sprites by the texture width divided by the the new height.
Private Sprites As New Queue
Private Structure Sprite_Type
Dim tex As Texture
Dim x, y, width, height As Integer
Dim c As Color
End Structure
Public Sub Draw_Sprites()
If Sprites.Count = 0 Then Return
Dim s As New Sprite(VideoDevice)
s.Begin(SpriteFlags.AlphaBlend)
While Sprites.Count > 0
Dim sp As Sprite_Type = DirectCast(Sprites.Dequeue, Sprite_Type)
Dim xmult As Single = sp.tex.GetSurfaceLevel(0).Description.Width / sp.width
Dim ymult As Single = sp.tex.GetSurfaceLevel(0).Description.Height / sp.height
s.Draw2D(sp.tex, Rectangle.Empty, New Rectangle(sp.x, sp.y, sp.width, sp.height), New Point(0, 0), 0, New Point(sp.x * xmult, sp.y * ymult), sp.c)
End While
s.End()
s.Dispose()
End Sub
I know that my code isn't following the .NET Framework Naming Guidelines. This is merely a test app that I'm throwing together to make sure that I can work out my rendering issues before I go full-bore into my next project.
4 comments:
Thank you thank you! I've spent hours this morning trying to figure this out!
I managed to fix it with your code example but I'm still not sure what's happening. Would it be possible to give more details if you can still remember?
The texture itself is stored as a power of two image - no matter what the filesize is that it's loaded from.
You can use the destination rectangle parameter to squash it back to the dimensions you wished for. The problem comes with the position . . . I don't really understand this bit - is it still rendering using the co-ordinates of the power of 2 texture?
This bit confuses me :D I wish I had a better head for maths!
What is the problem you are having?
Thank you!
I wonder - I'm just starting out with DX today, and I don't know where the Matrix scaling would appear in the code you posted?
SarahC,
The third parameter is the destination rectangle: the area on the screen that it's going to draw it.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms881037.aspx
Post a Comment