View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

# (Solved)Render 3D Triangle List

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

7 replies to this topic

### #1mcmonkey  Members

Posted 04 January 2013 - 07:56 PM

I want to render semi-dynamic 3D models... the built in Model class won't work.
So I thought I'd use a simple array of Vertices and render triangles from that...

I've looked all around the internet, and cannot figure out how to do it.

Here's what I'm currently trying:

        public static VertexPositionNormalTexture[] MapMesh = new VertexPositionNormalTexture[1];
public static void GenMesh()
{
MapMesh = new VertexPositionNormalTexture[3];
MapMesh[0].Position = new Vector3(-0.5f, -0.5f, 0f);
MapMesh[1].Position = new Vector3(0, 0.5f, 0.1f);
MapMesh[2].Position = new Vector3(0.5f, -0.5f, 0f);
}
public static void DrawMesh(GraphicsDevice device)
{
device.DrawUserPrimitives(PrimitiveType.TriangleList, MapMesh, 0, MapMesh.Length/3);
Models.drawmodel(Models.cube, new Vector3(-1, -1, -5), Vector3.Zero, Textures.textures[Console.constext], Vector3.One);
}

GenMesh is called once, DrawMesh is called in the Draw loop somewhere shortly after the code

// effect is a BasicEffect.
effect.View = (camera.ViewMatrix);
effect.Projection = (camera.ProjectionMatrix);
effect.World = (Matrix.Identity);
effect.TextureEnabled = true;
effect.Texture = Textures.White;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
}

the drawmodel(Models.cube bit is just so I can make sure I've pointed the camera at the right spot.

All I see is the cube, no triangle.

- Also, I have CullMode set to None.

What am I missing here?

### #2NewDisplayName  Members

Posted 04 January 2013 - 09:08 PM

Change this

public static VertexPositionNormalTexture[] MapMesh = new VertexPositionNormalTexture[1];
public static void GenMesh()
{
MapMesh = new VertexPositionNormalTexture[3];
MapMesh[0].Position = new Vector3(-0.5f, -0.5f, 0f);
MapMesh[1].Position = new Vector3(0, 0.5f, 0.1f);
MapMesh[2].Position = new Vector3(0.5f, -0.5f, 0f);
}
public static void DrawMesh(GraphicsDevice device)
{
device.DrawUserPrimitives(PrimitiveType.TriangleList, MapMesh, 0, MapMesh.Length/3);
Models.drawmodel(Models.cube, new Vector3(-1, -1, -5), Vector3.Zero, Textures.textures[Console.constext], Vector3.One);
}

to this :

public static VertexPositionNormalTexture[] MapMesh = new VertexPositionNormalTexture[3];
public static void GenMesh()
{
MapMesh[0].Position = new Vector3(-0.5f, -0.5f, 0f);
MapMesh[1].Position = new Vector3(0, 0.5f, 0f);
MapMesh[2].Position = new Vector3(0.5f, -0.5f, 0f);
}
public static void DrawMesh(GraphicsDevice device)
{
Models.drawmodel(Models.cube, new Vector3(-1, -1, -5), Vector3.Zero, Textures.textures[Console.constext], Vector3.One);
device.DrawUserPrimitives(PrimitiveType.TriangleList, MapMesh, 0, MapMesh.Length/3);
}

and then see if this helps.

### #3mcmonkey  Members

Posted 04 January 2013 - 10:18 PM

Thanks but it didn't help. The triangle is still invisible.

### #4mcmonkey  Members

Posted 07 January 2013 - 09:48 PM

Bump. Need help. I've no idea what's going wrong here.

### #5Such1  Members

Posted 07 January 2013 - 11:20 PM

try switching vertices 1 and 2 to see if the triangle isn't facing the other way.

### #6mcmonkey  Members

Posted 08 January 2013 - 06:28 PM

try switching vertices 1 and 2 to see if the triangle isn't facing the other way.

Nope. I have culling off.

### #7Zenix  Members

Posted 08 January 2013 - 09:02 PM

Hard to say what you're doing wrong without seeing the complete code.

I created a new XNA project, and added a triangle into the draw method and it displays fine.

My draw method looks like this:


</p><div> protected override void Draw(GameTime gameTime)</div>
<div>        {</div>
<div>            GraphicsDevice.Clear(Color.CornflowerBlue);</div>
<div> </div>
<div>            var verts = new VertexPositionNormalTexture[3];</div>
<div> </div>
<div>            verts[0].Position = new Vector3(-0.5f, -0.5f, 0.0f);</div>
<div>            verts[1].Position = new Vector3(0.0f, 0.5f, 0.0f);</div>
<div>            verts[2].Position = new Vector3(0.5f, -0.5f, 0.0f);</div>
<div> </div>
<div> </div>
<div>            var be = new BasicEffect(_graphics.GraphicsDevice);</div>
<div> </div>
<div>            foreach (var pass in be.CurrentTechnique.Passes)</div>
<div>            {</div>
<div>                pass.Apply();</div>
<div> </div>
<div>                _graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, verts, 0, 1);</div>
<div>            }</div>
<div> </div>
<div>            // TODO: Add your drawing code here);</div>
<div> </div>
<div>            base.Draw(gameTime);</div>
<div>        }</div>
<div>

### #8mcmonkey  Members

Posted 08 January 2013 - 11:16 PM

... Aaaand now I'm embarassed.

There was nothing wrong with my code - just I was expecting a white triangle, and got a triangle that's pitch black, same as that area's background. DIscovered this when I tried using a larger triangle.

(Thanks for trying to help though.)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.