🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Strange opengl matrix state?

Started by
1 comment, last by mrTony 17 years, 6 months ago
I wrote some codes like this: #pragma pack(1) struct Point { float x,y,z; }; static Point vertex[MAX_VERTEX]; void Transform(float*m,float p[3]) { float temp[3]; temp[0] = m[0] * p[0] + m[4]*p[1] + m[8]*p[2] + m[12]; temp[1] = m[1] * p[4] + m[5]*p[1] + m[9]*p[2] + m[13]; temp[2] = m[2] * p[0] + m[6]*p[1] + m[10]*p[2] + m[14]; p[0] = temp[0]; p[1] = temp[1]; p[2] = temp[2]; } void DrawScene() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glPushMatrix(); glRotatef(angle,1.0,1.0,0.0); glRotatef(angle,1.0,0.0,0.0); glGetFloatv(GL_MODELVIEW_MATRIX,m); {loop} Transform(m,(float*)&vertex); glLoadIdentity(); glVertexPointer( 3,GL_FLOAT,0,vertex ); glTexCoordPointer( 2,GL_FLOAT,0,texCoord); lColorPointer(4,GL_FLOAT,0,color); glDrawArrays( GL_TRIANGLES,0,p->numFace*3); glPopMatrix(); } My intention is do the modelview matrix transform by myself,but the result is quite different with the correct one,actually the vertex transform by own fucntion make the triangles teared into piece! Does anyone met this situation? Below is the code transform by opengl. glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glPushMatrix(); glRotatef(angle,1.0,1.0,0.0); glRotatef(angle,1.0,0.0,0.0); // glGetFloatv(GL_MODELVIEW_MATRIX,m); // {loop} // Transform(m,(float*)&vertex[ k * 3 + j ]); // glLoadIdentity(); glVertexPointer( 3,GL_FLOAT,0,vertex ); glTexCoordPointer( 2,GL_FLOAT,0,texCoord); lColorPointer(4,GL_FLOAT,0,color); glDrawArrays( GL_TRIANGLES,0,p->numFace*3); glPopMatrix();
Advertisement
But the GPU will do that transformation with the modelview matrix for you.

Oh also in your Transform() you are multiplying by p[4] instead of p[0]

temp[1] = m[1] * p[4] + m[5]*p[1] + m[9]*p[2] + m[13];
I check the code again,and that's the point.Thanks.
Sorry for that stupid mistakes.
Anyway,I need do some special effect in view space ,such as daw the depth in a colorbuffer,then you can do something.

This topic is closed to new replies.

Advertisement