#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();
}
}
}
[MDX] Going trough the tutorial..
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:
Thanks to thee who can explain why I don't see anything (that while this is almost 1-1 the tutorial).
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!
Add the following line of code directly above your vb.Unlock(); line in Initialize():
strm.Write(verts);
Recompile and run. Enjoy your triangle!
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement