Jump to content
  • Advertisement
Sign in to follow this  
boolean010

Try to render triangle strip: What is wrong?

This topic is 4958 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

void Render() { const FLOAT SWH = 320, SHH = 240; CUSTOMVERTEX triangleVertices[] = { {-5.0+SWH, -5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 0, 0 ) }, { 0.0+SWH, 5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 10, 0 ) }, { 5.0+SWH, -5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 20, 0 ) }, {10.0+SWH, 5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 30, 0 ) }, {15.0+SWH, -5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 40, 0 ) }, {20.0+SWH, 5.0+SHH, 0.0, 1.0, D3DCOLOR_XRGB ( 255, 50, 0 ) } }; IDirect3DVertexBuffer9* pVertexBuf = NULL; HRESULT hResult = g_pDirect3DDevice->CreateVertexBuffer( 6*sizeof(CUSTOMVERTEX), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE, D3DPOOL_DEFAULT, &pVertexBuf, NULL); if(FAILED(hResult)) { DXTRACE_ERR("Error creating vertex buffer", hResult); return; } VOID* pVertices; hResult = pVertexBuf->Lock(0, 0, (void**)&pVertices, 0); if(FAILED(hResult)) { DXTRACE_ERR("Error locking vertex buffer", hResult); return; } memcpy(pVertices, triangleVertices, sizeof(triangleVertices)); pVertexBuf->Unlock(); g_pDirect3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); g_pDirect3DDevice->SetStreamSource(0, pVertexBuf, 0, sizeof(CUSTOMVERTEX)); g_pDirect3DDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); g_pDirect3DDevice->BeginScene(); g_pDirect3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_FLAT); g_pDirect3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 4); g_pDirect3DDevice->EndScene(); g_pDirect3DDevice->Present( NULL, NULL, NULL, NULL ); if (pVertexBuf) pVertexBuf->Release(); }

Share this post


Link to post
Share on other sites
Advertisement
I'm a directX8 user so maybe what i'll say might be wrong in DX9
but i'll try anyway :

The way you defined your object is with two triangles with 3 vertices for each one (which is called TRIANGLE_LIST not STRIP)

Try reading in the SDK the difference between those two.

And when you create your vertex buffer u supply 6 * CUSTOMVERTEX
where CUSTOMVERTEX is your object definition when you need to supply the vertex structure size you are using.

e.g.

struct Vertex
{
float x, y, z;
DWORD color;
}

sizeof(Vertex) * 6

Share this post


Link to post
Share on other sites
The code that is listed below was taken from the directx documentation. I wanted to modify Tutorial 2: Vertices and have it display the triangle-strip contained in the array 'Vertices[]"
I thought I would be able to tack on a rhw in the struct and do a SetFVF ( D3DFVF_XYZRHW )
At this point I am thinking that the vertices should be in screen coordinate/space and all I would have to do is add half the screen width and height to the vertices and I would get a triangle-strip in the middle of the screen. But it seems to be more involved than that : maybe you can only do this when you have a single triangle?????
I was able to get it to work by modifying Tutorial 3 : Matrices. So I guess you can't do it the way I was thinking.




//////////////////////////////////////////////////////////////

struct CUSTOMVERTEX
{
float x,y,z;
};

CUSTOMVERTEX Vertices[] =
{
{-5.0, -5.0, 0.0},
{ 0.0, 5.0, 0.0},
{ 5.0, -5.0, 0.0},
{10.0, 5.0, 0.0},
{15.0, -5.0, 0.0},
{20.0, 5.0, 0.0}
};

//
// It is assumed that d3dDevice is a valid
// pointer to a IDirect3DDevice9 interface.
//
d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 4);
////////////////////////////////////////////////////////////////

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!