Jump to content
  • Advertisement
Sign in to follow this  
Sijmen

[MDX] Going trough the tutorial..

This topic is 4906 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Currently I'm trying to work trough the Managed Direct3D tutorial from MSDN (besides having read some stuff from other sites, of which I've got the links from very kind people over here), but I don't see any polygons. Here is the code. Direct3D was initialized (I can see the gray cleared color) but I have the idea that the drawn polyons are not in view range:
#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

using System.Drawing;
using System.Windows.Forms;

using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

#endregion

namespace D3DTest
{
	public class GameForm : Form
	{
		Device device;
		VertexBuffer vb;

		public GameForm()
		{
			Text = "Sijmen's Direct3D test!";
			FormBorderStyle = FormBorderStyle.FixedDialog;
			MaximizeBox = false;
			ClientSize = new Size(800, 600);
			BackgroundImage = new Bitmap("../loading.png");
			Show();
		}

		public void Initialize()
		{
			PresentParameters pp = new PresentParameters();
			pp.Windowed = true;
			pp.SwapEffect = SwapEffect.Discard;

			device = new Device(0, DeviceType.Hardware, this, 
				CreateFlags.SoftwareVertexProcessing, pp);
			vb = new VertexBuffer(typeof(CustomVertex.TransformedColored), 3, device, 0,
				CustomVertex.TransformedColored.Format, Pool.Default);
			
			GraphicsStream strm = vb.Lock(0, 0, 0);
			CustomVertex.TransformedColored[] verts = new CustomVertex.TransformedColored[3];

			verts[0].X = 150; 
			verts[0].Y = 50; 
			verts[0].Z = 0.5f; 
			verts[0].Rhw = 1;
			verts[0].Color = Color.Aqua.ToArgb();

			verts[1].X = 250; 
			verts[1].Y = 250; 
			verts[1].Z = 0.5f;
			verts[1].Rhw = 1;
			verts[1].Color = Color.Brown.ToArgb();

			verts[2].X = 50;
			verts[2].Y = 250;
			verts[2].Z = 0.5f;
			verts[2].Rhw = 1;
			verts[2].Color = Color.LightPink.ToArgb();

			vb.Unlock();

			BackColor = Color.Black;
			BackgroundImage = null;
		}

		public void Render()
		{
			if(device==null)
				return;

			device.Clear(ClearFlags.Target, Color.Gray, 1.0f, 0);
			device.BeginScene();

			device.SetStreamSource(0, vb, 0);
			device.VertexFormat = CustomVertex.TransformedColored.Format;
			device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);

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

		public void DoFrame()
		{
			Render();
		}

		public void Run()
		{
			while(Created)
			{
				DoFrame();
				Application.DoEvents();
			}
		}

		public void Finish()
		{
			vb.Dispose();
			device.Dispose();
		}
	}

	public class Program
	{
		public static void Main()
		{
			GameForm game = new GameForm();

			game.Initialize();
			game.Run();
			game.Finish();
		}
	}
}

Thanks to thee who can explain why I don't see anything (that while this is almost 1-1 the tutorial).

Share this post


Link to post
Share on other sites
Advertisement
So close! You are missing one line of code... You've forgotten to copy your verts into your GraphicsStream! :-)

Add the following line of code directly above your vb.Unlock(); line in Initialize():

strm.Write(verts);

Recompile and run. Enjoy your triangle!

Share this post


Link to post
Share on other sites
Quote:
Original post by C4KE
So close! You are missing one line of code... You've forgotten to copy your verts into your GraphicsStream! :-)

Add the following line of code directly above your vb.Unlock(); line in Initialize():

strm.Write(verts);

Recompile and run. Enjoy your triangle!


Awesome man, thanks!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!