CattleRustler
Well-known member
I have converted the following C# tutorial (Craigs Turorials) into vb.net, here is the C#:
C#:
using System;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace DevelopMentor.Candera.Direct3D
{
public class Game : System.Windows.Forms.Form
{
static void Main()
{
Game app = new Game();
app.InitializeGraphics();
app.Show();
while (app.Created)
{
app.Render();
Application.DoEvents();
}
//app.DisposeGraphics();
}
private Device device;
private VertexBuffer vertices;
protected bool InitializeGraphics()
{
PresentParameters pres = new PresentParameters();
pres.Windowed = true ;
pres.SwapEffect = SwapEffect.Discard;
device = new Device(0, DeviceType.Hardware, this ,
CreateFlags.SoftwareVertexProcessing, pres);
vertices = CreateVertexBuffer(device);
return true ;
}
protected VertexBuffer CreateVertexBuffer(Device device)
{
device.VertexFormat =
CustomVertex.PositionColored.Format;
device.RenderState.CullMode = Cull.None;
VertexBuffer buf = new VertexBuffer(
typeof (CustomVertex.PositionColored), // What type of vertices
3, // How many
device, // The device
0, // Default usage
CustomVertex.PositionColored.Format, // Vertex format
Pool.Default); // Default pooling
CustomVertex.PositionColored[] verts =
(CustomVertex.PositionColored[]) buf.Lock(0, 0);
int i = 0;
verts[i++] = new CustomVertex.PositionColored(
0, 1, 0, Color.Red.ToArgb());
verts[i++] = new CustomVertex.PositionColored(
-0.5F, 0, 0, Color.Green.ToArgb());
verts[i++] = new CustomVertex.PositionColored(
0.5F, 0, 0, Color.Blue.ToArgb());
buf.Unlock();
return buf;
}
protected void SetupMatrices()
{
float angle = Environment.TickCount / 500.0F;
device.Transform.World = Matrix.RotationY(angle);
device.Transform.View = Matrix.LookAtLH( new Vector3(0, 0.5F, -3),
new Vector3(0, 0.5F, 0), new Vector3(0, 1, 0));
device.Transform.Projection =
Matrix.PerspectiveFovLH(( float )Math.PI/4.0F, 1.0F, 1.0F, 5.0F);
}
protected void Render()
{
// Clear the back buffer
device.Clear(ClearFlags.Target, Color.Bisque, 1.0F, 0);
// Ready Direct3D to begin drawing
device.BeginScene();
// Set the Matrices
SetupMatrices();
// Draw the scene - 3D Rendering calls go here
device.SetStreamSource(0, vertices, 0);
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
// Indicate to Direct3D that we