Sign in to follow this  
Grantyt3

Red X Error?

Recommended Posts

I'm trying to display a sprite with Direct3D sprite class. It compiles fine, but when it runs, I get this: Here is the code(ps. this will eventually, hopefully, be a tetris remake, so that's the reason for stuff:)
sing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

public class Engine : System.Windows.Forms.Form
{
	private Device dev = null;
	private Texture block;
	public Texture HUD;
	public Engine eng = null;
	
	private System.ComponentModel.Container components = null;

	public Engine()
	{
		InitializeComponent();

		this.Setstyle(Controlstyles.AllPaintingInWmPaint | Controlstyles.Opaque, true);
		this.Text = "Zetrix";
	}

	protected override void Dispose( bool disposing )
	{
		if( disposing )
		{
			if (components != null) 
			{
				components.Dispose();
			}
		}
		base.Dispose( disposing );
	}

	public static void Main() 
	{
		using(Engine eng = new Engine())
		{
			eng.Show();
			eng.InitializeGraphics();
			Application.Run(eng);
		}
		Application.Exit();
	}

	private void InitializeGraphics() 
	{
		try 
		{
			PresentParameters presentParams = new PresentParameters();
			presentParams.Windowed = true;
			presentParams.SwapEffect = SwapEffect.Discard;
			presentParams.BackBufferFormat = Format.Unknown;
			presentParams.AutoDepthStencilFormat = DepthFormat.D16;
			presentParams.EnableAutoDepthStencil = true;

			// Store the default adapter
			int adapterOrdinal = Manager.Adapters.Default.Adapter;
			CreateFlags flags = CreateFlags.SoftwareVertexProcessing;

			// Check to see if we can use a pure hardware device
			Caps caps = Manager.GetDeviceCaps(adapterOrdinal, DeviceType.Hardware);

			// Do we support hardware vertex processing?
			if (caps.DeviceCaps.SupportsHardwareTransformAndLight)
				// Replace the software vertex processing
				flags = CreateFlags.HardwareVertexProcessing;
            
			// Do we support a pure device?
			if (caps.DeviceCaps.SupportsPureDevice)
				flags |= CreateFlags.PureDevice;

			dev = new Device(0, DeviceType.Hardware, this, flags, presentParams);
			dev.DeviceReset += new System.EventHandler(this.OnResetDevice);
			OnResetDevice(dev, null);
		}
		catch (DirectXException) 
		{
			// Catch any errors and return a failure
		}
	}

	private void LoadTextures() 
	{
		block = TextureLoader.FromFile(dev,"txblock.bmp", 20, 20, 
			1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000)));

		HUD = TextureLoader.FromFile(dev,"HUD.bmp", 200, 600,
			1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000)));
	}

	public void OnResetDevice(object sender, EventArgs e) 
	{
		Device device = (Device)sender;
		device.RenderState.CullMode = Cull.None;
		device.RenderState.Lighting = false;

		LoadTextures();
	}

	protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) 
	{
		dev.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black, 1.0f, 0);

		dev.BeginScene();

		Rectangle rect = new Rectangle(0,0,200,600);

		Vector3 spriteCenter = new Vector3( 0.0f, 0.0f, 0.0f );
		Vector3 spritePosition = new Vector3(0.0f,0.0f,0.0f);

		using (Sprite s = new Sprite(dev)) 
		{
			s.Begin(SpriteFlags.AlphaBlend);
			s.Draw(HUD, rect, spriteCenter, spritePosition, Color.FromArgb(255,255,255,255));
			s.End();
		}
		
		dev.EndScene();

		dev.Present();

		this.Invalidate();
	}

	private void InitializeComponent()
	{
		// 
		// Form1
		// 
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.ClientSize = new System.Drawing.Size(800,600);
		this.Name = "Form1";
		this.Text = "Form1";
	}



}


Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this