0
\$\begingroup\$

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..

\$\endgroup\$
  • \$\begingroup\$ 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. \$\endgroup\$ – user39686 Mar 1 '14 at 17:30
  • \$\begingroup\$ Thanks! Ill try them after finishing with learning PS/VS. \$\endgroup\$ – Croll Mar 1 '14 at 23:22
4
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ So i have to triangulate vertices anyway. Nice. \$\endgroup\$ – Croll Feb 27 '14 at 19:48
  • \$\begingroup\$ @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. \$\endgroup\$ – Maximus Minimus Feb 27 '14 at 19:58
1
\$\begingroup\$

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...

Source : http://www.directxtutorial.com/Lesson.aspx?lessonid=9-4-7

It also explains cubes and stuff...

Sorry if I didnt helped much

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.