1

I have a problem when I try to use D3DPT_TRIANGLELIST. The following sample is from a book, so I don't see what the problem can be.

VertexData:

ColorVertex *v;

Triangle->Lock(0,0,(void**)&v,0);

v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0,0));
v[1] = ColorVertex(0.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0,255,0));
v[2] = ColorVertex(1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0,0,255));

Triangle->Unlock();

Drawing function:

Device->SetFVF(ColorVertex::FVF);
Device->SetStreamSource(0,Triangle,0,sizeof(ColorVertex));

D3DXMatrixTranslation(&World,-1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&World);

Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

D3DXMatrixTranslation(&World,1.25f,0.0f,0.0f);
Device->SetTransform(D3DTS_WORLD,&World);

Device->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

Device->EndScene();
Device->Present(0,0,0,0);

However, if I change from D3DPT_TRIANGLELIST to for example D3DPT_LINELIST it draws a line. If I use D3DPT_POINTLIST it only draws one point (pixel) for each of the DrawPrimite-calls.

Thanks for any help!

user1118321
  • 25,567
  • 4
  • 55
  • 86
Araw
  • 2,410
  • 3
  • 29
  • 57

2 Answers2

0

Your vertex coordinates don't form a triangle, they are three points in a line.

jcoder
  • 29,554
  • 19
  • 87
  • 130
  • Thanks for your reply. But the ColorVertex is a struct, and since I pass all the values inside it should it then set x, y, z and the color for 3 different point. Together they form a triangle when the application draws a line between them? – Araw Jul 20 '12 at 21:41
  • YEs, sorry I didn't reply to this very quickly, but it looks like you figured out what I meant – jcoder Jul 24 '12 at 14:48
0

Well, after working around I found the MISTAKE(!), good practice for newbies. It was in front of me all the time, and it is in the coordinates:

v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0,0));
v[1] = ColorVertex(0.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0,255,0));
v[2] = ColorVertex(1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0,0,255));

This can't form a triangle as the Y-coordinate newer changes for any of the vertexes. Of course it is possible to draw lines and points as they don't need a Y-coordinate to form there specifications. So a solution is for example:

v[0] = ColorVertex(-1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(255, 0,0));
v[1] = ColorVertex(0.0f, 1.0f, 2.0f, D3DCOLOR_XRGB(0,255,0));
v[2] = ColorVertex(1.0f, 0.0f, 2.0f, D3DCOLOR_XRGB(0,0,255));
Araw
  • 2,410
  • 3
  • 29
  • 57