// Of the 3 methods, only one of the first two can be used, but the third one can be // used either by replacing either of the first two, or modulating with it.
// Transform a point by the current model view transformation matrix // The given initial space point is not changed, the new position of the transformed point is returned. Point TP(Point const& p) { static float mtr[16]; glGetFloatv(GL_MODELVIEW_MATRIX, mtr); float *col0 = mtr, *col1 = mtr + 4, *col2 = mtr + 8, *col3 = mtr + 12; Point ret = Point(0., 0., 0.); ret += Point(col0) * p.x; ret += Point(col1) * p.y; ret += Point(col2) * p.z; ret += Point(col3); return ret / (p.x * col0[3] + p.y * col1[3] + p.z * col2[3] + col3[3]); }
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // perhaps some transformation here // some transformation here. In the example below, we get the matrix of it, and multiply it directly to matrix stack. // draw geometry
The following code has the same effect as the above one.
glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // perhaps transformation here static float mtr[16]; glPushMatrix(); { glLoadIdentity(); // some some transformation here. glGetFloatv(GL_MODELVIEW_MATRIX, mtr); } glPopMatrix(); glMultMatrixf( rotationMatrix ); // draw geometry
// define a special key callback function. void specialKey(int key, int x, int y) { switch(key) { case : action1(); break; case : action2(); break; case : action3(); break; case : action4(); break; } glutPostRedisplay(); } // register it with glut (in main()). glutSpecialFunc(specialKey); // like glutKeyboardFunc(keyboard), deals some with non-ascii keys.
/* Draw all opaque geometries here. */ // Draw a transparent object. glEnable (GL_BLEND); { glDepthMask (GL_FALSE); // this object is not drawn if it is blocked by others, however it does not block any other objects. glBlendFunc (GL_DST_ALPHA, GL_ONE_MINUS_SRC_COLOR); // specify blend function here. // specify alpha value using glMaterial*() if lighting is enabled. GLfloat mat_transparent[] = { 0.0, 0.8, 0.8, 0.6 }; glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_transparent); // or using glColor*() if lighting is disabled. glColor4f(.0, .8, .8, .6); // draw transparent geometry here glDepthMask (GL_TRUE); // restore z-buffer mask } glDisable (GL_BLEND);
1.3.6