Re: Sprite.Draw draws differently on different computers
- From: "Robert Dunlop [MS MVP]" <rdunlop@xxxxxxxx>
- Date: Mon, 16 May 2005 05:11:21 -0700
I'm not sure I follow what's going on with your Clone() code, but from what
I see this looks like a problem with rescaling of the sprite.
I would suspect that the machines that are exhibiting the problem do not
support textures with non-power-of-two dimensions. The texture loader will
create a power-of-two dimensioned texture on such devices, using the next
power of two on each dimension if the loaded image doesn't conform to the
requirements of the device. It will also scale up to a square texture if
the device requires this.
When scaling is required, the filter flags passed to the texture loading
function determine the scaling algorithms used for rescaling. You are
specifying filter type 'None', which will cause the original image to be
copied unscaled to the upper left corner of the texture and the remaining
space to be filled with black.
I don't have enough information in the code snippet and image to determine
for sure what the original sprite size file is and what the dimensions of
the rects are, but I assuming that the images presented are a 5x blowup of
the rendered image, with dimensions of 250x250. As a test, in Photoshop I
expanded the canvas of the 'good' image to 256x256 and black filled the
remainder in the same manner as the 'None' filter would do. I then resized
the image down to 64x64 and back up to 250x250, and get almost identical
results to what you show in your 'bad' image.
After you load the texture you are retrieving the dimensions of the texture,
which would be the increased size of the texture rather than the original
image size. You can use the FromFile method that returns an
ImageInformation class to find the original size of the image. Using the
'None' filter is appropriate where you want to load images that may get
resized during texture creation, because it won't cause any blending of the
original pixels. However, you need to be sure to use the original image
size for your source rectangle when accessing the texture, otherwise you'll
also be including the black pixels that were filled by the loader.
One other possible cause is texel center alignment, which although
standardized there are some drivers that let the user to tweak them from the
default settings. I mention this because the same results would likely be
seen with bilinear filtering if the texel centers were mis-aligned from the
pixels by half a pixel.
--
Robert Dunlop
The X-Zone
http://www.directxzone.com/
Microsoft DirectX MVP
-------------
The opinions expressed in this message are my own personal views and do not
reflect the official views of the Microsoft Corporation.
The MVP program does not constitute employment or contractual obligation
with Microsoft.
"AlexGray" <grayaii@xxxxxxxxxxx> wrote in message
news:1116191564.670913.157870@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I'm writing a 2D, tile based role playing game, and everything seems to
> be drawn fine except on a handful of computers. On these computers,
> the rendering looks "fuzzy", and even worse, the bottom and right side
> of the "tile" is a dark line. I have all my tiles on a master bmp
> file, and i use .Clone() to extract what i want, but it's not being
> displayed as crisp as it should.
> I attached a screenshot of what i'm talking about.
>
> It's a windowed game (not full screen) and i create the Device rather
> simply:
>
> Code To Create the Device:
> PresentParameters presentParams = new PresentParameters();
> presentParams.Windowed=true;
> presentParams.SwapEffect = SwapEffect.Discard;
> presentParams.BackBufferFormat =
> Microsoft.DirectX.Direct3D.Format.Unknown;
> this.device = new Microsoft.DirectX.Direct3D.Device(0,
> DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing,
> presentParams);
>
> this.imageSprite = new Sprite(device);
>
> Code to Render:
> this.imageSprite.Begin(SpriteFlags.AlphaBlend);
> // Draw everything to the sprite via the function:
> // sprite.Draw(this.m_SpriteTexture, sourceRect, Center, m_Position,
> Color.White);
> this.imageSprite.End();
>
> Code to Create a Sprite that will be drawn:
> m_SpriteTexture = TextureLoader.FromFile(device,
> FileName,0,0,0,0,Format.A8B8G8R8,Microsoft.DirectX.Direct3D.Pool.Managed,Filter.None,Filter.None,Color.FromArgb(0,255,0).ToArgb());
> Surface s = m_SpriteTexture.GetSurfaceLevel(0);
> SurfaceDescription desc = s.Description;
> m_TextureSize = new Rectangle(0, 0, desc.Width, desc.Height);
>
> this.m_TileImage =
> GlobalBitmaps.WORLD_TILES.Clone(rect,GlobalBitmaps.WORLD_TILES.PixelFormat);
> this.m_TileSurface =
> Surface.FromBitmap(device,GlobalBitmaps.WORLD_TILES.Clone(rect,GlobalBitmaps.WORLD_TILES.PixelFormat),0);
>
> Here's a screenshot, side by side, of a display that works and a
> display that doesn't:
> http://www.graycoresoftware.com/Downloads/ScreenShot.bmp
>
> I've tried all sorts of paths, like creating the device differently etc
> etc, but it seems the drawing is done differently on different
> computers.
>
> Any ideas where i should even start looking? Someone suggested
> "Anti-Alias", but how do i disable Anti-Alias when rendering graphics?
> -alex-
>
.
- Follow-Ups:
- Re: Sprite.Draw draws differently on different computers
- From: Shane S. Anderson
- Re: Sprite.Draw draws differently on different computers
- References:
- Sprite.Draw draws differently on different computers
- From: AlexGray
- Sprite.Draw draws differently on different computers
- Prev by Date: Re: rotating camera around origin
- Next by Date: Re: CPU performance rises when I'm opening an other application/dialog
- Previous by thread: Sprite.Draw draws differently on different computers
- Next by thread: Re: Sprite.Draw draws differently on different computers
- Index(es):
Relevant Pages
|