D3D newbie question - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

D3D newbie question

Hi!

I am trying to learn D3D, mostly by looking at tutorials, sample projects etc...

I have made a render function, trying to render a simple triangle. It compiles and runs ok, but there is no triangle, only the black background color!? It is probably just a tiny thing I've forgotten, but I am just not able to figure out what I've forgotten! Any help is greatly appreciated!

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

device.BeginScene();

CustomVertex.PositionColored[] vert = new CustomVertex.PositionColored[3];
vert[0].X = -1.0f; vert[0].Y = -1.0f; vert[0].Z = 0.0f; vert[0].Color = Color.Blue.ToArgb();
vert[1].X = 1.0f; vert[1].Y = -1.0f; vert[1].Z = 0.0f; vert[1].Color = Color.Blue.ToArgb();
vert[2].X = 0.0f; vert[2].Y = 1.0f; vert[2].Z = 0.0f; vert[2].Color = Color.Blue.ToArgb();

VertexBuffer vb = new VertexBuffer(typeof(CustomVertex.PositionColored), vert.Length, device, Usage.None, CustomVertex.PositionColored.Format, Pool.Managed);
GraphicsStream stm = vb.Lock(0, 0, 0);
stm.Write(vert);

vb.Unlock();

device.SetStreamSource(0, vb, 0);
device.VertexFormat = CustomVertex.PositionColored.Format;
device.DrawPrimitives(PrimitiveType.TriangleList, 0, 1);
device.EndScene();
device.Present();
}

Comments

  • drmedicodrmedico Posts: 2Member
    Solved it....

    Basically just reversed the order of the vertix coords...

    vert[0].X = 1.0f; vert[0].Y = -1.0f; vert[0].Z = 0.0f; vert[0].Color = Color.Blue.ToArgb();
    vert[1].X = -1.0f; vert[1].Y = -1.0f; vert[1].Z = 0.0f; vert[1].Color = Color.Blue.ToArgb();
    vert[2].X = 0.0f; vert[2].Y = 1.0f; vert[2].Z = 0.0f; vert[2].Color = Color.Blue.ToArgb();
Sign In or Register to comment.