[C#] Direct3D Sprites & Textures, 2D

mrnugger

Member
Joined
Aug 20, 2006
Messages
6
I just started C# recently and Ive been wanting to display a simple .bmp image on the window. I have managed to do this already but the size of the image is modified and made big when rendered :S, any way to specify the dimensions and also area of the image(frames)?

here is my current code:
Code:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

class WinForm : Form
{
    public Device device;
    public PresentParameters presentParams;
    public Texture texture;

    WinForm()
    {
        this.Text = "DirectX Project";
        this.Width = 600;
        this.Height = 200;
        this.Show();
    }

    public static void Main()
    {
        Console.WriteLine("Program Executed");

        using (WinForm form = new WinForm())
        {
            form.InitializeGraphics();
            Application.Run(form);
        }
    }

    public void InitializeGraphics()
    {
        presentParams = new PresentParameters();
        presentParams.Windowed = true;
        presentParams.SwapEffect = SwapEffect.Discard;

        device = new Device(0, DeviceType.Hardware, this, CreateFlags.HardwareVertexProcessing, presentParams);

        texture = TextureLoader.FromFile(device, "image.bmp");
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        Render();
    }

    public void Render()
    {
        device.Clear(ClearFlags.Target, Color.Blue, 1.0f, 0);
        device.BeginScene();

        using (Sprite s = new Sprite(device))
        {
            s.Begin(SpriteFlags.AlphaBlend);
            s.Draw2D(texture, new Point(0, 0), 0f, new Point(0, 0), Color.White);
            s.End();
        }

        device.EndScene();
        device.Present();
    }
}
 
Back
Top