cugone Posted June 14, 2008 Posted June 14, 2008 I'm having issues with sprite scaling in XNA. The original file is the size I want the various frames of the sprite sheet, but whenever I want the game engine to draw the texture it requests a "Uniform multiple to scale the height and width" or "a vector to scale the width and height by the x- and y- values". Problem is, telling it 1.0 scales by 100%, 0.0 scales it to 0, effectively erasing it, and scaling by 0.5 makes it roughly the size I want (not perfect), but BLURRY. :/ Any suggestions? Quote
Leaders snarfblam Posted June 20, 2008 Leaders Posted June 20, 2008 Yes, the scale you specify is a scaling factor, i.e. the size in texels is multiplied by the scale you specified to get the final size in pixels. If it is not 1.0 (100% scale) then the texture doesn't match the screen pixels 1 for 1 and has to be filtered. The default is usually linear filtering, which is medium quality. For higher quality, you could try changing the filter, like... deviceManager.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.GaussianQuad; Nearest neighbor (TextureFilter.None) would be the least blurry, but tends to look blocky. Quote [sIGPIC]e[/sIGPIC]
cugone Posted June 21, 2008 Author Posted June 21, 2008 Yes, the scale you specify is a scaling factor, i.e. the size in texels is multiplied by the scale you specified to get the final size in pixels. If it is not 1.0 (100% scale) then the texture doesn't match the screen pixels 1 for 1 and has to be filtered. The default is usually linear filtering, which is medium quality. For higher quality, you could try changing the filter, like... deviceManager.GraphicsDevice.SamplerStates[0].MagFilter = TextureFilter.GaussianQuad; Nearest neighbor (TextureFilter.None) would be the least blurry, but tends to look blocky. I'll go ahead and poke around with it, but as it stands, is there a way to tell it NOT to scale and just use what's there? (you know, like what DirectX does NORMALLY) Quote
Leaders snarfblam Posted June 22, 2008 Leaders Posted June 22, 2008 Do you want to scale the image? scaling by 0.5 makes it roughly the size I want If you specify a scale of 1.0 or use an overload that does not accept a scale the texture should be drawn at actual size and there will be no interpolation residue. Specifying a scale of 0.5 is telling XNA to scale and not just use what's there. How are you drawing the sprites? I'm assuming you are using the SpriteBatch class. Quote [sIGPIC]e[/sIGPIC]
cugone Posted June 22, 2008 Author Posted June 22, 2008 Do you want to scale the image? If you specify a scale of 1.0 or use an overload that does not accept a scale the texture should be drawn at actual size and there will be no interpolation residue. Specifying a scale of 0.5 is telling XNA to scale and not just use what's there. How are you drawing the sprites? I'm assuming you are using the SpriteBatch class. Yeah, I'm using a spritebatch. I need to specify an origin and a clipping rectangle (source rectangle in the documentation) because it's a sprite sheet. Due to that, I'm forced to specify a scale. I noticed when I just use the default definition of (texture, position, tint) it still draws (the entire) texture way larger than it should, and blurry. Quote
Leaders snarfblam Posted June 23, 2008 Leaders Posted June 23, 2008 Maybe you should post your calls to SpriteBatch.Draw. I'm not really sure what could be going wrong. It may be that there is some misunderstanding on how scale/origin/rotation works. I know it took my a lot of tinkering with them to get a good understanding of how to render sprites that properly rotate and scale with the correct source rectangle. I've been working on a game that uses sprite sheets for quite a while and haven't run into problems once I got things sorted out. I'm using a scale of 1.0 which renders as expected. Also, one thing that has caused me issues in the past (with MDX, but I don't think it matters) is changing my graphics card settings to override application settings (forcing anti-aliasing, mip-map levels, etc). Quote [sIGPIC]e[/sIGPIC]
cugone Posted June 30, 2008 Author Posted June 30, 2008 Well, that explains it. Apparently after writing a test case where I output all of my graphics device's capbilities "Powers of 2 Required" was true. Meaning I can only have textures that are square and a power of 2. :/ Nice of the documentation to actually EXPLAIN this. I had to read it from a reference book. :P Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.