Help! I am trying to convert an OpenGL implementation into DirectX 9. I am getting screwed up results when converting the following triangle rendering code:
OpenGL:
glColor3f(1, 1, 1);
// Output the LEFT VERTEX for the triangle
glVertex3f((GLfloat) leftX,(GLfloat) leftZ,(GLfloat) leftY );
glColor3f(1, 1, 1);
// Output the RIGHT VERTEX for the triangle
glVertex3f((GLfloat) rightX, (GLfloat) rightZ, (GLfloat) rightY );
glColor3f(1, 1, 1);
// Output the APEX VERTEX for the triangle
glVertex3f((GLfloat) apexX,(GLfloat) apexZ,(GLfloat) apexY );
DirectX 9:
CUSTOMVERTEX cvVertices[3];
cvVertices[0].colour = D3DCOLOR_XRGB(255, 255, 255);
cvVertices[0].x = leftX;
cvVertices[0].y = leftZ;
cvVertices[0].z = leftY;
cvVertices[1].colour = D3DCOLOR_XRGB(255, 255, 255);
cvVertices[1].x = rightX;
cvVertices[1].y = rightZ;
cvVertices[1].z = rightY;
cvVertices[2].colour = D3DCOLOR_XRGB(255, 255, 255);
cvVertices[2].x = apexX;
cvVertices[2].y = apexZ;
cvVertices[2].z = apexY;
VOID* pVertices;
//Get a pointer to the vertex buffer vertices and lock the vertex buffer
m_pVertexBuffer->Lock(0, sizeof(cvVertices), (VOID**)&pVertices, 0);
//Copy our stored vertices values into the vertex buffer
memcpy(pVertices, cvVertices, sizeof(cvVertices));
//Unlock the vertex buffer
m_pVertexBuffer->Unlock();
HRESULT hr = m_pD3DDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(CUSTOMVERTEX));
hr = m_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
hr = m_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
Using DirectX9 I get a tower of random triangles instead of smooth flowing terrain I get in OpenGL.
Thanks,
Strahan
[edited by - strahan on January 7, 2004 2:37:26 PM]
[edited by - strahan on January 7, 2004 2:37:44 PM]
[edited by - strahan on January 7, 2004 2:38:45 PM]