Archived

This topic is now archived and is closed to further replies.

strahan

OpenGL OpenGL -> DirectX 9 Conversion

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Right, I am not doing it by any means in an efficient way. Just trying to get it to render correctly first.

Here is a screen shot of my tower of triangles that should be roam terrain:

http://www.3dconquest.com/images/tower.jpg

Btw, does anyone know of a good ROAM or LOD implementation in DirectX 9 that would be easily added to one''s own 3d engine?

Thanks.

Share this post


Link to post
Share on other sites
Also,

Ensure that you set up a identity World Matrix (basically resets the scene)

I assume your view and projection matrices are set up properly too (although it won''t make much difference in this instance)

Share this post


Link to post
Share on other sites