Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Converting between coordinate systems

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

I am currently working on wrapping up the methods I need for my game within a render device class. I have abstracted it so I can render with either OpenGL or DirectX. The problem lies with the fact that the two use different coordinate systems. I have tried using the D3DX *RH matrix functions... unfortunately I can't seem to get it to work no matter what I do. I have searched here and on Google and unless I am using the wrong keywords, or am over looking something, I can't seem to find the answer. If anyone has any insight into how I can make both OpenGL and DirectX use the same coordinate system to achieve the same exact display. Thanks in advance.

Share this post

Link to post
Share on other sites
Okay, after messing around with it more, I got this.


I am getting closer, but there has to be something I am missing...

I'll show you the basic code I am using to set up the views, and render the polys. Keep in mind, some of this code is BAD because I am just doing a test run to see if I can get them to render the same. Keep in mine, this code is condensed from various methods, but the code executes in the same order the same way regardless

My code for DX looks like this:

D3DXMATRIX projection;
D3DXMATRIX camera;

D3DXMatrixPerspectiveFovRH(&projection, 45.0f, (float)m_Width/(float)m_Height, 1.0f, 1000.0f);
m_D3DDevice->SetTransform(D3DTS_PROJECTION, &projection);
m_D3DDevice->SetTransform(D3DTS_WORLD, &world);
D3DXMatrixLookAtRH(&camera, &D3DXVECTOR3(0, 0, 10), &D3DXVECTOR3(0, 0, 0), &D3DXVECTOR3(0, 1, 0));
m_D3DDevice->SetTransform(D3DTS_VIEW, &camera);

// I clear the scene here, but I edited out the code

verts[0].position = D3DXVECTOR3(-1, -1, 3);
verts[0].color = D3DCOLOR_COLORVALUE(1, 0, 0, 1);
verts[1].position = D3DXVECTOR3(-1, 1, 3);
verts[1].color = D3DCOLOR_COLORVALUE(0, 1, 0, 1);
verts[2].position = D3DXVECTOR3( 1, 1, 3);
verts[2].color = D3DCOLOR_COLORVALUE(0, 0, 1, 1);

m_D3DDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
m_D3DDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 3, verts, sizeof(CUSTOMVERTEX));

m_D3DDevice->Present(NULL, NULL, NULL, NULL);

My code for OpenGL looks like this:

glViewport(0, 0, m_Width, m_Height);
gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);

// I clear the screen here

glColor3f(1, 0, 0);
glVertex3f(-1, -1, 3);
glColor3f(0, 1, 0);
glVertex3f(-1, 1, 3);
glColor3f(0, 0, 1);
glVertex3f( 1, 1, 3);


Is there something I am just overlooking or missing?

Share this post

Link to post
Share on other sites
Sign in to follow this  

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