Stengun

08-11-2008, 05:38 AM

Hi,

Can someone tell me what maths openGL does internally with the projection matrix when rendering? I've tried drawing a wireframe version of the world using my own 2d draws on top the openGL 3d world. They are pretty much the same, expect my own projected 2d lines seem as if there's a slightly different FOV. This can't be the case I've checked the matrix that I pass to openGL as a GL_PROJECTION_MATRIX, and it's the same as what I'm using to draw when converting from 3d to 2d. So that must mean I'm not using the projection matrix correctly, or that openGL must be adding an extra step somewhere. My 3d to 2d function looks like this:

void Transform3dto2dScreenCoord( MATRIX *m, VECTOR *v, VECTOR *vout )

{

float w;

vout->x = v->x*m->m[MINDEX_00] + v->y*m->m[MINDEX_10] + v->z*m->m[MINDEX_20] + m->m[MINDEX_30];

vout->y = v->x*m->m[MINDEX_01] + v->y*m->m[MINDEX_11] + v->z*m->m[MINDEX_21] + m->m[MINDEX_31];

vout->z = v->x*m->m[MINDEX_02] + v->y*m->m[MINDEX_12] + v->z*m->m[MINDEX_22] + m->m[MINDEX_32];

w = v->x*m->m[MINDEX_03] + v->y*m->m[MINDEX_13] + v->z*m->m[MINDEX_23] + m->m[MINDEX_33];

vout->z = vout->z/w;

vout->y = vout->y/w;

vout->x = vout->x/w;

vout->x/=vout->z;

vout->y/=vout->z;

vout->x *= ScreenWidth;

vout->y *= ScreenWidth;

vout->x += ScreenWidth/2;

vout->y += ScreenHeight/2;

}

Any ideas how this compares to what openGL actually does?

Thanks in advance.

Can someone tell me what maths openGL does internally with the projection matrix when rendering? I've tried drawing a wireframe version of the world using my own 2d draws on top the openGL 3d world. They are pretty much the same, expect my own projected 2d lines seem as if there's a slightly different FOV. This can't be the case I've checked the matrix that I pass to openGL as a GL_PROJECTION_MATRIX, and it's the same as what I'm using to draw when converting from 3d to 2d. So that must mean I'm not using the projection matrix correctly, or that openGL must be adding an extra step somewhere. My 3d to 2d function looks like this:

void Transform3dto2dScreenCoord( MATRIX *m, VECTOR *v, VECTOR *vout )

{

float w;

vout->x = v->x*m->m[MINDEX_00] + v->y*m->m[MINDEX_10] + v->z*m->m[MINDEX_20] + m->m[MINDEX_30];

vout->y = v->x*m->m[MINDEX_01] + v->y*m->m[MINDEX_11] + v->z*m->m[MINDEX_21] + m->m[MINDEX_31];

vout->z = v->x*m->m[MINDEX_02] + v->y*m->m[MINDEX_12] + v->z*m->m[MINDEX_22] + m->m[MINDEX_32];

w = v->x*m->m[MINDEX_03] + v->y*m->m[MINDEX_13] + v->z*m->m[MINDEX_23] + m->m[MINDEX_33];

vout->z = vout->z/w;

vout->y = vout->y/w;

vout->x = vout->x/w;

vout->x/=vout->z;

vout->y/=vout->z;

vout->x *= ScreenWidth;

vout->y *= ScreenWidth;

vout->x += ScreenWidth/2;

vout->y += ScreenHeight/2;

}

Any ideas how this compares to what openGL actually does?

Thanks in advance.