views:

1573

answers:

2

Hello I'm having trouble rendering correctly sprite with SlimDX. It draws a little scaled just like .NET Drawing DrawImageUnscaled does. I'm not using any transformations.

Init:

Vector2 position;
Sprite sprite;
Size size;
Texture texture;
sprite = new Sprite(Device);
string filename = /*some bitmap*/;
using (Image b = Bitmap.FromFile(filename))
  size = b.Size;

position = new Vector2(550, 230);
texture = Texture.FromFile(Device, filename);

Rendering:

Device.Clear(ClearFlags.Target, Color.Black, 1.0f, 0);
Device.BeginScene();
sprite.Begin(SpriteFlags.None);
sprite.Draw(texture, new Vector3(size.Width / 2, size.Height / 2, 0), new Vector3(position, 0), Color.White);
sprite.End();
Device.EndScene();

EDIT: If you don't know how to imagine the wrong rendering, here is what I get rendered and reference (ignore that white color, it's just transparent PNG). Notice how the first image is scaled Wrong Correct

+3  A: 

Is it possible that your graphic card has problems drawing NPOT-textures (non-power of two). If so, increase the texture size to the next POT. This resolved many drawing issues for me (using SlimDX too).

Btw...I also used SlimDX for 2D rendering, but haven't made use of sprites, but draw all the things as "primitives" and using a vertex buffer. Maybe this could also be an option

Scoregraphic
+1  A: 

Add alpha blend when initializing the sprite.