¡¡¡¡ ±¾ÎIJ»×ÅÁ¦ÓÚOpenGL±à³ÌµÄ·½·¨ºÍ¼¼ÇÉ£¬¶øÊÇ°ÑÖصã·ÅÔÚÈçºÎÔÚLinuxƽ̨ÉÏ¿ª·¢OpenGL³ÌÐò¡£½éÉÜÖ§³ÖOpenGLµÄ¼¸¸ö¹¤¾ß°ü£¬²¢¸¨ÒÔÏêϸµÄʵÀýÀ´²ûÊö¡£
1. LinuxÏÂOpenGL±à³Ì»·¾³¼ò½é
¡¡¡¡ OpenGL²»ÊÇ×ÔÓÉÈí¼þ£¬ËüµÄ°æȨ¡¢É̱꣨OpenGLÕâ¸öÃû×Ö£©¶¼¹éSGI¹«Ë¾ËùÓС£µ«ÔÚLinuxÏÂÓÐOpenGLµÄÈ¡´ú²úÆ·£ºMesa¡£MesaÌṩºÍOpenGL¼¸ºõÍêÈ«Ò»ÖµĽӿڣ¬¶ÔÀûÓÃOpenGL API±à³ÌµÄÈËÀ´Ëµ£¬¼¸ºõ¸Ð¾õ²»µ½ÈκβîÒì¡£MesaÊÇ×ñÑGPLÐÒ飨²¿·Ö×ñÑLGPLÐÒ飩µÄ×ÔÓÉÈí¼þ£¬¶øÇÒ£¬ÕýÊÇÓÉÓÚMesaµÄ×ÔÓÉÐÔ£¬ËüÔÚ¶ÔÐÂÓ²¼þµÄÖ§³Ö¶ÈµÈ·½Ã涼³¬¹ýÁËOpenGL¡£Mesa¿ÉÒÔ´Ówww.mesa3d.orgÈ¡µÃ¡£µÃµ½Mesaºó£¬ÒÀÕÕ˵Ã÷¼´¿ÉÉú³É±àд³ÌÐòËùÐèÒªµÄ¶¯Ì¬¡¢¾²Ì¬Á¬½Ó¿âºÍÍ·Îļþ¡£
¡¡¡¡ Á˽âOpenGLµÄ¶ÁÕ߶¼ÖªµÀ£¬OpenGL±¾ÉíÖ»ÌṩÈýάͼÐνӿڣ¬²»¾ß±¸»æÖÆ´°¿Ú¡¢½ÓÊÜÏìÓ¦¡¢´¦ÀíÏûÏ¢µÈ¹¦ÄÜ¡£ÕâЩ¹¦ÄܱØÐëÓɵÚÈý·½µÄ¿ª·¢»·¾³Ìṩ£¬ÈçÉÏÃæÌá¼°µÄVCµÈµÈ¡£ÓÐÈË»áÏ룬¼ÈÈ»ÔÚMotifÏ¿ÉÒÔ¿ª·¢OpenGL³ÌÐò£¬ÄÇô£¬Ê¹ÓÃLinuxϵÄLesstifÒ²Ó¦¸Ã¿ÉÒÔ¡£Êǵģ¬µÄÈ·¿ÉÒÔ£¬µ«²»ÐÒµÄÊÇ£¬LinuxϵÄLesstifÊÇÒ»¸öºÜ²»³ÉÊìµÄ²úÆ·£¬¶øÇÒÒ²²»¾ßÓпÉÒÆÖ²ÐÔ£¬ËùÒÔÓ¦ÓÃLesstif¿ª·¢µÄÈ˺ÜÉÙ¡£ÏÂÃæÎÒÃǼòµ¥½éÉܼ¸¸ö³£ÓõŤ¾ß°ü¡£
¡¡¡¡ ÔÚLinuxÏ¿ª·¢OpenGL³ÌÐò£¬×î³£ÓõŤ¾ßÊÇGLUT£¨The OpenGL Utility Toolkit£©¡£Ëü¿ÉÒÔ´´½¨Ò»¸ö»ò¶à¸öOpenGL´°¿Ú£¬ÏìÓ¦¡¢´¦ÀíÓû§µÄ½»»¥²Ù×÷¡¢¼òµ¥µÄµ¯³öʽ²Ëµ¥ÒÔ¼°Ò»Ð©ÄÚÖõĻæͼºÍ×ÖÌå´¦Àí¹¦ÄÜ¡£GLUTºÍOpenGLÒ»Ñù£¬¿ÉÒÔÒÆÖ²ÓÚ¶àÖÖƽ̨¡£ÓÉÓÚËüÁ¼ºÃµÄ±íÏÖ£¬ÏÖÔÚËüÒѾ³ÉΪMesa·¢²¼µÄ±ê×¼Ì×¼þÖ®Ò»¡£
¡¡¡¡ ÁíÒ»¸öºÜºÃµÄ¿ª·¢¹¤¾ß°üÊÇFLTK£¨Fast Light Tool Kit£©£¬ÕâÊÇÒ»¸öÓÃC++±àдµÄͼÐνçÃ濪·¢¹¤¾ß¡£ºÍGTK++¡¢KDE²»Í¬£¬ËüÖ»¹Ø×¢ÓÚͼÐνçÃæµÄÉè¼Æ£¬¶ø¾¡Á¿²»Ç£ÉæÆäËûµÄʵ¼ÊÓ¦Óá£Õâ¸öÌصãʹµÃËü±ÈÆäËûÐí¶à¿ª·¢¹¤¾ß¼òÁ·ºÍ¸ßЧ¡£¶øÇÒ£¬ËüͬÑùÒ²ÊÇÒ»¸ö¾ßÓÐÁ¼ºÃÒÆÖ²ÐԵĿª·¢¹¤¾ß¡£ÊÂʵÉÏ£¬ËüÏÖÔÚÕýÒýÀ´Ô½À´Ô½¶àÈ˵ÄÐËȤ£¬Ðí¶àÉÌÒµÈí¼þ£¨ÓÈÆäÊÇÖÂÁ¦ÓÚ¿ª·¢Ç¶Èëʽ×ÀÃæϵͳµÄÈí¼þ£©¶¼Ñ¡ÓÃÁËËü×÷ΪͼÐνçÃæµÄ¿ª·¢¹¤¾ß¡£¹ØÓÚËüµÄÏêϸÇé¿ö²Î¼û×÷ÕßµÄÁíһƪÎÄÕ¡¶FLTK---Ò»¸öÓÅÐãµÄͼÐνçÃ濪·¢¹¤¾ß°ü¡·¡£ÔÚFLTKÀïÓÐÒ»¸ö×é¼þ£ºFl_Gl_WindowÊÇרÃŵÄOpenGL´°¿Ú£¬ÀûÓÃËü¿ª·¢OpenGL³ÌÐòÏ൱·½±ã¡£
¡¡¡¡ ×îºóÒªÌáµÄÊÇGTKºÍKDE£¬ËüÃÇÊÇÄ¿Ç°ÔÚLinuxÏÂÓõÄ×î¶àµÄ¿ª·¢¹¤¾ß¡£GTK±¾Éí²¢²»Ö±½ÓÖ§³ÖOpenGL£¨Ðµİ汾ÊÇ·ñÖ§³Ö£¬Éв»Ì«Çå³þ£©£¬µ«ÓÐÈË¿ª·¢ÁËÖ§³ÖOpenGLµÄWidget£¬½Ð×öGLAREA£¬ÐèÒªµÄ¶ÁÕß¿ÉÒÔµ½ÍøÉÏÈ¥²éÕÒ»òÕßÓë±¾ÎÄ×÷ÕßÁªÏµ¡£KDEÌṩÁ˶ÔOpenGLµÄÖ§³Ö£¬µ«ËüµÄȱÏÝÖ®Ò»ÊÇKDEÖ»ÔËÐÐÓÚLinuxϵͳ£¬²»¾ßÓпÉÒÆÖ²ÐÔ¡£ÔÚÕâÀÎÒ½«Ö÷ÒªÏò´ó¼Ò½éÉÜÇ°ÃæÁ½¸ö¹¤¾ß°ü¡£
2. ÓÃGLUT¿ª·¢OpenGL³ÌÐò
2.1 ÈçºÎ»ñµÃ
¡¡¡¡ GLUT¿ÉÒÔ´ÓMesaÖлñµÃ£¬¶ÁÕßÒ²¿ÉÒÔÖ±½Óµ½ËüµÄÖ÷ҳȥÏÂÔØËü£º¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡http://reality.sgi.com/employees/mjk_asd/glut3/glut3.html¡£°´ÕÕ˵Ã÷°²×°ºóÔÚOpenGLµÄÍ·ÎļþGLĿ¼Ï½«»áÓÐGLUTµÄÍ·Îļþglut.h£¬Í¬Ê±°²×°µÄ»¹ÓпâÎļþlibglut.a»òlibglut.so¡£ÓÐÁËËüÃÇÒԺ󣬾ͿÉÒÔÓÃGLUTÀ´±à³ÌÁË¡£
2.2 Ò»¸ö¼òµ¥µÄÀý×Ó
ÏÂÃ棬ÎÒÃÇÏÈ¿´Ò»¸ö¼òµ¥µÄÀý×Ó¡£Õâ¸öÀý×Ó»Ò»¸öÁ¢ÌåµÄÇò¡£
/* light.c
´Ë³ÌÐòÀûÓÃGLUT»æÖÆÒ»¸öOpenGL´°¿Ú£¬²¢ÏÔʾһ¸ö¼ÓÒÔ¹âÕÕµÄÇò¡£
*/
/* ÓÉÓÚÍ·Îļþglut.hÖÐÒѾ°üº¬ÁËÍ·Îļþgl.hºÍglu.h£¬ËùÒÔÖ»ÐèÒªinclude ´ËÎļþ*/
# include < GL / glut.h >
# include < stdlib.h >
/* ³õʼ»¯²ÄÁÏÊôÐÔ¡¢¹âÔ´ÊôÐÔ¡¢¹âÕÕÄ£ÐÍ£¬´ò¿ªÉî¶È»º³åÇø */
ÒýÓÃ:void init ( void )
{
GLfloat mat_specular [ ] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat mat_shininess [ ] = { 50.0 };
GLfloat light_position [ ] = { 1.0, 1.0, 1.0, 0.0 };
glClearColor ( 0.0, 0.0, 0.0, 0.0 );
glShadeModel ( GL_SMOOTH );
glMaterialfv ( GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv ( GL_FRONT, GL_SHININESS, mat_shininess);
glLightfv ( GL_LIGHT0, GL_POS99vION, light_position);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);
}
/*µ÷ÓÃGLUTº¯Êý£¬»æÖÆÒ»¸öÇò*/
void display ( void )
{
glClear (GL_COLOR_BUFFER_B99v | GL_DEPTH_BUFFER_B99v);
glutSolidSphere (1.0, 40, 50);
glFlush ();
}
/* ¶¨ÒåGLUTµÄreshapeº¯Êý£¬w¡¢h·Ö±ðÊǵ±Ç°´°¿ÚµÄ¿íºÍ¸ß*/
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ( );
if (w <= h)
glOrtho (-1.5, 1.5, -1.5 * ( GLfloat ) h / ( GLfloat ) w,
1.5 * ( GLfloat ) h / ( GLfloat ) w, -10.0, 10.0 );
else
glOrtho (-1.5 * ( GLfloat ) w / ( GLfloat ) h,
1.5 * ( GLfloat ) w / ( GLfloat ) h, -1.5, 1.5, -10.0, 10.0);
glMatrixMode ( GL_MODELVIEW );
glLoadIdentity ( ) ;
}
/* ¶¨Òå¶Ô¼üÅ̵ÄÏìÓ¦º¯Êý */
void keyboard ( unsigned char key, int x, int y)
{
/*°´Esc¼üÍ˳ö*/
switch (key) {
case 27:
exit ( 0 );
break;
}
}
int main(int argc, char** argv)
{
/* GLUT»·¾³³õʼ»¯*/
glutInit (&argc, argv);
/* ÏÔʾģʽ³õʼ»¯ */
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
/* ¶¨Òå´°¿Ú´óС */
glutInitWindowSize (300, 300);
/* ¶¨Òå´°¿ÚλÖà */
glutInitWindowPosition (100, 100);
/* ÏÔʾ´°¿Ú£¬´°¿Ú±êÌâΪִÐк¯ÊýÃû */
glutCreateWindow ( argv [ 0 ] );
/* µ÷ÓÃOpenGL³õʼ»¯º¯Êý */
init ( );
/* ×¢²áOpenGL»æͼº¯Êý */
glutDisplayFunc ( display );
/* ×¢²á´°¿Ú´óС¸Ä±äʱµÄÏìÓ¦º¯Êý */
glutReshapeFunc ( reshape );
/* ×¢²á¼üÅÌÏìÓ¦º¯Êý */
glutKeyboardFunc ( keyboard );
/* ½øÈëGLUTÏûϢѻ·£¬¿ªÊ¼Ö´ÐгÌÐò */
glutMainLoop( );
return 0;
}
¡¡¡¡ ´ÓÉÏÃæµÄÀý×ÓÖÐÎÒÃÇ¿ÉÒÔ¿´³ö£¬GLUT²ÉÓÃÒ»ÖÖº¯Êý×¢²áµÄ»úÖÆÀ´ÊµÏÖOpenGL»æͼ¡£ËüµÄÒ»°ãÁ÷³ÌÕýÈçÎÒÃÇÉÏÃæµÄ×¢ÊÍËùд£¬ÏÈÊdzõʼ»¯º¯Êý£¬¶¨Òå´°¿Ú£¬È»ºóÖ´ÐÐOpenGL³õʼ»¯³ÌÐò£¬ÕâÖ÷ÒªÊÇһЩÐèҪȫ¾ÖÉèÖõĻ·¾³±äÁ¿¡£½ÓÏÂÀ´ÊÇ×¢²áÏàӦʼþµÄº¯Êý£¬°üÀ¨Íê³Éʵ¼Ê»æͼ¹¤×÷µÄ»æÖƳÌÐò¡¢¸Ä±äOpenGL´°¿Ú´óСʱµÄÏìÓ¦º¯Êý¡¢¼üÅÌʼþµÄÏìÓ¦º¯ÊýºÍÊó±êʱ¼äµÄÏìÓ¦º¯Êý¡£×îºóµ÷ÓÃglutMainLoop£¨£©º¯Êý£¬Ö´ÐÐÔÚglutReshapeFuncºÍglutDisplayFuncÖÐ×¢²áµÄº¯Êý£¬½øÈëÏûϢѻ·¡£µ±Óû§Í¨¹ý¼üÅ̺ÍÊó±ê½øÐн»»¥²Ù×÷ʱ£¬Ëü¼´µ÷ÓÃÏàÓ¦µÄº¯Êý¡£
¡¡¡¡ ÎÒÃDZàÒëÉÏÃæµÄÃûΪlight.cµÄÔ´Îļþ¡£¼Ù¶¨Í·Îļþ£¨Ä¿Â¼GL£©·ÅÔÚĿ¼/usr/local/includeÏ£¬¿âÎļþ£¨¶¯Ì¬¿âlibGL.so.*¡¢libGLU.so.*ºÍlibglut.so.*£©ÔÚĿ¼/usr/local/libĿ¼Ï£¬²¢ÒѾÔËÐÐÁËldconfig£¬Ôò±àÒëÃüÁîΪ£º
¡¡¡¡ gcc -I/usr/local/include -L/usr/local/lib -L/usr/X11R6/lib -lglut -lGLU -lGL
¡¡¡¡ -lX11 -lXext -lXmu -lXi -lm light.c -o light
¡¡¡¡ ÆäÖеÄ-lX11 -lXert -lXi -lm ÊÇ»æÖÆ´°¿ÚÐèÒªµÄXµÄ¿â£¬ËüÃÇĬÈÏÔÚ /usr/X11R6/libĿ¼Ï¡£ÏÂÃæµÄͼһ¼´ÊÇÔËÐÐlightµÄ½á¹û£¬µ±°´ÏÂESC¼üʱ£¬³ÌÐò»áÍ˳ö¡£µ÷Õû´°¿Ú´óСʱ£¬Í¼ÐÎ×Ô¶¯Öػ档עÒâÔÚÉÏÃæreshapeº¯ÊýÖУ¬±È½ÏwºÍhµÄÖµ¸ø³öµÄÈ¡¾°±ä»»£¬ÕâÊÇÒ»¸ö³£Óõļ¼ÇÉ¡£
2.3 GLUT¼ò½é
¡¡¡¡ GLUT³£Óõĺ¯ÊýÖ÷Òª°üÀ¨ÒÔϼ¸Àࣺ
¡¡¡¡ ? ³õʼ»¯º¯Êý¡£Ö÷Òª¾ÍÊÇÉÏÃæÀý×ÓÖеļ¸¸öº¯Êý¡£
¡¡¡¡ ? ÏûϢѻ·º¯Êý¡£¼´glutMainLoopº¯Êý¡£
¡¡¡¡ ? ´°¿Ú¹ÜÀíº¯Êý¡£°üÀ¨´°¿ÚµÄ´´½¨¡¢Ð޸ġ¢É¾³ýµÈ¡£GLUTÖ§³Ö¶à¸öOpenGL´°¿Ú¡£
¡¡¡¡ ? Overlay¹ÜÀíº¯Êý¡£µ±Óû§ÏÔ¿¨Ö§³ÖOverlay·½Ê½Ê±£¬¿ÉÒÔÓÃÕâЩº¯ÊýÀ´´´½¨¡¢¹ÜÀí¡¢É¾³ýGLUT´°¿ÚµÄOverlay¡£
¡¡¡¡ ? ²Ëµ¥¹ÜÀíº¯Êý¡£¶¨ÖƲ˵¥ÒÔ¼°¶¨Òå²Ëµ¥ÏàӦʼþ¡£
¡¡¡¡ ? ʼþ×¢²áº¯Êý¡£³ýÁËÉÏÃæÀý×ÓÖÐÌá¼°µÄÍ⣬»¹ÓÐÊó±ê¡¢¿Õ¼äÇò£¨ÌṩÈýά²Ù×÷µÄ×°±¸£©¡¢ÌØÊâ¼ü£¨Ctrl¡¢Shift¡¢FϵÁмü¡¢·½Ïò¼ü£©µÈÉ豸µÄʼþ×¢²áº¯Êý¡£
¡¡¡¡ ? ×ÖÌå»æÖƺ¯Êý¡£ÓöàÖÖ×ÖÌå¡¢×ֺŹ©Ñ¡Ôñ¡£
¡¡¡¡ ? ¼òµ¥¼¸ºÎÌåµÄ»æÖƳÌÐò¡£°üÀ¨Çò¡¢Á¢·½Ì塢׶Ìå¡¢Ô²»·Ì塢ʮ¶þÃæÌå¡¢°ËÃæÌå¡¢ËÄÃæÌå¡¢¶þÊ®ÃæÌåºÍ²èºø¡£Ã¿ÖÖ¼¸ºÎÌ嶼ÓÐʵÌåºÍÐéÏßÁ½¸öÑ¡Ïî¡£
¡¡¡¡ ? ȡ״̬º¯Êý¡£ÀàËÆOpenGLµÄglGetϵÁк¯Êý£¬È¡µÃGLUTµÄ¸÷ÖÖ״ֵ̬¡£
¡¡¡¡ ? ÑÕÉ«Ë÷Òý±íº¯Êý¡£
ÕâЩº¯Êý¼«´óµÄ·½±ãÁËÓû§µÄOpenGL±à³Ì¡£ÏÂÃæÎÒÃǼòÂÔ½éÉÜһϼ¸¸ö³£Óõĺ¯Êý¡£
¡¡¡¡ ? glutPostRedisplay£¨£©¡£·¢ËÍÏûÏ¢¸øº¯ÊýglutMainLoop£¬ÇëÇóÖػ汾´°¿Ú¡£ÀûÓô˺¯Êý¿ÉÒÔʵÏÖ¶¯»¡£ÀýÈçÔÚÉÏÃæµÄÀý×ÓÖУ¬ÎÒÃÇÌí¼ÓÒ»¸öÈ«¾Ö±äÁ¿£ºfloat move=0.0¡£²¢¶¨Ò庯ÊýMoveSphereÈçÏ£º
ÒýÓÃ:void MoveSphere ( void )
{
for(int i=0;i<100;i++){
if ( move<1.0) move+=0.1;
else move=0.0;
glutPostRedisplay ( );
}
}
ͬʱÐ޸ĺ¯Êýdisplay£¨£©Îª£º
ÒýÓÃ:void display ( void )
{
glClear (GL_COLOR_BUFFER_B99v | GL_DEPTH_BUFFER_B99v);
glTranslatef ( move, 0.0, 0.0);
glutSolidSphere (1.0, 40, 50);
glFlush ();
}
¡¡¡¡ ÕâÑù£¬µ±ÎÒÃÇÖ´Ðк¯ÊýMoveSphereʱ£¬¾Í»á¿´µ½ÉÏÃæµÄÇò´ÓÖмäÏòÓÒÒƶ¯Ò»¶Î¾àÀ룬ȻºóÓֻص½ÖÐÐÄ£¬¼ÌÐøÒƶ¯¡£
¡¡¡¡ ? glutIdleFunc£¨£©º¯Êý¡£Õâ¸öº¯Êý×¢²áÒ»¸ö¿ÕÏгÌÐòÒ»Ö±ÔÚºǫ́ÔËÐС£ÎÒÃǽ«ÉÏÃæµÄMoveSphereº¯Êý¼ÓÒÔÐ޸ģ¬È¥µôÑ»·£¬È»ºóÔÚlight.c³ÌÐòµÄglutMainLoop£¨£©º¯Êýµ÷ÓÃÇ°Ìí¼ÓÒ»ÐдúÂ룺glutIdleFunc (MoveSphere)£»ÕâÑùÎÒÃDz»ÐèÒªÖ±½Óµ÷Óú¯ÊýMoveSphere£¬³ÌÐòÒ»ÔËÐУ¬Ëü¾Í±»·´¸´µ÷ÓÃÖ±µ½ÎÒÃÇÍ˳ö³ÌÐòΪֹ£¬ÕâºÍÎÒÃÇÇ°Ò»°æ±¾ÖÐËüÖ»ÄÜÑ»·Ìض¨µÄ²½Êý²»Ò»Ñù¡£
¡¡¡¡ ? glutTimerFunc£¨£©º¯Êý¡£ºÍÇ°ÃæµÄglutIdleFunc£¨£©º¯ÊýÀàËÆ£¬µ«²»Í¬µÄÊÇËü×¢²áµÄº¯Êýÿ¸ôÌض¨µÄʼþ·¢Éú¡£Ê±¼äµÄµ¥Î»ÊǺÁÃë¡£
¡¡¡¡ ? glutBitmapCharacter£¨£©º¯Êý¡£ÓÃλͼ·½Ê½°´Ö¸¶¨µÄ×ÖÌå»æÖÆÒ»¸ö×Ö·û´®¡£
¡¡¡¡ ? glutSolidSphere£¨£©º¯Êý¡£ÕâÊÇ»æÖƼ¸ºÎÌåÀຯÊýÖеÄÒ»¸ö¡£´Ëº¯Êý»æÖÆÒ»¸öÇòÌå¡£
2.4 Ò»¸ö¸üÓдú±íÐÔµÄÀý×Ó
¡¡¡¡ ÏÂÃæÎÒÃÇÀ´¿´Ò»¸öÉÔÉÔ¸´ÔÓµÄÀý×Ó¡£ÎÒÃÇ»æÖÆÒ»¸öƽÃ棬Óû§µÄ×ó¼üµã»÷±»×Ô¶¯Á¬½Ó³ÉÒ»¸ö¶à±ßÐΡ£µ±Óû§µã»÷ÓÒ¼ü£¬»áµ¯³ö²Ëµ¥¹©Óû§Ñ¡Ôñ¡£Óû§¿ÉÒÔÑ¡ÔñÇå³ý¡¢ÏâǶºÍÍ˳ö¡£Ñ¡ÔñÇå³ý½«»Øµ½³õʼ״̬£»Ñ¡ÔñÏâǶ³ÌÐò×Ô¶¯¶Ô¶à±ßÐνøÐÐÈý½ÇÆÊ·Ö£»Ñ¡ÔñÍ˳öÔòÖÕÖ¹³ÌÐò¡£
/* tessdemo.c ¶à±ßÐÎÏâǶµÄÀý×Ó£¬Ê¹Óú¯ÊýgluTessCallbackºÍº¯ÊýgluTessVertex¡£*/
#include
#include
#include
#include
/* ¶¨ÒåÔÊÐíµÄ×î´ó¶à±ßÐÎÊý¡¢¶à±ßÐÎÔÊÐíµÄ×î´ó¶¥µãÊýºÍ¿ÉÏâǶµÄ×î´óÈý½ÇÐÎÊý*/
#define MAX_POINTS 256
#define MAX_CONTOURS 32
#define MAX_TRIANGLES 256
/* ÓÃÓڲ˵¥Ñ¡ÏîµÄö¾ÙÀàÐÍ */
typedef enum{ QU99v, TESSELATE, CLEAR } menu_entries;
static mode_type mode;
/* ¶¨Òå»æÖÆģʽµÄö¾ÙÀàÐÍ */
typedef enum{ DEFINE, TESSELATED } mode_type;
static int menu;
static GLsizei width, height; /* OpenGL´°¿ÚµÄ´óС */
static GLuint contour_cnt; /* ¼Ç¼¶à±ßÐÎÊýÄ¿ */
static GLuint triangle_cnt; /* ¼Ç¼Èý½ÇÐÎÊýÄ¿ */
static GLuint list_start; /* ÓÃÓÚÏÔʾÁбí */
/* ¶à±ßÐνṹ */
static struct {
GLfloat p[MAX_POINTS][2];
GLuint point_cnt;
} contours [ MAX_CONTOURS ] ;
/* Èý½ÇÐνṹ */
static struct {
GLsizei no;
GLfloat p [3] [2];
GLclampf color [3] [3];
} triangles [ MAX_TRIANGLES ];
/* ´°¿Ú´óС¸Ä±äʱ£¬É趨widthºÍheightÖµ£¬ÓÃÓÚÖØлæÖÆÍø¸ñ */
void set_screen_wh ( GLsizei w, GLsizei h )
{ width = w; height = h; }
void tesse ( void )
{ /* ÏâǶº¯Êý£¬µ÷ÓÃgluTess* º¯ÊýʵÏÖ*/ }
/* ¶Ôµã»÷Êó±ê×ó¼üʼþµÄÏìÓ¦º¯Êý£º¸üе±Ç°¶à±ßÐζ¥µãÊý×飬²¢ÖØлæÖÆ */
void left_down ( int x1, int y1 )
{
GLfloat P[2];
GLuint point_cnt;
/* ½«GLUT´°¿Ú×ø±ê±ä»»ÎªGL×ø±ê£ºÇ°Õߣ¨0£¬0£©ÔÚ×óÉϽǶøºóÕßÔÚ×óϽÇ*/
P[0] = x1; P[1] = height - y1;
/* ¸üж¥µãÊý¾Ý */
point_cnt = contours [ contour_cnt ] . point_cnt;
contours [ contour_cnt ] . p [ point_cnt ][ 0 ] = P [ 0 ];
contours [ contour_cnt ]. p [ point_cnt ] [ 1 ] = P [ 1 ];
/* »æÖÆÐÂÌí¼ÓµÄ±ß£¬ÈôΪµÚÒ»¸öµã£¬Ôò»æÖÆÒ»¸öµã */
glBegin ( GL_LINES );
if ( point_cnt ) {
glVertex2fv ( contours[contour_cnt].p[point_cnt-1] );
glVertex2fv ( P );
}
else {
glVertex2fv ( P );
glVertex2fv ( P );
}
glEnd();
glFinish();
contours[contour_cnt].point_cnt++;
}
/* µã»÷Êó±êÖмüµÄÏìӦʼþ£¬ÓÐЩϵͳ¿ÉÒÔÓÃͬʱµã»÷×óÓÒ¼üÄ£Ä⣺½áÊøÒ»¸ö¶à±ßÐÎ */
void middle_down( int x1, int y1 )
{
GLuint point_cnt;
(void) x1;
(void) y1;
point_cnt = contours[contour_cnt].point_cnt;
/* Á¬½ÓÆðʼµãºÍ×îºóÒ»¸öµã£¬¹¹³ÉÒ»¸öÍêÕûµÄ¶à±ßÐÎ */
if ( point_cnt > 2 )
{
glBegin( GL_LINES );
glVertex2fv( contours[contour_cnt].p[0] );
glVertex2fv( contours[contour_cnt].p[point_cnt-1] );
contours[contour_cnt].p[point_cnt][0] = -1;
glEnd();
glFinish();
contour_cnt++;
contours[contour_cnt].point_cnt = 0;
}
}
/* ´¦ÀíÊó±êÏìÓ¦µÄº¯Êý£¬¸ù¾Ý°´¼üµÄÀàÐ͵÷Óò»Í¬µÄº¯Êý£º×ó¼üºÍÖмü¡£ */
void mouse_clicked( int button, int state, int x, int y )
{
/* ½«OpenGLµÄÏñËØ×ø±ê»»Îª±³¾°µÄÍø¸ñ×ø±ê£¬±³¾°Íø¸ñΪ±ß³¤Îª10µÄСÕý·½ÐÎ */
x -= x%10;
y -= y%10;
switch ( button ) {
case GLUT_LEFT_BUTTON: /* GLUT·¢ÏÖ×ó¼ü±»µã»÷ */
if ( state == GLUT_DOWN ) {
left_down( x, y );
}
break;
case GLUT_MIDDLE_BUTTON: /* Öмü±»µã»÷ */
if ( state == GLUT_DOWN ) {
middle_down( x, y );
}
break;
}
}
/* OpenGL»æÖƺ¯Êý£¬ÓÐÁ½ÖÖģʽ */
void display( void )
{
GLuint i,j;
GLuint point_cnt;
glClear( GL_COLOR_BUFFER_B99v );
switch ( mode )
{
case DEFINE: /* ¶à±ßÐζ¨Òå½×¶Î */
/* »æÖÆÍø¸ñ£¬µ¥¸öÍø¸ñ´óСΪ10ÏñËØ£¬Íø¸ñÊýÄ¿È¡¾öÓÚOpenGL´°¿Ú´óС */
glColor3f ( 0.6, 0.5, 0.5 );
glBegin ( GL_LINES );
for ( i = 0 ; i < width ; i += 10 ){
for ( j = 0 ; j < height ; j += 10 ) {
glVertex2i ( 0, j );
glVertex2i ( width, j );
glVertex2i ( i, height );
glVertex2i ( i, 0 );
}
}
/* »æÖƶà±ßÐÎ */
glColor3f( 1.0, 1.0, 0.0 );
for ( i = 0 ; i <= contour_cnt ; i++ ) {
point_cnt = contours[i].point_cnt;
glBegin( GL_LINES );
switch ( point_cnt ) {
case 0:
break;
case 1:
glVertex2fv ( contours[i].p[0] );
glVertex2fv ( contours[i].p[0] );
break;
case 2:
glVertex2fv( contours[i].p[0] );
glVertex2fv( contours[i].p[1] );
break;
default:
--point_cnt;
for ( j = 0 ; j < point_cnt ; j++ ) {
glVertex2fv ( contours [ i ]. p [ j ] );
glVertex2fv ( contours [ i ] .p [ j+1 ] );
}
if ( contours [ i ].p [ j+1 ] [ 0 ] == -1 )
{
glVertex2fv ( contours [ i ]. p [ 0 ] );
glVertex2fv ( contours [ i ] .p [ j ] );
}
break;
}
glEnd();
}
glFinish();
break;
case TESSELATED: /* »æÖÆÏâǶºóµÄ¶à±ßÐΣ¬ÏÔʾÁбíÓɺ¯Êýtesse£¨£©¸ø³ö */
glColor3f( 0.7, 0.7, 0.0 );
glCallList( list_start );
glLineWidth( 2.0 );
glCallList( list_start + 1 );
glLineWidth( 1.0 );
glFlush();
break;
}
glColor3f( 1.0, 1.0, 0.0 );
}
/* ²Ëµ¥Ñ¡ÏîclearµÄÏìÓ¦º¯Êý£¬½«ËùÓбäÁ¿ÇåÁ㣬»æÖÆģʽÉèΪDEFINE */
void clear( void )
{
contour_cnt = 0;
contours[0].point_cnt = 0;
triangle_cnt = 0;
mode = DEFINE;
glDeleteLists( list_start, 2 );
list_start = 0;
}
/* ²Ëµ¥Ñ¡ÏîquitµÄÏìÓ¦º¯Êý£¬Í˳ö³ÌÐò */
void quit( void )
{
exit( 0 );
}
/* ¶¨Òå²Ëµ¥µÄÏìÓ¦º¯Êý */
void menu_selected( int entry )
{
switch ( entry ) {
case CLEAR:
clear ( );
break;
case TESSELATE:
tesse ( );
break;
case QU99v:
quit ( );
break;
}
/* Ñ¡Ôñ²Ëµ¥ºóÖØ»æOpenGL´°¿Ú */
glutPostRedisplay();
}
/* ¶¨Òå¿ì½Ý¼üÏìÓ¦º¯Êý */
void key_pressed( unsigned char key, int x, int y )
{
/* ÔÚ´ËÀý×ÓÖУ¬²»ÐèÒªÓñíÃ÷Êó±êλÖõıäÁ¿xºÍy */
( void ) x; ( void ) y;
/* Õë¶Ô²»Í¬°´¼ü£¬¶¨Ò嶯×÷ */
switch ( key ) {
case 'c':
case 'C':
clear();
break;
case 't':
case 'T':
tesse();
break;
case 'q':
case 'Q':
quit();
break;
}
/* °´¼üºóÖػ洰¿Ú */
glutPostRedisplay();
}
/* Ö´ÐÐһЩ³ÌÐòµÄ³õʼ»¯¹ý³Ì */
void myinit( void )
{
/* ÉèÖô°¿Ú±³¾°ÑÕÉ«*/
glClearColor( 0.4, 0.4, 0.4, 0.0 );
glShadeModel( GL_FLAT );
glPolygonMode( GL_FRONT, GL_FILL );
/* ´´½¨Ò»¸ö²Ëµ¥£¬²¢¶¨Òå²Ëµ¥Ïî¼°¸Ã²Ëµ¥¶ÔÓ¦µÄÏìÓ¦º¯Êý */
menu = glutCreateMenu( menu_selected );
glutAddMenuEntry( "clear", CLEAR );
glutAddMenuEntry( "tesselate", TESSELATE );
glutAddMenuEntry( "quit", QU99v );
/* ¶¨Òå²Ëµ¥¶¯×÷·½Ê½£ºµã»÷ÓÒ¼üµ¯³ö */
glutAttachMenu( GLUT_RIGHT_BUTTON );
/* ×¢²áÊó±êʼþÏìÓ¦º¯Êý */
glutMouseFunc( mouse_clicked );
/* ×¢²á¼üÅÌʼþÏìÓ¦º¯Êý */
glutKeyboardFunc( key_pressed );
contour_cnt = 0;
mode = DEFINE;
}
/* ¶¨Òå´°¿Ú´óС¸Ä±äʱµÄÏìÓ¦ */
static void reshape( GLsizei w, GLsizei h )
{
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho( 0.0, (GLdouble)w, 0.0, (GLdouble)h, -1.0, 1.0 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
set_screen_wh( w, h );
}
int main( int argc, char **argv )
{
/* ´´½¨´°¿Ú */
glutInit ( & argc, argv );
glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize ( 400, 400 );
glutCreateWindow( argv[0] );
myinit();
glutDisplayFunc( display );
glutReshapeFunc( reshape );
glutMainLoop();
return 0;
}
3. ÓÃFLTK¿ª·¢OpenGL³ÌÐò
¡¡¡¡ ´ÓÉÏÃæµÄÀý×ÓÎÒÃDz»ÄÑ¿´³ö£¬ËäÈ»GLUTΪʵÏÖOpenGL±à³ÌÌṩÁË¿ÉÄÜ£¬µ«ÊÇ×÷ΪӦÓóÌÐò£¬ËüÊÇÔ¶Ô¶²»¹»µÄ¡£ËüÖ»ÌṩÁËÔʼ¡¢¼òªµÄ¿ØÖƺͲÙ×÷·½Ê½£¬Ã»ÓÐÒ»°ãÓ¦ÓóÌÐòËùÐèÒªµÄ°´Å¥¡¢²Ëµ¥Ìõ¡¢ÊäÈë¿òµÈ¿Ø¼þ¡£ÊÂʵÉÏ£¬GLUT²¢²»ÊÇÓÃÀ´µ¥¶À¿ª·¢Ó¦ÓóÌÐòµÄ£¬ËüÊÇÓÃ×÷½éÓÚOpenGLº¯Êý½Ó¿ÚºÍÒ»°ãµÄͼÐνçÃ濪·¢½Ó¿ÚÖ®¼äµÄ¹ý¶É²ã¡£ÔÚÕâÒ»µãÉÏ£¬ËüÎÞÒÉÊdzɹ¦µÄ¡£MesaÑ¡ÔñËü×÷Ϊ±ê×¼Ì×¼þ·Ö·¢£¬´ó¶àÊýͼÐνçÃ濪·¢¹¤¾ßÒ²±£³ÖÓëËüµÄ¼æÈÝÐÔ¡£´Ó¶øʹµÃÓÃGLUT¿ª·¢µÄOpenGL³ÌÐòÓÐÁ¼ºÃµÄ¿ÉÒÆÖ²ÐÔ¡£
¡¡¡¡ ºÍGLUT²»Í¬£¬FLTK±¾ÉíÊÇÒ»¸öͼÐνçÃ濪·¢¹¤¾ß£¬Ê¹ÓÃËüÍêÈ«¿ÉÒÔ¿ª·¢ÊµÓõġ¢ÉÌÓõÄÓ¦ÓóÌÐò¡£FLTKÓÃC++±àд£¬Ê¹ÓÃÃæÏò¶ÔÏóµÄ¿ª·¢¼¼Êõ£¬ËüÌṩ¶àÖÖ×é¼þ¹©Óû§Ñ¡Óã¬Ã¿¸ö×é¼þÓÐ×Ô¼ºµÄÊôÐÔºÍʼþ¡£ÔÚÕâÀÎÒÃÇÖ÷Òª½²ÊöËüµÄOpenGL´°¿Ú×é¼þ£ºFl_Gl_Window£¬²¢³ä·ÖʹÓÃC++µÄÌØÐÔ¡£
¡¡¡¡ ÕâÒ»½ÚÀÎÒÃÇ»æÖÆÒ»¸ö¿ÉÒÔ×ÔÓÉÐýת¡¢Æ½ÒÆ¡¢·ÅËõµÄСÁ¢·½Ìå¡£³ÌÐòÔËÐкóÈçͼÎåËùʾ¡£Õû¸ö´°¿ÚÊÇÒ»¸öÓÉFl_Window×é¼þ¶¨ÒåµÄÒ»°ã´°¿Ú£¬ÖмäÊÇÒ»¸öOpenGL´°¿Ú¡£ÎÒÃÇʹÓÃÁËһЩ¿ØÖƹ¤¾ßÀ´µ÷ÕûСÁ¢·½ÌåµÄÊôÐÔ¡£ÉÏÃæµÄZoom±ê³ßµ÷ÕûËüµÄ´óС£¬×ó±ßºÍϱ߸÷ÓÐÒ»¸öƽÒƱê³ßºÍÒ»¸öÐýת±ê³ß£¬µ÷ÕûСÁ¢·½ÌåµÄλÖúͽǶȡ£ÕâЩ±ê³ß¶¼ÊÇFLTKµÄ±ê×¼×é¼þ£¬ËüÃǵÄ×÷ÓÃÊǸù¾ÝÓû§µÄ¶¯×÷·µ»ØÌض¨µÄÕûÊý»ò·ûµãÊý¡£
¡¡¡¡ Fl_Gl_Window×îÖØÒªµÄÊÇÁ½¸öÐ麯Êý£ºdraw£¨£©¡¢handle£¨£©ºÍ³ÉÔ±º¯Êýredraw£¨£©¡£º¯Êýdraw£¨£©Öж¨Òå»æÖÆÄÚÈÝ£¬´´½¨´°¿ÚºÍ´°¿Ú´óС¸Ä±äÊÇÕâ¸öº¯Êý±»×Ô¶¯µ÷Ó᣺¯Êýhandle£¨£©Öж¨Òå¶Ô¸÷ÖÖ¼üÅÌ¡¢Êó±êʼþµÄÏìÓ¦¡£µ±ÓмüÅÌ¡¢Êó±êʼþÏìӦʱ£¬Õâ¸öº¯Êý±»×Ô¶¯µ÷Óã¬ÈçºÎÓÐÏìӦʼþµÄº¯Êý±»¶¨Ò壬Ôò»áÖ´Ðд˺¯Êý¡£º¯Êýredraw£¨£©Öػ洰¿Ú¡£ÔÚÕâ¸ö½Ð×öCubeViewµÄÀý×ÓÖУ¬ÎÒÃÇÅÉÉúFl_Gl_Window£¬µÃµ½»æÖÆÎÒÃÇÕâ¸öСÁ¢·½ÌåµÄOpenGL´°¿Ú¡£
// ÎļþCubeView.cxx£¬ÅÉÉúFl_Gl_Window£¬µÃµ½»æÖÆСÁ¢·½ÌåµÄOpenGL´°¿Ú
#include
#include
#include
#include
#include
// ÅÉÉúÀàCubeViewµÄ¶¨Òå
class CubeView : public Fl_Gl_Window {
public:
double size; // ¶¨ÒåСÁ¢·½ÌåµÄ´óС£¬¹©glScalef£¨£©º¯ÊýʹÓÃ
// ¹¹Ô캯Êý£¬ÅÉÉú×ÔFl_Gl_Window£¬¶¨Òå´°¿Ú´óСºÍ±êÌâ
CubeView(int x,int y,int w,int h,const char *l=0);
// ÉèÖúÍÈ¡µÃ´¹Ö±·½ÏòµÄÐýת½Ç¶È£¬¹©×é¼þ±ê³ßµ÷ÓÃ
void v_angle(float angle){vAng=angle;};
float v_angle(){return vAng;};
// ÉèÖúÍÈ¡µÃˮƽ·½ÏòµÄÐýת½Ç¶È£¬¹©×é¼þ±ê³ßµ÷ÓÃ
void h_angle(float angle){hAng=angle;};
float h_angle(){return hAng;};
// ÉèÖÃˮƽºÍ´¹Ö±·½ÏòµÄÆ«ÒÆÁ¿
void panx(float x){xshift=x;};
void pany(float y){yshift=y;};
void draw();
private:
void drawCube();
float vAng,hAng;
float xshift,yshift;
float boxv0[3];float boxv1[3];
float boxv2[3];float boxv3[3];
float boxv4[3];float boxv5[3];
float boxv6[3];float boxv7[3];
};
// ¹¹Ô캯ÊýµÄ¶¨Òå
CubeView::CubeView(int x,int y,int w,int h,const char *l)
: Fl_Gl_Window(x,y,w,h,l)
{
// ÉèÖñ任³õÖµ
vAng = 0.0;
hAng=0.0;
size=10.0;
// ÉèÖÃСÁ¢·½Ì嶥µã²ÎÊý
boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
};
void CubeView::drawCube() {
// »æÖÆÒ»¸ö°ë͸Ã÷µÄÁ¢·½Ìå
#define ALPHA 0.5
glShadeModel(GL_FLAT);
// Óò»Í¬µÄÑÕÉ«»æÖÆÁù¸öÃæ
glBegin(GL_QUADS);
glColor4f (0.0, 0.0, 1.0, ALPHA );
glVertex3fv ( boxv0 ); glVertex3fv ( boxv1 ); glVertex3fv ( boxv2 ); glVertex3fv( boxv3 );
glColor4f(1.0, 1.0, 0.0, ALPHA);
glVertex3fv ( boxv0 ); glVertex3fv ( boxv4 ); glVertex3fv ( boxv5 ); glVertex3fv ( boxv1 );
glColor4f(0.0, 1.0, 1.0, ALPHA);
glVertex3fv ( boxv2 ); glVertex3fv ( boxv6 ); glVertex3fv ( boxv7 ); glVertex3fv ( boxv3 );
glColor4f(1.0, 0.0, 0.0, ALPHA);
glVertex3fv ( boxv4 ); glVertex3fv ( boxv5 ); glVertex3fv ( boxv6 ); glVertex3fv ( boxv7 );
glColor4f(1.0, 0.0, 1.0, ALPHA);
glVertex3fv ( boxv0 ); glVertex3fv ( boxv3 ); glVertex3fv ( boxv7 ); glVertex3fv ( boxv4 );
glColor4f(0.0, 1.0, 0.0, ALPHA);
glVertex3fv ( boxv1 ); glVertex3fv ( boxv5 ); glVertex3fv ( boxv6 ); glVertex3fv ( boxv2 );
glEnd();
// »æÖÆÁ¢·½ÌåµÄÂÖÀªÏߣ¬Ò»¹²12Ìõ
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINES);
glVertex3fv ( boxv0 ); glVertex3fv ( boxv1 );
glVertex3fv ( boxv1 ); glVertex3fv ( boxv2 );
glVertex3fv ( boxv2 ); glVertex3fv ( boxv3 );
glVertex3fv ( boxv3 ); glVertex3fv ( boxv0 );
glVertex3fv ( boxv4 ); glVertex3fv ( boxv5 );
glVertex3fv ( boxv5 ); glVertex3fv ( boxv6 );
glVertex3fv ( boxv6 ); glVertex3fv ( boxv7 );
glVertex3fv ( boxv7 ); glVertex3fv ( boxv4 );
glVertex3fv ( boxv0 ); glVertex3fv ( boxv4 );
glVertex3fv ( boxv1 ); glVertex3fv ( boxv5 );
glVertex3fv ( boxv2 ); glVertex3fv ( boxv6 );
glVertex3fv ( boxv3 ); glVertex3fv ( boxv7 );
glEnd();
};
void CubeView::draw() {
if (!valid ( ) ) {
//valid£¨£©µ±´°¿Ú´óС¸Ä±äʱ¸Ä±ä£¬µ¼ÖÂÕâÒ»²¿·ÖÄÚÈݱ»Ö´ÐУ¬ÖØÐÂÉèÖô°¿Ú
glLoadIdentity();
glViewport(0,0,w(),h());
glOrtho(-10,10,-10,10,-20000,10000);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
glClear (GL_COLOR_BUFFER_B99v | GL_DEPTH_BUFFER_B99v );
glPushMatrix ( );
// ±ä»»¡£²ÎÊý»æ±»Íⲿº¯ÊýÐÞ¸Ä
glTranslatef ( xshift, yshift, 0);
glRotatef ( hAng, 0, 1, 0 ); glRotatef ( vAng, 1, 0, 0 );
glScalef ( float ( size ), float ( size ) , float ( size ) );
// »æÖÆÁ¢·½Ìå
drawCube ( );
glPopMatrix ( );
};
ÉÏÃæµÄÀàCubeView¶¨ÒåÁËÒ»¸ö»æÖÆÁ¢·½ÌåµÄOpenGL´°¿Ú£¬Íⲿº¯Êý¿ÉÒÔµ÷ÓÃËüµÄ³ÉÔ±º¯Êýv_angle¡¢h_angle¡¢panx¡¢panyµÈÀ´ÐÞ¸ÄÕâ¸öСÁ¢·½ÌåµÄÊôÐÔ£¬ÐÞ¸ÄÒԺ󣬿ÉÒÔµ÷Óú¯Êýredraw£¨£©À´Ë¢Ð´°¿Ú¡£ÔÚÏÂÃæµÄCubeViewUI.cxxÖУ¬ÎÒÃǶ¨ÒåÀàCubeViewUI£¬Ëü»æÖÆÖ÷´°¿Ú£¬²¢ÔÚÆäÖж¨ÒåÁËÀàCubeViewµÄÒ»¸öʵÀý£ºcube¡£Ëüͬʱ»¹¶¨ÒåÁËÓÃÀ´¿ØÖÆÁ¢·½ÌåÊôÐÔµÄ5¸ö±ê³ß£¬µ±Óû§²Ù×÷±ê³ßʱ£¬ÕâЩ±ê³ßµ÷ÓÃv_angleµÈº¯ÊýÀ´ÉèÖûæÖÆÁ¢·½ÌåµÄһЩ²ÎÊý¡£ÕâÒ»²¿·ÖºÍÎÒÃǵÄÖ÷Ìâ¹Øϵ²»´ó£¬²»¸ø³ö¾ßÌåµÄ´úÂë¡£×îºó£¬ÎÒÃǶ¨Òåmainº¯Êý£¬ËüµÄÄÚÈÝÏ൱µÄ¼òµ¥¡£
#include "CubeViewUI.h"
int main(int argc, char **argv) {
// ¶¨ÒåÀàCubeViewUIµÄÒ»¸öʵÀý
CubeViewUI *cvui=new CubeViewUI;
// ÉèÖÃFLTK´°¿ÚÏÔʾģʽ
Fl::visual(FL_DOUBLE|FL_INDEX);
cvui->show();
// ½øÈëÏûϢѻ·
return Fl::run();
}
ÎÒÃDZàÒë¡¢Á¬½Ó²¢Ö´ÐгÌÐò£¬¾Í¿ÉÒԵõ½ÈçͼÎåËùʾµÄ½á¹û¡£´ÓÉÏÃæµÄÀý×ÓÎÒÃÇ¿ÉÒÔ¿´³öʹÓÃFLTK±àдOpenGL³ÌÐòµÄһЩÓŵ㣬ºÍGLUTËü½á¹¹ÇåÎú£¬Ê¹Ó÷½±ã£¬¶øÇÒËüºÍGLUTÊǼæÈݵġ£³ýÁËglutInit£¨£©¡¢glutMainLoop£¨£©µÈÉÙÊýº¯ÊýÍ⣬´ó²¿·ÖGLUTº¯Êý¿ÉÒÔÔÚFLTKÖÐʹÓá£FLTK±¾ÉíÒ²ÌṩÁËÐí¶àOpenGLº¯Êý£¬Èç»æÖÆ×Ö·û´®µÄgl_draw£¨£©µÈ¡£
4. ½áÊøÓï
¡¡¡¡ ÊìϤÕÆÎÕÁËLinuxÏÂOpenGLµÄ¿ª·¢»·¾³¾àÀ뿪·¢OpenGL³ÌÐò»¹ÓкܴóµÄ¾àÀ룬±Ï¾¹ÎÊÌâµÄÄѵãÊÇÈçºÎºÜºÃµÄʹÓÃOpenGLµÄAPI¡£±¾ÎÄΪ¼´½«ÔÚLinuxÏ¿ª·¢OpenGLµÄ¶ÁÕß×÷һЩÆ̵æºÍ×¼±¸¹¤×÷£¬Ï£Íû²¢ÏàÐŶԴó¼ÒÓÐËù°ïÖú¡£
honglianqxw123 ÓÚ 2012-06-23 07:51:24·¢±í:
лл¥Ö÷£¬Ñ§Ï°¡£
hkhantang ÓÚ 2012-06-17 21:59:55·¢±í:
kankan
ÓÚ 2012-06-16 10:26:32·¢±í:
ÓеãС´íÎó°¢
59.25.9.* ÓÚ 2007-07-19 06:02:27·¢±í:
http://www.ringtones-rate.com/mp3/ ringtones site. Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. from website .
59.25.9.* ÓÚ 2007-07-19 06:02:17·¢±í:
http://www.ringtones-rate.com/mp3/ ringtones site. qwest ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. nextel ringtones from website .
59.25.9.* ÓÚ 2007-07-19 06:02:16·¢±í:
http://www.ringtones-rate.com/tones/ real ringtones. motorola ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-rate.com/ring/ [link=http://www.ringtones-rate.com]tracfone ringtones[/link] from site .
194.88.214.* ÓÚ 2007-07-19 06:02:10·¢±í:
http://www.ringtones-rate.com/tones/ real ringtones. motorola ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-rate.com/ring/ [link=http://www.ringtones-rate.com]tracfone ringtones[/link] from site .
194.88.214.* ÓÚ 2007-07-19 06:02:10·¢±í:
http://www.ringtones-rate.com/tones/ real ringtones. motorola ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-rate.com/ring/ [link=http://www.ringtones-rate.com]tracfone ringtones[/link] from site .
194.88.214.* ÓÚ 2007-07-19 06:01:47·¢±í:
http://www.ringtones-rate.com/tones/ real ringtones. motorola ringtones: Free nokia ringtones here, Download ringtones FREE, Best free samsung ringtones. http://www.ringtones-rate.com/ring/ [link=http://www.ringtones-rate.com]tracfone ringtones[/link] from site .