• Announcements

Archived

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

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 on other sites
Why are you using XZY instead of XYZ? That could be your problem right there.

MindEngine Development
http://medev.sourceforge.net

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 on other sites
Try using a TRIANGLELIST - a strip takes the last defined vertex and uses that as the start vertex for the next triangle.

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 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 on other sites
Thanks, I do not know anything about OpenGL.

What is "winding order" though?

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 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 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 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 on other sites
Hi there.... why you wanna switch to D3D? I try to port all my work to OGL now!

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)

• Partner Spotlight

• Forum Statistics

• Total Topics
627676
• Total Posts
2978578
• Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 11
• 12
• 10
• 12
• 22