Re: Sprite.Draw draws differently on different computers

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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-
>


.



Relevant Pages

  • Re: Sprite.Draw draws differently on different computers
    ... anti-aliases, regardless of the texture. ... > I see this looks like a problem with rescaling of the sprite. ... the filter flags passed to the texture loading ... >> be drawn fine except on a handful of computers. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: ID3DXSprite::Draw screen image doesnt match texture???
    ... If you're using D3DX for loading the texture, ... function that stretched the dimensions to powers of two. ... > I am displaying a sprite from a .tga file thats 32 bit with alpha channel ... My laptop display runs 1400x1050. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • About implementing 2D Sprites
    ... This interface works with textures created by the ... have power of two dimensions. ... Using the D3DX_FILTER_NONE parameter to filter ... texture in 2D screen space, but as no filter is effectively applied, scaling ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Problems with drawing scaled texture ID3DXSprite
    ... Due to the fact Textures in D3D are created from bitmaps rounding their ... dimensions to power of two, I'm using a matrix passed to the ... D3DXMatrixScalingfunction to adjust texture's dimensions to the original ... Then I obtain the created texture ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: creating a non-power of 2 size texture
    ... Have you tried explicitly specifying the dimensions in your call to ... D3DXCreateTextureFromFileEx() that it would not create a non-pow2 ... operations you will be performing with the texture. ... > What I'm trying to do is to load a image file ...
    (microsoft.public.win32.programmer.directx.graphics)