Why are my images stretched? d3d 9

Started by
3 comments, last by death_entry 18 years, 3 months ago
I have set the screen size to be 640, 480, however the images come out elongated. The background image is 640 * 480 but it is stretched. I am using a 2d draw method. This is the original http://img.photobucket.com/albums/v308/death_entry/screen.jpg Tihs is from a screenshot of how it comes out http://img.photobucket.com/albums/v308/death_entry/screen2.jpg
Advertisement
When you load textures that aren't the power of 2, they will get stretched by Direct3D. It's always best to keep your textures to a power of 2 to avoid having to do other processing to get the correct resolution for your textures.

This screenshot shows the difference between the 2 textures (power of 2 and non-power of 2).


You can see a slight problem in quality of the non-power of 2 texture on the right hand side versus the texture on the left hand side. This might increase the more your texture is out of range.
Power of 2 compliant sizes are...
16 x 16, 32 x 32, 64 x 64, 128 x 128, 256 x 256 etc...
You can mix and match then as you see fit such as
16x256 and so forth.


I hope this helps.
Take care.
I might be wrong, but don't bad texture sizes result in squashed, not elongated, textures?

For example, a 499x512 texture is loaded by DirectX onto a 512x512 area. The extra 13 pixels in width is filled with alpha pixels, right? That means horizontal texture co-ordinates of 0.0 to 1.0 would be squashing all 512 pixels across into the space you expected to hold 499 pixels.

Texture elongation would happen because you've told DirectX to completely fill a particular area/surface you've given it, instead of telling it to display the texture as is. In D3D I would just suggest checking the size and texture co-ordinates of the quad you're rendering the texture to.. but since you're using a 2D draw method I can only say check the documentation for the function that draws the texture. Check to see if that function is meant to fill the entire area regardless of texture size. I haven't used any DirectDraw functions, so I'm afraid I can't help with which function that is exactly.
Try loading the image into an offscreen surface and then copy the surface to the backbuffer. Images in surfaces, unlike textures, don't have size restrictions.
my backbuffer is set to be 640 * 480. the image im using is also 640*480 (so I shouldn't have an issue with the power of 2 thing) so how is it being stretched to greater then the backbuffer? The image is meant to be a background and to fill the whole area, but it's being stretched over it :S


Quote:
mdlOptions.sprite.Draw2D(background, backRotation, 0, backRectangle.Location, Color.White)

background = TextureLoader.FromFile(mdlOptions.DDevice, Application.StartupPath & "/Images/Backgrounds/nightandmountains.png")




Quote:
Module mdlOptions
Public Const ScreenWidth As Integer = 640
Public Const ScreenHeight As Integer = 480
Public device As device = Nothing
Public sprite As sprite

Public ReadOnly Property DDevice() As device
Get
Return device
End Get
End Property


Public Sub InitializeGraphics(ByVal form As Form)
' Set our presentation parameters
Dim presentParams As New PresentParameters

presentParams.SwapEffect = SwapEffect.Discard

' Start up full screen
Dim current As Format = Manager.Adapters(0).CurrentDisplayMode.Format

If Manager.CheckDeviceType(0, DeviceType.Hardware, current, current, False) Then
' Perfect, this is valid
presentParams.Windowed = True
presentParams.BackBufferFormat = current
presentParams.BackBufferWidth = ScreenWidth
presentParams.BackBufferHeight = ScreenHeight
Else
presentParams.Windowed = True
End If
' Create our device
device = New device(0, DeviceType.Hardware, form, CreateFlags.SoftwareVertexProcessing, presentParams)



End Sub 'InitializeGraphics

This topic is closed to new replies.

Advertisement