# How to draw non-triangulated mesh?

I am working with DirectX (C#/C++). I am wondering is it possible to do not triangulate meshes and what the difference between cases (in loading and rendering code)? If so, how to do this? I know DrawIndexed requires primitive_topology to be set - which value should I use then? I always used triangulated mesh before with no problems but it is interesting..

• Look up Geometry Shaders. There are the only effective way to draw non-triangulated meshes. Then again, you're more of generating them on the GPU side rather than "drawing" a mesh that you've previously created. – Thebluefish Mar 1 '14 at 17:30
• Thanks! Ill try them after finishing with learning PS/VS. – Croll Mar 1 '14 at 23:22

Using directx you must draw triangle meshes. If your mesh data contains quads, then create an index buffer that indexes each quad as two triangles and draw by calling DrawIndexed. For example if you have vertex1,vertex2,vertex3,vertex4 which describes a quad then index them by 0,1,2,0,2,3 or according to the desired winding order.

• So i have to triangulate vertices anyway. Nice. – Croll Feb 27 '14 at 19:48
• @DmitrijA - That's the way GPU hardware works, and DX doesn't pretend that other primitive types exist, so yes, you're stuck with triangles. – Maximus Minimus Feb 27 '14 at 19:58

Do you mean draw stuff like cubes, rectangles.. etc?

It´s easy!

Per example for a rectangle (square or something with 4 vertices) :

CUSTOMVERTEX Dirt[] =
{
{ 0.0f, 600.0f, 0.0f,  1.0f, D3DCOLOR_XRGB(221, 216, 148), },
{ 700.0f, 600.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(221, 216, 148), },
{ 0.0f, 700.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(221, 216, 148), },
{ 700.0f, 700.0f, 0.0f, 1.0f, D3DCOLOR_XRGB(221, 216, 148), },
};


instead of having only 3 vertices

then d3ddev->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX), 0, CUSTOMFVF, D3DPOOL_MANAGED, &v_buffer, NULL); instead of 3 * sizeof....

and atlast : d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); instead of D3DPT_TRIANGLELIST and change the uiPrimitiveCount to 2...

It also explains cubes and stuff...

Sorry if I didnt helped much