OpenGL -> DirectX 9 Conversion

Started by
11 comments, last by strahan 20 years, 3 months ago
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]
Advertisement
Why are you using XZY instead of XYZ? That could be your problem right there.

MindEngine Development
http://medev.sourceforge.net
I am just copying the code from the "Real-Time Dynamic Level of
Detail Terrain Rendering with ROAM" implementation that you get source for at:

http://www.gamasutra.com/features/20000403/turner_01.htm

Try using a TRIANGLELIST - a strip takes the last defined vertex and uses that as the start vertex for the next triangle.
Thanks. I tried a D3DPT_TRIANGLELIST and also tried swapping the Z/Y coordinates but I got the same result.
I think your aware of this but OpenGL and DirectX use different coordinate systems.

So you''ll need to swap your y and z values and change your winding order.

Cheers
CHris
CheersChris
Thanks, I do not know anything about OpenGL.

What is "winding order" though?
If all vertices use a consistent winding order, it shouldn''t make a difference. Likewise with the Z / Y co-ords. As long as it''s consistent, the shape will remain as intended, it''d just be rotated differently.

How many vertices are you attempting to render?

In D3d, you''d allocate a VB for the whole batch of vertices and render triangles using one DrawPrimitive function.
The process:

Allocate VB for x * 3 amount of triangles.
Copy vertex data across
Set stream source to the VB
RenderPrimitive(TRI_LIST, x) // where x is the triangle count
Hello

Winding order is the order that you define your triangle with.

1 --------- 2
\ |
\ |
\ |
\ |
\| 3

1, 2, 3 would be clockwize and 1,3,2 would be counter clock wise. Off hand I forget if gl is clockwize or counter clockwize.
Eitherway you can tell DX to use a Right Hand Coordinate system and then they are both the same.

Ben
ps Well apparently you can uses spaces and I am not about to start putting nbsp for everyone..

[edited by - zander76 on January 7, 2004 3:15:40 PM]

This topic is closed to new replies.

Advertisement