Jump to content
  • Advertisement

Archived

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

strahan

OpenGL OpenGL -> DirectX 9 Conversion

This topic is 5309 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

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
Advertisement
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
Thanks. I tried a D3DPT_TRIANGLELIST and also tried swapping the Z/Y coordinates but I got the same result.

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
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

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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!