gsub.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #if defined(_WIN32)
00004 #include <windows.h>
00005 #include <string.h>
00006 #endif
00007 #ifndef __APPLE__
00008 #  include <GL/glut.h>
00009 #  ifdef GL_VERSION_1_2
00010 #    include <GL/glext.h>
00011 #  endif
00012 #else
00013 #  include <GLUT/glut.h>
00014 #  include <OpenGL/glext.h>
00015 #endif
00016 #include <AR/config.h>
00017 #include <AR/param.h>
00018 #include <AR/ar.h>
00019 #include <AR/gsub.h>
00020 
00021 #ifndef GL_ABGR
00022 #  define GL_ABGR GL_ABGR_EXT
00023 #endif
00024 #ifndef GL_BGRA
00025 #  define GL_BGRA GL_BGRA_EXT
00026 #endif
00027 #ifndef GL_BGR
00028 #  define GL_BGR GL_BGR_EXT
00029 #endif
00030 #ifndef GL_RGBA
00031 #  define GL_RGBA GL_RGBA_EXT
00032 #endif
00033 #ifndef GL_RGB
00034 #  define GL_RGB GL_RGB_EXT
00035 #endif
00036 
00037 #ifdef AR_OPENGL_TEXTURE_RECTANGLE
00038 #  if defined(GL_TEXTURE_RECTANGLE_EXT)
00039 #    define AR_TEXTURE_RECTANGLE   GL_TEXTURE_RECTANGLE_EXT
00040 #  elif defined(GL_TEXTURE_RECTANGLE_NV)
00041 #    define AR_TEXTURE_RECTANGLE   GL_TEXTURE_RECTANGLE_NV
00042 #  else
00043 #    undef AR_OPENGL_TEXTURE_RECTANGLE
00044 #  endif
00045 #endif
00046 
00047 #define   MINIWIN_MAX    8
00048 #define   REVERSE_LR     1
00049 #define   LEFTEYE        1
00050 #define   RIGHTEYE       2
00051 #define   GMINI          2
00052 
00053 int  argDrawMode   = DEFAULT_DRAW_MODE;
00054 int  argTexmapMode = DEFAULT_DRAW_TEXTURE_IMAGE;
00055 
00056 
00057 static ARParam  gCparam;
00058 static ARSParam gsCparam;
00059 static double   gl_cpara[16];
00060 //static double   gl_cparaL[16];
00061 //static double   gl_cparaR[16];
00062 static double   gl_lpara[16];
00063 static double   gl_rpara[16];
00064 static int      gl_hmd_flag      = 0;
00065 static int      gl_hmd_para_flag = 0;
00066 static int      gl_stereo_flag   = 0;
00067 //static int      gl_twin_flag     = 0;
00068 
00069 static double   gZoom;
00070 static int      gXsize, gYsize;
00071 static int      gMiniXnum,  gMiniYnum;
00072 static int      gMiniXsize, gMiniYsize;
00073 static int      gWinXsize, gWinYsize;
00074 static int      gImXsize, gImYsize;
00075 static int      win;
00076 static GLuint   glid[4];
00077 
00078 static void (*gMouseFunc)(int button, int state, int x, int y);
00079 static void (*gKeyFunc)(unsigned char key, int x, int y);
00080 static void (*gMainFunc)(void);
00081 
00082 
00083 static void argInit2( int fullFlag );
00084 static void argInitLoop(void);
00085 static void argInitStencil(void);
00086 static void argSetStencil( int flag );
00087 static void argConvGLcpara2( double cparam[3][4], int width, int height, double gnear, double gfar, double m[16] );
00088 
00089 
00090 static int    useTextureRectangle = 0;
00091 static GLint  maxRectangleTextureSize = 0;
00092 static int    tex1Xsize1 = 1;
00093 static int    tex1Xsize2 = 1;
00094 static int    tex1Ysize  = 1;
00095 static int    tex2Xsize  = 1;
00096 static int    tex2Ysize  = 1;
00097 #ifdef AR_OPENGL_TEXTURE_RECTANGLE
00098 static void   argDispImageTexRectangle( ARUint8 *image, int xwin, int ywin, int mode );
00099 #endif
00100 static void   argDispImageTex3( ARUint8 *image, int xwin, int ywin, int mode );
00101 static void   argDispImageTex4( ARUint8 *image, int xwin, int ywin, int mode );
00102 static void   argDispHalfImageTex( ARUint8 *image, int xwin, int ywin, int mode );
00103 static void   argDispImageDrawPixels( ARUint8 *image, int xwin, int ywin );
00104 static void   argDispHalfImageDrawPixels( ARUint8 *image, int xwin, int ywin );
00105 
00106 void argInqSetting( int *hmdMode,
00107                     int *gMiniXnum2, int *gMiniYnum2,
00108                     void (**mouseFunc)(int button, int state, int x, int y),
00109                     void (**keyFunc)(unsigned char key, int x, int y),
00110                     void (**mainFunc)(void) )
00111 {
00112     *hmdMode    = gl_hmd_flag;
00113     *gMiniXnum2 = gMiniXnum;
00114     *gMiniYnum2 = gMiniYnum;
00115     *mouseFunc = gMouseFunc;
00116     *keyFunc   = gKeyFunc;
00117     *mainFunc  = gMainFunc;
00118 }
00119 
00120 void argInit( ARParam *cparam, double zoom, int fullFlag, int xwin, int ywin, int hmd_flag )
00121 {
00122     int       i;
00123 
00124     gl_hmd_flag = hmd_flag;
00125     gZoom  = zoom;
00126     gImXsize = cparam->xsize;
00127     gImYsize = cparam->ysize;
00128     if( gl_hmd_flag == 0 ) {
00129         gXsize = (double)cparam->xsize * gZoom;
00130         gYsize = (double)cparam->ysize * gZoom;
00131     }
00132     else {
00133         gXsize = AR_HMD_XSIZE;
00134         gYsize = AR_HMD_YSIZE;
00135     }
00136     gMiniXsize = (double)cparam->xsize * gZoom / GMINI;
00137     gMiniYsize = (double)cparam->ysize * gZoom / GMINI;
00138 
00139     if( xwin * ywin > MINIWIN_MAX ) {
00140         if( xwin > MINIWIN_MAX ) xwin = MINIWIN_MAX;
00141         ywin = MINIWIN_MAX / xwin;
00142     }
00143     gMiniXnum = xwin;
00144     gMiniYnum = ywin;
00145     gWinXsize = (gMiniXsize*gMiniXnum > gXsize)?
00146                      gMiniXsize*gMiniXnum: gXsize;
00147     gWinYsize = gYsize + gMiniYsize*gMiniYnum;
00148 
00149     gCparam = *cparam;
00150     for( i = 0; i < 4; i++ ) {
00151         gCparam.mat[1][i] = (gCparam.ysize-1)*(gCparam.mat[2][i]) - gCparam.mat[1][i];
00152     }
00153     argConvGLcpara( &gCparam, AR_GL_CLIP_NEAR, AR_GL_CLIP_FAR, gl_cpara );
00154 
00155     argInit2( fullFlag );
00156 }
00157 
00158 static void argInit2( int fullFlag )
00159 {
00160     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_STENCIL);
00161     glutInitWindowPosition(0, 0);
00162     glutInitWindowSize(gWinXsize, gWinYsize);
00163     win = glutCreateWindow("");
00164     if( fullFlag ) {
00165         glutFullScreen();
00166         gWinXsize = glutGet(GLUT_SCREEN_WIDTH);
00167         gWinYsize = glutGet(GLUT_SCREEN_HEIGHT);
00168     }
00169 
00170 #ifdef AR_OPENGL_TEXTURE_RECTANGLE
00171 #if defined(GL_TEXTURE_RECTANGLE_EXT)
00172     if( glutExtensionSupported("GL_EXT_texture_rectangle") ) {
00173         useTextureRectangle = 1;
00174         glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_EXT, &maxRectangleTextureSize);
00175     }
00176 #elif defined(GL_TEXTURE_RECTANGLE_NV)
00177     if( glutExtensionSupported("GL_NV_texture_rectangle") ) {
00178         useTextureRectangle = 1;
00179         glGetIntegerv(GL_MAX_RECTANGLE_TEXTURE_SIZE_NV, &maxRectangleTextureSize);
00180     }
00181 #endif
00182 #endif
00183 
00184     gMouseFunc = NULL;
00185     gKeyFunc   = NULL;
00186     gMainFunc  = NULL;
00187 
00188 
00189     glGenTextures(4, glid);
00190     glBindTexture( GL_TEXTURE_2D, glid[0] );
00191     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
00192     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00193     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00194     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00195     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00196     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00197     glBindTexture( GL_TEXTURE_2D, glid[1] );
00198     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
00199     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00200     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00201     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00202     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00203     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00204     glBindTexture( GL_TEXTURE_2D, glid[2] );
00205     glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
00206     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
00207     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );
00208     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00209     glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
00210     glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00211 
00212     if( gImXsize > 512 ) {
00213         tex1Xsize1 = 512;
00214         tex1Xsize2 = 1;
00215         while( tex1Xsize2 < gImXsize - tex1Xsize1 ) tex1Xsize2 *= 2;
00216     }
00217     else {
00218         tex1Xsize1 = 1;
00219         while( tex1Xsize1 < gImXsize ) tex1Xsize1 *= 2;
00220     }
00221     tex1Ysize  = 1;
00222     while( tex1Ysize < gImYsize ) tex1Ysize *= 2;
00223 
00224     tex2Xsize = 1;
00225     while( tex2Xsize < gImXsize/2 ) tex2Xsize *= 2;
00226     tex2Ysize = 1;
00227     while( tex2Ysize < gImYsize/2 ) tex2Ysize *= 2;
00228 }
00229 
00230 void argCleanup( void )
00231 {
00232 /*
00233     glutDestroyWindow( win );
00234 */
00235 }
00236 
00237 void argSwapBuffers( void )
00238 {
00239     glutSwapBuffers();
00240 }
00241 
00242 void argMainLoop( void (*mouseFunc)(int button, int state, int x, int y),
00243                   void (*keyFunc)(unsigned char key, int x, int y),
00244                   void (*mainFunc)(void) )
00245 {
00246     gMouseFunc = mouseFunc;
00247     gKeyFunc   = keyFunc;
00248     gMainFunc  = mainFunc;
00249 
00250     glutDisplayFunc( argInitLoop );
00251     glutMainLoop();
00252 }
00253 
00254 static void argInitLoop(void)
00255 {
00256     arUtilSleep( 500 );
00257 
00258     argDrawMode2D();
00259     if( gl_hmd_flag || gl_stereo_flag ) {
00260         glClearColor( 0.0, 0.0, 0.0, 0.0 );
00261         glClear(GL_COLOR_BUFFER_BIT);
00262         argInitStencil();
00263         argSwapBuffers();
00264     }
00265 
00266     glClearColor( 0.0, 0.0, 0.0, 0.0 );
00267     glClear(GL_COLOR_BUFFER_BIT);
00268     argSwapBuffers();
00269     glClear(GL_COLOR_BUFFER_BIT);
00270     argSwapBuffers();
00271 
00272     glutKeyboardFunc( gKeyFunc );
00273     glutMouseFunc( gMouseFunc );
00274     glutDisplayFunc( gMainFunc );
00275     glutIdleFunc( gMainFunc );
00276 }
00277 
00278 void argDrawMode2D( void )
00279 {
00280     glMatrixMode(GL_MODELVIEW);
00281     glLoadIdentity();
00282     glMatrixMode(GL_PROJECTION);
00283     glLoadIdentity();
00284     glOrtho(0, gWinXsize, 0, gWinYsize, -1.0, 1.0);
00285     glViewport(0, 0, gWinXsize, gWinYsize);
00286 
00287     argSetStencil( 0 );
00288 }
00289 
00290 void argDraw2dLeft( void )
00291 {
00292     if( gl_hmd_flag == 0 && gl_stereo_flag == 0 ) return;
00293 
00294     argSetStencil( LEFTEYE );
00295 }
00296 
00297 void argDraw2dRight( void )
00298 {
00299     if( gl_hmd_flag == 0 && gl_stereo_flag == 0 ) return;
00300 
00301     argSetStencil( RIGHTEYE );
00302 }
00303 
00304 void argDrawMode3D( void )
00305 {
00306     glMatrixMode(GL_MODELVIEW);
00307     glLoadIdentity();
00308 }
00309 
00310 void argDraw3dLeft( void )
00311 {
00312     if( gl_hmd_flag == 0 || gl_hmd_para_flag == 0 ) return;
00313 
00314     glViewport(0, gWinYsize-AR_HMD_YSIZE, AR_HMD_XSIZE, AR_HMD_YSIZE);
00315     argSetStencil( LEFTEYE );
00316     glMatrixMode(GL_PROJECTION);
00317     glLoadMatrixd( gl_lpara );
00318 }
00319 
00320 void argDraw3dRight( void )
00321 {
00322     if( gl_hmd_flag == 0 || gl_hmd_para_flag == 0 ) return;
00323 
00324     glViewport(0, gWinYsize-AR_HMD_YSIZE, AR_HMD_XSIZE, AR_HMD_YSIZE);
00325     argSetStencil( RIGHTEYE );
00326     glMatrixMode(GL_PROJECTION);
00327     glLoadMatrixd( gl_rpara );
00328 }
00329 
00330 
00331 void argDraw3dCamera( int xwin, int ywin )
00332 {
00333     if( xwin == 0 && ywin == 0 ) {
00334         glViewport(0, gWinYsize-(int)(gZoom*gImYsize),
00335                    (int)(gZoom*gImXsize), (int)(gZoom*gImYsize));
00336     }
00337     else {
00338         glViewport((xwin-1)*gMiniXsize, gWinYsize-gYsize-ywin*gMiniYsize,
00339                                         gMiniXsize, gMiniYsize);
00340     }
00341 
00342     argSetStencil( 0 );
00343     
00344     glMatrixMode(GL_PROJECTION);
00345     glLoadMatrixd( gl_cpara );
00346 }
00347 
00348 
00349 void argConvGlpara( double para[3][4], double gl_para[16] )
00350 {
00351     int     i, j;
00352 
00353     for( j = 0; j < 3; j++ ) {
00354         for( i = 0; i < 4; i++ ) {
00355             gl_para[i*4+j] = para[j][i];
00356         }
00357     }
00358     gl_para[0*4+3] = gl_para[1*4+3] = gl_para[2*4+3] = 0.0;
00359     gl_para[3*4+3] = 1.0;
00360 }
00361 
00362 
00363 void argDispImage( ARUint8 *image, int xwin, int ywin )
00364 {
00365     if( argDrawMode == AR_DRAW_BY_GL_DRAW_PIXELS ) {
00366         argDispImageDrawPixels( image, xwin, ywin );
00367     }
00368     else {
00369         if( xwin == 0 && ywin == 0 ) {
00370             glScissor(0, gWinYsize-(int)(gZoom*gImYsize),
00371                       (int)(gZoom*gImXsize), (int)(gZoom*gImYsize));
00372         }
00373         else {
00374             glScissor((xwin-1)*gMiniXsize, gWinYsize-gYsize-ywin*gMiniYsize,
00375                        gMiniXsize, gMiniYsize);
00376         }
00377         glEnable( GL_SCISSOR_TEST );
00378         /* glDisable( GL_DEPTH_TEST ); */
00379         if( useTextureRectangle
00380          && gImXsize < maxRectangleTextureSize
00381          && gImYsize < maxRectangleTextureSize ) {
00382 #ifdef AR_OPENGL_TEXTURE_RECTANGLE
00383             argDispImageTexRectangle( image, xwin, ywin, 0 );
00384 #endif
00385         }
00386         else {
00387             if( gImXsize > tex1Xsize1 )
00388                 argDispImageTex3( image, xwin, ywin, 0 );
00389             else
00390                 argDispImageTex4( image, xwin, ywin, 0 );
00391         }
00392         glDisable( GL_SCISSOR_TEST );
00393     }
00394 }
00395 
00396 
00397 static void argDispImageDrawPixels( ARUint8 *image, int xwin, int ywin )
00398 {
00399     float    sx, sy;
00400     GLfloat  zoom;
00401 
00402     if( xwin == 0 && ywin == 0 ) {
00403         zoom = gZoom;
00404         sx = 0;
00405         sy = gWinYsize - 0.5;
00406     }
00407     else if( xwin == 1 && ywin == 0 ) {
00408         zoom = gZoom;
00409         sx = gXsize;
00410         sy = gWinYsize - 0.5;
00411     }
00412     else {
00413         zoom = gZoom / (double)GMINI;
00414         sx = (xwin-1)*gMiniXsize;
00415         sy = gWinYsize - gYsize - (ywin-1)*gMiniYsize - 0.5;
00416     }
00417         glDisable(GL_TEXTURE_2D);
00418     glPixelZoom( zoom, -zoom);
00419     glRasterPos3f( sx, sy, -1.0 );
00420 
00421 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00422 #  ifdef AR_BIG_ENDIAN
00423     glDrawPixels( gImXsize, gImYsize, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00424 #  else
00425     glDrawPixels( gImXsize, gImYsize, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00426 #  endif        
00427 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00428     glDrawPixels( gImXsize, gImYsize, GL_ABGR, GL_UNSIGNED_BYTE, image );
00429 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00430     glDrawPixels( gImXsize, gImYsize, GL_BGRA, GL_UNSIGNED_BYTE, image );
00431 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00432     glDrawPixels( gImXsize, gImYsize, GL_BGR, GL_UNSIGNED_BYTE, image );
00433 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00434     glDrawPixels( gImXsize, gImYsize, GL_RGBA, GL_UNSIGNED_BYTE, image );
00435 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00436     glDrawPixels( gImXsize, gImYsize, GL_RGB, GL_UNSIGNED_BYTE, image );
00437 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00438     glDrawPixels( gImXsize, gImYsize, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00439 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00440 #  ifdef AR_BIG_ENDIAN
00441     glDrawPixels( gImXsize, gImYsize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00442 #  else
00443     glDrawPixels( gImXsize, gImYsize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00444 #  endif        
00445 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00446 #  ifdef AR_BIG_ENDIAN
00447         glDrawPixels( gImXsize, gImYsize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00448 #  else
00449         glDrawPixels( gImXsize, gImYsize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00450 #  endif        
00451 #else
00452 #  error Unknown default pixel format defined in config.h
00453 #endif
00454 }
00455 
00456 #ifdef AR_OPENGL_TEXTURE_RECTANGLE
00457 static void argDispImageTexRectangle( ARUint8 *image, int xwin, int ywin, int mode )
00458 {
00459     static int      initf = 1;
00460     static int      flag[3][MINIWIN_MAX+2][2];
00461     static int      listIndex[3][MINIWIN_MAX+2][2];
00462     static int      old_size_adjust_factor = -1;
00463     double   *dist_factor;
00464     double   px, py, qy, z;
00465     double   x1, x2;
00466     double   y1, y2;
00467     double   xx1, xx2;
00468     double   yy1, yy2;
00469     int      size_adjust_factor;
00470     int      list, win;
00471     int      i, j;
00472 
00473     switch( mode ) {
00474                 case 0: dist_factor = &(gCparam.dist_factor[0]);   break;
00475                 case 1: dist_factor = &(gsCparam.dist_factorL[0]); break;
00476                 case 2: dist_factor = &(gsCparam.dist_factorR[0]); break;
00477                 default: return;
00478     }
00479 
00480     if( initf ) {
00481         for(j=0;j<3;j++) {
00482             for(i=0;i<MINIWIN_MAX+2;i++) flag[j][i][0] = flag[j][i][1] = 1;
00483         }
00484         initf = 0;
00485     }
00486     if( argTexmapMode == AR_DRAW_TEXTURE_HALF_IMAGE ) {
00487         size_adjust_factor = 2;
00488         list = 1;
00489     }
00490     else {
00491         size_adjust_factor = 1;
00492         list = 0;
00493     }
00494     if( xwin == 0 && ywin == 0 )      win = 0;
00495     else if( xwin == 1 && ywin == 0 ) win = 1;
00496     else win = gMiniXnum * (ywin-1) + xwin + 1;
00497 
00498     glEnable( AR_TEXTURE_RECTANGLE );
00499     glMatrixMode(GL_TEXTURE);
00500     glLoadIdentity();
00501     glMatrixMode(GL_MODELVIEW);
00502 
00503 
00504     glBindTexture( AR_TEXTURE_RECTANGLE, glid[3] );
00505 #ifdef APPLE_TEXTURE_FAST_TRANSFER
00506     glTexParameterf(AR_TEXTURE_RECTANGLE, GL_TEXTURE_PRIORITY, 0.0);
00507     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
00508 #endif
00509     glPixelStorei( GL_UNPACK_ROW_LENGTH, gImXsize*size_adjust_factor );
00510     if( size_adjust_factor == old_size_adjust_factor ) {
00511 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00512 #  ifdef AR_BIG_ENDIAN
00513         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00514 #  else
00515         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00516 #  endif        
00517 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00518         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_ABGR, GL_UNSIGNED_BYTE, image );
00519 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00520         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_BYTE, image );
00521 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00522         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_BGR, GL_UNSIGNED_BYTE, image );
00523 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00524         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_RGBA, GL_UNSIGNED_BYTE, image );
00525 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00526         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_RGB, GL_UNSIGNED_BYTE, image );
00527 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00528         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00529 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00530 #  ifdef AR_BIG_ENDIAN
00531         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00532 #  else
00533         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00534 #  endif        
00535 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00536 #  ifdef AR_BIG_ENDIAN
00537         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00538 #  else
00539         glTexSubImage2D( AR_TEXTURE_RECTANGLE, 0, 0, 0, gImXsize, gImYsize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_REV_8_8_APPLE, image );
00540 #  endif        
00541 #else
00542 #  error Unknown default pixel format defined in config.h
00543 #endif
00544     }
00545     else {
00546 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00547 #  ifdef AR_BIG_ENDIAN
00548         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGBA, gImXsize, gImYsize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00549 #  else
00550         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGBA, gImXsize, gImYsize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00551 #  endif        
00552 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00553         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGBA, gImXsize, gImYsize/size_adjust_factor, 0, GL_ABGR, GL_UNSIGNED_BYTE, image );
00554 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00555         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_BYTE, image );
00556 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00557         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_BGR, GL_UNSIGNED_BYTE, image );
00558 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00559         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGBA, gImXsize, gImYsize/size_adjust_factor, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
00560 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00561         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_RGB, GL_UNSIGNED_BYTE, image );
00562 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00563         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_LUMINANCE, gImXsize, gImYsize/size_adjust_factor, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00564 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00565 #  ifdef AR_BIG_ENDIAN
00566         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00567 #  else
00568         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00569 #  endif        
00570 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00571 #  ifdef AR_BIG_ENDIAN
00572         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00573 #  else
00574         glTexImage2D( AR_TEXTURE_RECTANGLE, 0, GL_RGB, gImXsize, gImYsize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00575 #  endif        
00576 #else
00577 #  error Unknown default pixel format defined in config.h
00578 #endif
00579         old_size_adjust_factor = size_adjust_factor;
00580     }
00581 
00582     if( flag[mode][win][list] ) {
00583         listIndex[mode][win][list] = glGenLists(1);
00584         glNewList(listIndex[mode][win][list], GL_COMPILE_AND_EXECUTE);
00585 
00586         z = -1.0;
00587         qy = gImYsize   * 0 / 20.0;
00588         for( j = 1; j <= 20; j++ ) {
00589             py = qy;
00590             qy = gImYsize * j / 20.0;
00591 
00592             glBegin( GL_QUAD_STRIP );
00593             for( i = 0; i <= 20; i++ ) {
00594                 px = gImXsize * i / 20.0;
00595 
00596                 arParamObserv2Ideal( dist_factor, px, py, &x1, &y1 );
00597                 arParamObserv2Ideal( dist_factor, px, qy, &x2, &y2 );
00598 
00599                 if( xwin == 0 && ywin == 0 ) {
00600                     xx1 = x1 * gZoom;
00601                     yy1 = gWinYsize - y1 * gZoom;
00602                     xx2 = x2 * gZoom;
00603                     yy2 = gWinYsize - y2 * gZoom;
00604                 }
00605                 else if( xwin == 1 && ywin == 0 ) {
00606                     xx1 = gXsize + x1 * gZoom;
00607                     yy1 = gWinYsize - y1 * gZoom;
00608                     xx2 = gXsize + x2 * gZoom;
00609                     yy2 = gWinYsize - y2 * gZoom;
00610                 }
00611                 else {
00612                     xx1 = (xwin-1)*gMiniXsize + x1*gZoom/(double)GMINI;
00613                     xx2 = (xwin-1)*gMiniXsize + x2*gZoom/(double)GMINI;
00614                     yy1 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y1*gZoom/(double)GMINI;
00615                     yy2 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y2*gZoom/(double)GMINI;
00616                 }
00617 
00618                 glTexCoord2d( px, py/size_adjust_factor ); glVertex3d( xx1, yy1, z );
00619                 glTexCoord2d( px, qy/size_adjust_factor ); glVertex3d( xx2, yy2, z );
00620             }
00621             glEnd();
00622         }
00623         glEndList();
00624         flag[mode][win][list] = 0;
00625     }
00626     else {
00627         glCallList( listIndex[mode][win][list] );
00628     }
00629 
00630     glBindTexture( AR_TEXTURE_RECTANGLE, 0 );
00631     glDisable( AR_TEXTURE_RECTANGLE );
00632     glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
00633 }
00634 #endif
00635 
00636 #ifndef _WIN32
00637 static void argDispImageTex4( ARUint8 *image, int xwin, int ywin, int mode )
00638 #else
00639 static void argDispImageTex4( ARUint8 *wimage, int xwin, int ywin, int mode )
00640 #endif
00641 {
00642     static int      initf = 1;
00643     static int      flag[3][MINIWIN_MAX+2][2];
00644     static int      listIndex[3][MINIWIN_MAX+2][2];
00645     static int      old_size_adjust_factor = -1;
00646 #ifdef _WIN32
00647     static ARUint8  *image = NULL;
00648 #endif
00649     double   *dist_factor;
00650     double   tsx, tsy, tex, tey;
00651     double   px, py, qx, qy, z;
00652     double   x1, x2, x3, x4;
00653     double   y1, y2, y3, y4;
00654     double   xx1, xx2, xx3, xx4;
00655     double   yy1, yy2, yy3, yy4;
00656     int      size_adjust_factor;
00657     int      list, win;
00658     int      i, j;
00659 
00660     switch( mode ) {
00661                 case 0: dist_factor = &(gCparam.dist_factor[0]);   break;
00662                 case 1: dist_factor = &(gsCparam.dist_factorL[0]); break;
00663                 case 2: dist_factor = &(gsCparam.dist_factorR[0]); break;
00664                 default: return;
00665     }
00666 
00667 #ifdef _WIN32
00668     if( image == NULL ) {
00669         arMalloc(image,ARUint8,gImXsize*tex1Ysize*AR_PIX_SIZE_DEFAULT);
00670     }
00671     memcpy(image, wimage, gImXsize*gImYsize*AR_PIX_SIZE_DEFAULT);
00672 #endif
00673 
00674     if( initf ) {
00675         for(j=0;j<3;j++) {
00676             for(i=0;i<MINIWIN_MAX+2;i++) flag[j][i][0] = flag[j][i][1] = 1;
00677         }
00678         initf = 0;
00679     }
00680     if( argTexmapMode == AR_DRAW_TEXTURE_HALF_IMAGE ) {
00681         size_adjust_factor = 2;
00682         list = 1;
00683     }
00684     else {
00685         size_adjust_factor = 1;
00686         list = 0;
00687     }
00688     if( xwin == 0 && ywin == 0 )      win = 0;
00689     else if( xwin == 1 && ywin == 0 ) win = 1;
00690     else win = gMiniXnum * (ywin-1) + xwin + 1;
00691 
00692     glEnable( GL_TEXTURE_2D );
00693     glMatrixMode(GL_TEXTURE);
00694     glLoadIdentity();
00695     glMatrixMode(GL_MODELVIEW);
00696 
00697     glBindTexture( GL_TEXTURE_2D, glid[0] );
00698 #ifdef APPLE_TEXTURE_FAST_TRANSFER
00699     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.0);
00700     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
00701 #endif
00702     glPixelStorei( GL_UNPACK_ROW_LENGTH, gImXsize*size_adjust_factor );
00703 
00704     if( size_adjust_factor == old_size_adjust_factor ) {
00705 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00706 #  ifdef AR_BIG_ENDIAN
00707         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00708 #  else
00709         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00710 #  endif
00711 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00712         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_ABGR, GL_UNSIGNED_BYTE, image );
00713 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00714         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_BYTE, image );
00715 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00716         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGR, GL_UNSIGNED_BYTE, image );
00717 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00718         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_RGBA, GL_UNSIGNED_BYTE, image );
00719 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00720         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_RGB, GL_UNSIGNED_BYTE, image );
00721 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00722         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00723 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00724 #  ifdef AR_BIG_ENDIAN
00725         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00726 #  else
00727         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00728 #  endif
00729 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00730 #  ifdef AR_BIG_ENDIAN
00731         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00732 #  else
00733         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00734 #  endif
00735 #else
00736 #  error Unknown default pixel format defined in config.h
00737 #endif
00738     }
00739     else {
00740 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00741 #  ifdef AR_BIG_ENDIAN
00742         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00743 #  else
00744         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00745 #  endif
00746 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00747         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_ABGR, GL_UNSIGNED_BYTE, image );
00748 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00749         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_BYTE, image );
00750 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00751         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGR, GL_UNSIGNED_BYTE, image );
00752 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00753         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
00754 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00755         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_RGB, GL_UNSIGNED_BYTE, image );
00756 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00757         glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00758 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00759 #  ifdef AR_BIG_ENDIAN
00760         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00761 #  else
00762         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00763 #  endif
00764 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00765 #  ifdef AR_BIG_ENDIAN
00766         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00767 #  else
00768         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00769 #  endif
00770 #else
00771 #  error Unknown default pixel format defined in config.h
00772 #endif
00773         old_size_adjust_factor = size_adjust_factor;
00774     }
00775 
00776     if( flag[mode][win][list] ) {
00777         listIndex[mode][win][list] = glGenLists(1);
00778         glNewList(listIndex[mode][win][list], GL_COMPILE_AND_EXECUTE);
00779 
00780         z = -1.0;
00781         qy = gImYsize   * 0 / 20.0;
00782         tey = ((double)gImYsize / (double)tex1Ysize) * (double)0 / 20.0;
00783         for( j = 1; j <= 20; j++ ) {
00784             py = qy;
00785             tsy = tey;
00786             qy = gImYsize   * j / 20.0;
00787             tey = ((double)gImYsize / (double)tex1Ysize) * (double)j / 20.0;
00788 
00789             qx = gImXsize * 0 / 20.0;
00790             tex = ((double)gImXsize / (double)(tex1Xsize1)) * (double)0 / 20.0;
00791             for( i = 1; i <= 20; i++ ) {
00792                 px = qx;
00793                 tsx = tex;
00794                 qx = gImXsize * i / 20.0;
00795                 tex = ((double)gImXsize / (double)(tex1Xsize1)) * (double)i / 20.0;
00796 
00797                 arParamObserv2Ideal( dist_factor, px, py, &x1, &y1 );
00798                 arParamObserv2Ideal( dist_factor, qx, py, &x2, &y2 );
00799                 arParamObserv2Ideal( dist_factor, qx, qy, &x3, &y3 );
00800                 arParamObserv2Ideal( dist_factor, px, qy, &x4, &y4 );
00801 
00802                 if( xwin == 0 && ywin == 0 ) {
00803                     xx1 = x1 * gZoom ;
00804                     yy1 = gWinYsize - y1 * gZoom;
00805                     xx2 = x2 * gZoom ;
00806                     yy2 = gWinYsize - y2 * gZoom;
00807                     xx3 = x3 * gZoom ;
00808                     yy3 = gWinYsize - y3 * gZoom;
00809                     xx4 = x4 * gZoom ;
00810                     yy4 = gWinYsize - y4 * gZoom;
00811                 }
00812                 else if( xwin == 1 && ywin == 0 ) {
00813                     xx1 = gXsize + x1 * gZoom;
00814                     yy1 = gWinYsize - y1 * gZoom;
00815                     xx2 = gXsize + x2 * gZoom;
00816                     yy2 = gWinYsize - y2 * gZoom;
00817                     xx3 = gXsize + x3 * gZoom;
00818                     yy3 = gWinYsize - y3 * gZoom;
00819                     xx4 = gXsize + x4 * gZoom;
00820                     yy4 = gWinYsize - y4 * gZoom;
00821                 }
00822                 else {
00823                     xx1 = (xwin-1)*gMiniXsize + x1*gZoom/(double)GMINI;
00824                     xx2 = (xwin-1)*gMiniXsize + x2*gZoom/(double)GMINI;
00825                     xx3 = (xwin-1)*gMiniXsize + x3*gZoom/(double)GMINI;
00826                     xx4 = (xwin-1)*gMiniXsize + x4*gZoom/(double)GMINI;
00827                     yy1 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y1*gZoom/(double)GMINI;
00828                     yy2 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y2*gZoom/(double)GMINI;
00829                     yy3 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y3*gZoom/(double)GMINI;
00830                     yy4 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y4*gZoom/(double)GMINI;
00831                 }
00832 
00833                 glBegin( GL_QUADS );
00834                 glTexCoord2d( tsx, tsy ); glVertex3d( xx1, yy1, z );
00835                 glTexCoord2d( tex, tsy ); glVertex3d( xx2, yy2, z );
00836                 glTexCoord2d( tex, tey ); glVertex3d( xx3, yy3, z );
00837                 glTexCoord2d( tsx, tey ); glVertex3d( xx4, yy4, z );
00838                 glEnd();
00839             }
00840         }
00841         glEndList();
00842         flag[mode][win][list] = 0;
00843     }
00844     else {
00845         glCallList( listIndex[mode][win][list] );
00846     }
00847 
00848     glBindTexture( GL_TEXTURE_2D, 0 );
00849     glDisable( GL_TEXTURE_2D );
00850     glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
00851 }
00852 
00853 #ifndef _WIN32
00854 static void argDispImageTex3( ARUint8 *image, int xwin, int ywin, int mode )
00855 #else
00856 static void argDispImageTex3( ARUint8 *wimage, int xwin, int ywin, int mode )
00857 #endif
00858 {
00859     static int      initf = 1;
00860     static int      flag[3][MINIWIN_MAX+2][2];
00861     static int      listIndex[3][MINIWIN_MAX+2][2];
00862     static int      old_size_adjust_factor = -1;
00863 #ifdef _WIN32
00864     static ARUint8  *image = NULL;
00865 #endif
00866     double   *dist_factor;
00867     double   tsx, tsy, tex, tey;
00868     double   px, py, qx, qy, z;
00869     double   x1, x2, x3, x4;
00870     double   y1, y2, y3, y4;
00871     double   xx1, xx2, xx3, xx4;
00872     double   yy1, yy2, yy3, yy4;
00873     int      size_adjust_factor;
00874     int      win, list;
00875     int      i, j;
00876 
00877     switch( mode ) {
00878                 case 0: dist_factor = &(gCparam.dist_factor[0]);   break;
00879                 case 1: dist_factor = &(gsCparam.dist_factorL[0]); break;
00880                 case 2: dist_factor = &(gsCparam.dist_factorR[0]); break;
00881                 default: return;
00882     }
00883 
00884 #ifdef _WIN32
00885     if( image == NULL ) {
00886         arMalloc(image,ARUint8,gImXsize*tex1Ysize*AR_PIX_SIZE_DEFAULT);
00887     }
00888     memcpy(image, wimage, gImXsize*gImYsize*AR_PIX_SIZE_DEFAULT);
00889 #endif
00890 
00891     if( initf ) {
00892         for(j=0;j<3;j++) {
00893             for(i=0;i<=MINIWIN_MAX;i++) flag[j][i][0] = flag[j][i][1] = 1;
00894         }
00895         initf = 0;
00896     }
00897     if( argTexmapMode == AR_DRAW_TEXTURE_HALF_IMAGE ) {
00898         size_adjust_factor = 2;
00899         list = 1;
00900     }
00901     else {
00902         size_adjust_factor = 1;
00903         list = 0;
00904     }
00905     if( xwin == 0 && ywin == 0 )      win = 0;
00906     else if( xwin == 1 && ywin == 0 ) win = 1;
00907     else win = gMiniXnum * (ywin-1) + xwin + 1;
00908 
00909     glEnable( GL_TEXTURE_2D );
00910     glMatrixMode(GL_TEXTURE);
00911     glLoadIdentity();
00912     glMatrixMode(GL_MODELVIEW);
00913 
00914     glBindTexture( GL_TEXTURE_2D, glid[0] );
00915 #ifdef APPLE_TEXTURE_FAST_TRANSFER
00916     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.0);
00917     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
00918 #endif
00919     glPixelStorei( GL_UNPACK_ROW_LENGTH, gImXsize*size_adjust_factor );
00920 
00921     if( size_adjust_factor == old_size_adjust_factor ) {
00922 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00923 #  ifdef AR_BIG_ENDIAN
00924         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00925 #  else
00926         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00927 #  endif
00928 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00929         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_ABGR, GL_UNSIGNED_BYTE, image );
00930 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00931         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_BYTE, image );
00932 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00933         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_BGR, GL_UNSIGNED_BYTE, image );
00934 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00935         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_RGBA, GL_UNSIGNED_BYTE, image );
00936 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00937         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_RGB, GL_UNSIGNED_BYTE, image );
00938 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00939         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00940 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00941 #  ifdef AR_BIG_ENDIAN
00942         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00943 #  else
00944         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00945 #  endif
00946 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00947 #  ifdef AR_BIG_ENDIAN
00948         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00949 #  else
00950         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize1, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00951 #  endif
00952 #else
00953 #  error Unknown default pixel format defined in config.h
00954 #endif
00955     }
00956     else {
00957 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
00958 #  ifdef AR_BIG_ENDIAN
00959         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
00960 #  else
00961         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
00962 #  endif
00963 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
00964         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_ABGR, GL_UNSIGNED_BYTE, image );
00965 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
00966         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_BYTE, image );
00967 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
00968         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_BGR, GL_UNSIGNED_BYTE, image );
00969 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
00970         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
00971 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
00972         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_RGB, GL_UNSIGNED_BYTE, image );
00973 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
00974         glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
00975 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
00976 #  ifdef AR_BIG_ENDIAN
00977         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00978 #  else
00979         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00980 #  endif
00981 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
00982 #  ifdef AR_BIG_ENDIAN
00983         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
00984 #  else
00985         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize1, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
00986 #  endif
00987 #else
00988 #  error Unknown default pixel format defined in config.h
00989 #endif
00990     }
00991 
00992     if( flag[mode][win][list] ) {
00993         listIndex[mode][win][list] = glGenLists(2);
00994         glNewList(listIndex[mode][win][list], GL_COMPILE_AND_EXECUTE);
00995 
00996         z = -1.0;
00997         qy = gImYsize   * 0 / 20.0;
00998         tey = ((double)gImYsize / (double)tex1Ysize) * (double)0 / 20.0;
00999         for( j = 1; j <= 20; j++ ) {
01000             py = qy;
01001             tsy = tey;
01002             qy = gImYsize   * j / 20.0;
01003             tey = ((double)gImYsize / (double)tex1Ysize) * (double)j / 20.0;
01004 
01005             qx = tex1Xsize1 * 0 / 16.0;
01006             tex = (double)0 / 16.0;
01007             for( i = 1; i <= 16; i++ ) {
01008                 px = qx;
01009                 tsx = tex;
01010                 qx = tex1Xsize1 * i / 16.0;
01011                 tex = (double)i / 16.0;
01012 
01013                 arParamObserv2Ideal( dist_factor, px, py, &x1, &y1 );
01014                 arParamObserv2Ideal( dist_factor, qx, py, &x2, &y2 );
01015                 arParamObserv2Ideal( dist_factor, qx, qy, &x3, &y3 );
01016                 arParamObserv2Ideal( dist_factor, px, qy, &x4, &y4 );
01017 
01018                 if( x2 < x1 ) continue;
01019                 if( x4 > x3 ) continue;
01020                 if( y4 < y1 ) continue;
01021                 if( y3 < y2 ) continue;
01022                 if( x2 < 0 || x3 < 0 ) continue;
01023                 if( x1 > gImXsize || x4 > gImXsize ) continue;
01024                 if( y4 < 0 || y3 < 0 ) continue;
01025                 if( y1 > gImYsize || y2 > gImXsize ) continue;
01026 
01027                 if( xwin == 0 && ywin == 0 ) {
01028                     xx1 = x1 * gZoom;
01029                     yy1 = gWinYsize - y1 * gZoom;
01030                     xx2 = x2 * gZoom;
01031                     yy2 = gWinYsize - y2 * gZoom;
01032                     xx3 = x3 * gZoom;
01033                     yy3 = gWinYsize - y3 * gZoom;
01034                     xx4 = x4 * gZoom;
01035                     yy4 = gWinYsize - y4 * gZoom;
01036                 }
01037                 else if( xwin == 1 && ywin == 0 ) {
01038                     xx1 = gXsize + x1 * gZoom;
01039                     yy1 = gWinYsize - y1 * gZoom;
01040                     xx2 = gXsize + x2 * gZoom;
01041                     yy2 = gWinYsize - y2 * gZoom;
01042                     xx3 = gXsize + x3 * gZoom;
01043                     yy3 = gWinYsize - y3 * gZoom;
01044                     xx4 = gXsize + x4 * gZoom;
01045                     yy4 = gWinYsize - y4 * gZoom;
01046                 }
01047                 else {
01048                     xx1 = (xwin-1)*gMiniXsize + x1*gZoom/(double)GMINI;
01049                     xx2 = (xwin-1)*gMiniXsize + x2*gZoom/(double)GMINI;
01050                     xx3 = (xwin-1)*gMiniXsize + x3*gZoom/(double)GMINI;
01051                     xx4 = (xwin-1)*gMiniXsize + x4*gZoom/(double)GMINI;
01052                     yy1 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y1*gZoom/(double)GMINI;
01053                     yy2 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y2*gZoom/(double)GMINI;
01054                     yy3 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y3*gZoom/(double)GMINI;
01055                     yy4 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y4*gZoom/(double)GMINI;
01056                 }
01057 
01058                 glBegin( GL_QUADS );
01059                 glTexCoord2d( tsx, tsy ); glVertex3d( xx1, yy1, z );
01060                 glTexCoord2d( tex, tsy ); glVertex3d( xx2, yy2, z );
01061                 glTexCoord2d( tex, tey ); glVertex3d( xx3, yy3, z );
01062                 glTexCoord2d( tsx, tey ); glVertex3d( xx4, yy4, z );
01063                 glEnd();
01064             }
01065         }
01066         glEndList();
01067     }
01068     else {
01069         glCallList( listIndex[mode][win][list] );
01070     }
01071 
01072     glBindTexture( GL_TEXTURE_2D, glid[1] );
01073 #ifdef APPLE_TEXTURE_FAST_TRANSFER
01074     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.0);
01075     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
01076 #endif
01077 
01078     if( size_adjust_factor == old_size_adjust_factor ) {
01079 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
01080 #  ifdef AR_BIG_ENDIAN
01081         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01082 #  else
01083         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01084 #  endif
01085 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
01086         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_ABGR, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01087 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
01088         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_BGRA, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01089 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
01090         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_BGR, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01091 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
01092         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_RGBA, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01093 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
01094         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_RGB, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01095 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
01096         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_LUMINANCE, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01097 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
01098 #  ifdef AR_BIG_ENDIAN
01099         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01100 #  else
01101         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01102 #  endif
01103 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
01104 #  ifdef AR_BIG_ENDIAN
01105         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01106 #  else
01107         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex1Xsize2, tex1Ysize/size_adjust_factor, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01108 #  endif
01109 #else
01110 #  error Unknown default pixel format defined in config.h
01111 #endif
01112     }
01113     else {
01114 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
01115 #  ifdef AR_BIG_ENDIAN
01116         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01117 #  else
01118         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01119 #  endif
01120 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
01121         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_ABGR, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01122 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
01123         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_BGRA, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01124 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
01125         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_BGR, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01126 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
01127         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_RGBA, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01128 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
01129         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_RGB, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01130 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
01131         glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01132 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
01133 #  ifdef AR_BIG_ENDIAN
01134         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01135 #  else
01136         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01137 #  endif
01138 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
01139 #  ifdef AR_BIG_ENDIAN
01140         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01141 #  else
01142         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex1Xsize2, tex1Ysize/size_adjust_factor, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image+tex1Xsize1*AR_PIX_SIZE_DEFAULT );
01143 #  endif
01144 #else
01145 #  error Unknown default pixel format defined in config.h
01146 #endif
01147         old_size_adjust_factor = size_adjust_factor;
01148     }
01149 
01150     if( flag[mode][win][list] ) {
01151         glNewList(listIndex[mode][win][list]+1, GL_COMPILE_AND_EXECUTE);
01152 
01153         z = -1.0;
01154         qy = gImYsize   * 0 / 20.0;
01155         tey = ((double)gImYsize / (double)tex1Ysize) * (double)0 / 20.0;
01156         for( j = 1; j <= 20; j++ ) {
01157             py = qy;
01158             tsy = tey;
01159             qy = gImYsize   * j / 20.0;
01160             tey = ((double)gImYsize / (double)tex1Ysize) * (double)j / 20.0;
01161 
01162             qx = tex1Xsize1 + (gImXsize-tex1Xsize1) * 0 / 4.0;
01163             tex = ((double)(gImXsize-tex1Xsize1) / (double)tex1Xsize2) * 0 / 4.0;
01164             for( i = 1; i <= 4; i++ ) {
01165                 px = qx;
01166                 tsx = tex;
01167                 qx = tex1Xsize1 + (gImXsize-tex1Xsize1) * i / 4.0;
01168                 tex = ((double)(gImXsize-tex1Xsize1) / (double)tex1Xsize2) * i / 4.0;
01169 
01170                 arParamObserv2Ideal( dist_factor, px, py, &x1, &y1 );
01171                 arParamObserv2Ideal( dist_factor, qx, py, &x2, &y2 );
01172                 arParamObserv2Ideal( dist_factor, qx, qy, &x3, &y3 );
01173                 arParamObserv2Ideal( dist_factor, px, qy, &x4, &y4 );
01174 
01175                 if( x2 < x1 ) continue;
01176                 if( x4 > x3 ) continue;
01177                 if( y4 < y1 ) continue;
01178                 if( y3 < y2 ) continue;
01179                 if( x2 < 0 || x3 < 0 ) continue;
01180                 if( x1 > gImXsize || x4 > gImXsize ) continue;
01181                 if( y4 < 0 || y3 < 0 ) continue;
01182                 if( y1 > gImYsize || y2 > gImXsize ) continue;
01183 
01184                 if( xwin == 0 && ywin == 0 ) {
01185                     xx1 = x1 * gZoom;
01186                     yy1 = gWinYsize - y1 * gZoom;
01187                     xx2 = x2 * gZoom;
01188                     yy2 = gWinYsize - y2 * gZoom;
01189                     xx3 = x3 * gZoom;
01190                     yy3 = gWinYsize - y3 * gZoom;
01191                     xx4 = x4 * gZoom;
01192                     yy4 = gWinYsize - y4 * gZoom;
01193                 }
01194                 else if( xwin == 1 && ywin == 0 ) {
01195                     xx1 = gXsize + x1 * gZoom;
01196                     yy1 = gWinYsize - y1 * gZoom;
01197                     xx2 = gXsize + x2 * gZoom;
01198                     yy2 = gWinYsize - y2 * gZoom;
01199                     xx3 = gXsize + x3 * gZoom;
01200                     yy3 = gWinYsize - y3 * gZoom;
01201                     xx4 = gXsize + x4 * gZoom;
01202                     yy4 = gWinYsize - y4 * gZoom;
01203                 }
01204                 else {
01205                     xx1 = (xwin-1)*gMiniXsize + x1*gZoom/(double)GMINI;
01206                     xx2 = (xwin-1)*gMiniXsize + x2*gZoom/(double)GMINI;
01207                     xx3 = (xwin-1)*gMiniXsize + x3*gZoom/(double)GMINI;
01208                     xx4 = (xwin-1)*gMiniXsize + x4*gZoom/(double)GMINI;
01209                     yy1 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y1*gZoom/(double)GMINI;
01210                     yy2 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y2*gZoom/(double)GMINI;
01211                     yy3 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y3*gZoom/(double)GMINI;
01212                     yy4 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y4*gZoom/(double)GMINI;
01213                 }
01214 
01215                 glBegin( GL_QUADS );
01216                 glTexCoord2d( tsx, tsy ); glVertex3d( xx1, yy1, z );
01217                 glTexCoord2d( tex, tsy ); glVertex3d( xx2, yy2, z );
01218                 glTexCoord2d( tex, tey ); glVertex3d( xx3, yy3, z );
01219                 glTexCoord2d( tsx, tey ); glVertex3d( xx4, yy4, z );
01220                 glEnd();
01221             }
01222         }
01223         glEndList();
01224         flag[mode][win][list] = 0;
01225     }
01226     else {
01227         glCallList( listIndex[mode][win][list]+1 );
01228     }
01229 
01230     glBindTexture( GL_TEXTURE_2D, 0 );
01231     glDisable( GL_TEXTURE_2D );
01232     glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
01233 }
01234 
01235 void argDispHalfImage( ARUint8 *image, int xwin, int ywin )
01236 {
01237     if( argDrawMode == AR_DRAW_BY_GL_DRAW_PIXELS ) {
01238         argDispHalfImageDrawPixels( image, xwin, ywin );
01239     }
01240     else {
01241         if( xwin == 0 && ywin == 0 ) {
01242             glScissor(0, gWinYsize-(int)(gZoom*gImYsize),
01243                       (int)(gZoom*gImXsize), (int)(gZoom*gImYsize));
01244         }
01245         else {
01246             glScissor((xwin-1)*gMiniXsize, gWinYsize-gYsize-ywin*gMiniYsize,
01247                        gMiniXsize, gMiniYsize);
01248         }
01249         glEnable( GL_SCISSOR_TEST );
01250         /* glDisable( GL_DEPTH_TEST ); */
01251         argDispHalfImageTex( image, xwin, ywin, 0 );
01252         glDisable( GL_SCISSOR_TEST );
01253     }
01254 }
01255 
01256 static void argDispHalfImageDrawPixels( ARUint8 *image, int xwin, int ywin )
01257 {
01258     float    sx, sy;
01259     GLfloat  zoom;
01260 
01261     if( xwin == 0 && ywin == 0 ) {
01262         zoom = gZoom * 2.0;
01263         sx = 0;
01264         sy = gWinYsize - 0.5;
01265     }
01266     if( xwin == 1 && ywin == 0 ) {
01267         zoom = gZoom * 2.0;
01268         sx = gXsize;
01269         sy = gWinYsize - 0.5;
01270     }
01271     else {
01272         zoom = gZoom / (double)GMINI * 2.0;
01273         sx = (xwin-1)*gMiniXsize;
01274         sy = gWinYsize - gYsize - (ywin-1)*gMiniYsize - 0.5;
01275     }
01276     glPixelZoom( zoom, -zoom);
01277     glRasterPos3f( sx, sy, -1.0 );
01278 
01279 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
01280 #  ifdef AR_BIG_ENDIAN
01281     glDrawPixels( gImXsize/2, gImYsize/2, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
01282 #  else
01283     glDrawPixels( gImXsize/2, gImYsize/2, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
01284 #  endif
01285 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
01286     glDrawPixels( gImXsize/2, gImYsize/2, GL_ABGR, GL_UNSIGNED_BYTE, image );
01287 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
01288     glDrawPixels( gImXsize/2, gImYsize/2, GL_BGRA, GL_UNSIGNED_BYTE, image );
01289 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
01290     glDrawPixels( gImXsize/2, gImYsize/2, GL_BGR, GL_UNSIGNED_BYTE, image );
01291 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
01292     glDrawPixels( gImXsize/2, gImYsize/2, GL_RGBA, GL_UNSIGNED_BYTE, image );
01293 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
01294     glDrawPixels( gImXsize/2, gImYsize/2, GL_RGB, GL_UNSIGNED_BYTE, image );
01295 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
01296     glDrawPixels( gImXsize/2, gImYsize/2, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
01297 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
01298 #  ifdef AR_BIG_ENDIAN
01299         glDrawPixels( gImXsize/2, gImYsize/2, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01300 #  else
01301         glDrawPixels( gImXsize/2, gImYsize/2, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01302 #  endif
01303 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
01304 #  ifdef AR_BIG_ENDIAN
01305         glDrawPixels( gImXsize/2, gImYsize/2, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01306 #  else
01307         glDrawPixels( gImXsize/2, gImYsize/2, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01308 #  endif
01309 #else
01310 #  error Unknown default pixel format defined in config.h
01311 #endif
01312 }
01313 
01314 #ifndef _WIN32
01315 static void argDispHalfImageTex( ARUint8 *image, int xwin, int ywin, int mode )
01316 #else
01317 static void argDispHalfImageTex( ARUint8 *wimage, int xwin, int ywin, int mode )
01318 #endif
01319 {
01320     static int      initf = 1;
01321     static int      flag[3][MINIWIN_MAX+2];
01322     static int      listIndex[3][MINIWIN_MAX+2];
01323 #ifdef _WIN32
01324     static ARUint8  *image = NULL;
01325 #endif
01326     double   *dist_factor;
01327     double   tsx, tsy, tex, tey;
01328     double   px, py, qx, qy, z;
01329     double   x1, x2, x3, x4;
01330     double   y1, y2, y3, y4;
01331     double   xx1, xx2, xx3, xx4;
01332     double   yy1, yy2, yy3, yy4;
01333     int      win;
01334     int      i, j;
01335 
01336     switch( mode ) {
01337                 case 0: dist_factor = &(gCparam.dist_factor[0]);   break;
01338                 case 1: dist_factor = &(gsCparam.dist_factorL[0]); break;
01339                 case 2: dist_factor = &(gsCparam.dist_factorR[0]); break;
01340                 default: return;
01341     }
01342 
01343 #ifdef _WIN32
01344     if( image == NULL ) {
01345         arMalloc(image,ARUint8,tex2Xsize*tex2Ysize*AR_PIX_SIZE_DEFAULT);
01346     }
01347     memcpy(image, wimage, gImXsize*gImYsize*AR_PIX_SIZE_DEFAULT/4);
01348 #endif
01349 
01350     if( initf ) {
01351         for(j=0;j<3;j++) {
01352             for(i=0;i<=MINIWIN_MAX;i++) flag[j][i] = 1;
01353         }
01354     }
01355     if( xwin == 0 && ywin == 0 )      win = 0;
01356     else if( xwin == 1 && ywin == 0 ) win = 1;
01357     else win = gMiniXnum * (ywin-1) + xwin + 1;
01358 
01359     glEnable( GL_TEXTURE_2D );
01360     glMatrixMode(GL_TEXTURE);
01361     glLoadIdentity();
01362     glMatrixMode(GL_MODELVIEW);
01363 
01364     glBindTexture( GL_TEXTURE_2D, glid[2] );
01365 #ifdef APPLE_TEXTURE_FAST_TRANSFER
01366     glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_PRIORITY, 0.0);
01367     glPixelStorei(GL_UNPACK_CLIENT_STORAGE_APPLE, 1);
01368 #endif
01369     glPixelStorei( GL_UNPACK_ROW_LENGTH, gImXsize/2 );
01370 
01371     if( initf == 0 ) {
01372 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
01373 #  ifdef AR_BIG_ENDIAN
01374         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
01375 #  else
01376         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
01377 #  endif
01378 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
01379         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_ABGR, GL_UNSIGNED_BYTE, image );
01380 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
01381         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_BGRA, GL_UNSIGNED_BYTE, image );
01382 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
01383         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_BGR, GL_UNSIGNED_BYTE, image );
01384 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
01385         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_RGBA, GL_UNSIGNED_BYTE, image );
01386 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
01387         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_RGB, GL_UNSIGNED_BYTE, image );
01388 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
01389         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
01390 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
01391 #  ifdef AR_BIG_ENDIAN
01392         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01393 #  else
01394         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01395 #  endif
01396 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
01397 #  ifdef AR_BIG_ENDIAN
01398         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01399 #  else
01400         glTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, tex2Xsize, tex2Ysize, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01401 #  endif
01402 #else
01403 #  error Unknown default pixel format defined in config.h
01404 #endif
01405     }
01406     else {
01407 #if (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ARGB)
01408 #  ifdef AR_BIG_ENDIAN
01409         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex2Xsize, tex2Ysize, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, image );
01410 #  else
01411         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex2Xsize, tex2Ysize, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, image );
01412 #  endif
01413 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_ABGR)
01414         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex2Xsize, tex2Ysize, 0, GL_ABGR, GL_UNSIGNED_BYTE, image );
01415 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGRA)
01416         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_BGRA, GL_UNSIGNED_BYTE, image );
01417 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_BGR)
01418         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_BGR, GL_UNSIGNED_BYTE, image );
01419 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGBA)
01420         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, tex2Xsize, tex2Ysize, 0, GL_RGBA, GL_UNSIGNED_BYTE, image );
01421 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_RGB)
01422         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_RGB, GL_UNSIGNED_BYTE, image );
01423 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_MONO)
01424         glTexImage2D( GL_TEXTURE_2D, 0, GL_LUMINANCE, tex2Xsize, tex2Ysize, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, image );
01425 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_2vuy)
01426 #  ifdef AR_BIG_ENDIAN
01427         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01428 #  else
01429         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01430 #  endif
01431 #elif (AR_DEFAULT_PIXEL_FORMAT == AR_PIXEL_FORMAT_yuvs)
01432 #  ifdef AR_BIG_ENDIAN
01433         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, image );
01434 #  else
01435         glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tex2Xsize, tex2Ysize, 0, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_REV_APPLE, image );
01436 #  endif
01437 #else
01438 #  error Unknown default pixel format defined in config.h
01439 #endif
01440     }
01441 
01442     if( flag[mode][win] ) {
01443         listIndex[mode][win] = glGenLists(1);
01444         glNewList(listIndex[mode][win], GL_COMPILE_AND_EXECUTE);
01445 
01446         z = -1.0;
01447         qy = gImYsize * 0 / 20.0;
01448         tey = ((double)gImYsize / (double)(tex2Ysize*2.0)) * (double)0 / 20.0;
01449         for( j = 1; j <= 20; j++ ) {
01450             py = qy;
01451             tsy = tey;
01452             qy = gImYsize * j / 20.0;
01453             tey = ((double)gImYsize / (double)(tex2Ysize*2.0)) * (double)j / 20.0;
01454 
01455             qx = gImXsize * 0 / 20.0;
01456             tex = ((double)gImXsize / (double)(tex2Xsize*2.0)) * (double)0 / 20.0;
01457             for( i = 1; i <= 20; i++ ) {
01458                 px = qx;
01459                 tsx = tex;
01460                 qx = gImXsize * i / 20.0;
01461                 tex = ((double)gImXsize / (double)(tex2Xsize*2.0)) * (double)i / 20.0;
01462 
01463                 arParamObserv2Ideal( dist_factor, px, py, &x1, &y1 );
01464                 arParamObserv2Ideal( dist_factor, qx, py, &x2, &y2 );
01465                 arParamObserv2Ideal( dist_factor, qx, qy, &x3, &y3 );
01466                 arParamObserv2Ideal( dist_factor, px, qy, &x4, &y4 );
01467 
01468                 if( xwin == 0 && ywin == 0 ) {
01469                     xx1 = x1 * gZoom;
01470                     yy1 = gWinYsize - y1 * gZoom;
01471                     xx2 = x2 * gZoom;
01472                     yy2 = gWinYsize - y2 * gZoom;
01473                     xx3 = x3 * gZoom;
01474                     yy3 = gWinYsize - y3 * gZoom;
01475                     xx4 = x4 * gZoom;
01476                     yy4 = gWinYsize - y4 * gZoom;
01477                 }
01478                 else if( xwin == 1 && ywin == 0 ) {
01479                     xx1 = gXsize + x1 * gZoom;
01480                     yy1 = gWinYsize - y1 * gZoom;
01481                     xx2 = gXsize + x2 * gZoom;
01482                     yy2 = gWinYsize - y2 * gZoom;
01483                     xx3 = gXsize + x3 * gZoom;
01484                     yy3 = gWinYsize - y3 * gZoom;
01485                     xx4 = gXsize + x4 * gZoom;
01486                     yy4 = gWinYsize - y4 * gZoom;
01487                 }
01488                 else {
01489                     xx1 = (xwin-1)*gMiniXsize + x1*gZoom/(double)GMINI;
01490                     xx2 = (xwin-1)*gMiniXsize + x2*gZoom/(double)GMINI;
01491                     xx3 = (xwin-1)*gMiniXsize + x3*gZoom/(double)GMINI;
01492                     xx4 = (xwin-1)*gMiniXsize + x4*gZoom/(double)GMINI;
01493                     yy1 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y1*gZoom/(double)GMINI;
01494                     yy2 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y2*gZoom/(double)GMINI;
01495                     yy3 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y3*gZoom/(double)GMINI;
01496                     yy4 = gWinYsize-gYsize-(ywin-1)*gMiniYsize - y4*gZoom/(double)GMINI;
01497                 }
01498 
01499                 glBegin( GL_QUADS );
01500                 glTexCoord2d( tsx, tsy ); glVertex3d( xx1, yy1, z );
01501                 glTexCoord2d( tex, tsy ); glVertex3d( xx2, yy2, z );
01502                 glTexCoord2d( tex, tey ); glVertex3d( xx3, yy3, z );
01503                 glTexCoord2d( tsx, tey ); glVertex3d( xx4, yy4, z );
01504                 glEnd();
01505             }
01506         }
01507         glEndList();
01508         flag[mode][win] = 0;
01509     }
01510     else {
01511         glCallList( listIndex[mode][win] );
01512     }
01513 
01514     initf = 0;
01515 
01516     glBindTexture( GL_TEXTURE_2D, 0 );
01517     glDisable( GL_TEXTURE_2D );
01518     glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 );
01519 }
01520 
01521 void argDrawSquare( double  vertex[4][2], int xwin, int ywin )
01522 {
01523     argLineSeg( vertex[0][0], vertex[0][1],
01524                 vertex[1][0], vertex[1][1], xwin, ywin );
01525     argLineSeg( vertex[1][0], vertex[1][1],
01526                 vertex[2][0], vertex[2][1], xwin, ywin );
01527     argLineSeg( vertex[2][0], vertex[2][1],
01528                 vertex[3][0], vertex[3][1], xwin, ywin );
01529     argLineSeg( vertex[3][0], vertex[3][1],
01530                 vertex[0][0], vertex[0][1], xwin, ywin );
01531 }
01532 
01533 void argLineSeg( double x1, double y1, double x2, double y2, int xwin, int ywin )
01534 {
01535     float   ox, oy;
01536     double  xx1, yy1, xx2, yy2;
01537 
01538     if( argDrawMode == AR_DRAW_BY_TEXTURE_MAPPING ) {
01539         xx1 = x1;  yy1 = y1;
01540         xx2 = x2;  yy2 = y2;
01541     }
01542     else {
01543         arParamIdeal2Observ( gCparam.dist_factor, x1, y1, &xx1, &yy1 );
01544         arParamIdeal2Observ( gCparam.dist_factor, x2, y2, &xx2, &yy2 );
01545     }
01546 
01547     xx1 *= gZoom; yy1 *= gZoom;
01548     xx2 *= gZoom; yy2 *= gZoom;
01549 
01550     if( xwin == 0 && ywin == 0 ) {
01551         ox = 0;
01552         oy = gWinYsize-1;
01553         glBegin(GL_LINES);
01554           glVertex2f( ox+xx1, oy-yy1 );
01555           glVertex2f( ox+xx2, oy-yy2 );
01556         glEnd();
01557     }
01558     else {
01559         ox = (xwin-1)*gMiniXsize;
01560         oy = gWinYsize - gYsize -(ywin-1)*gMiniYsize - 1;
01561         glBegin(GL_LINES);
01562           glVertex2f( ox+xx1/GMINI, oy-yy1/GMINI );
01563           glVertex2f( ox+xx2/GMINI, oy-yy2/GMINI );
01564         glEnd();
01565     }
01566 
01567     glFlush();
01568 }
01569 
01570 void argLineSegHMD( double x1, double y1, double x2, double y2 )
01571 {
01572     float   ox, oy;
01573 
01574     ox = 0;
01575     oy = gWinYsize - gYsize;
01576     glBegin(GL_LINES);
01577       glVertex2f( ox+x1, oy+y1 );
01578       glVertex2f( ox+x2, oy+y2 );
01579     glEnd();
01580 }
01581 
01582 
01583 static void argInitStencil(void)
01584 {
01585     int     offset;
01586     int     i;
01587 
01588     glEnable(GL_STENCIL_TEST);
01589     glClearStencil(0);
01590     glClear(GL_STENCIL_BUFFER_BIT);
01591     glLineWidth(1.0);
01592 
01593     offset = gWinYsize - gYsize;
01594 
01595 #if REVERSE_LR
01596     glStencilFunc(GL_ALWAYS, LEFTEYE, LEFTEYE);
01597     glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
01598     glBegin(GL_LINES);
01599     for( i = 0; i < gYsize; i+=2 ) {
01600         glVertex2f( 0.0,       (float)(i+offset) );
01601         glVertex2f( gWinXsize, (float)(i+offset) );
01602     }
01603     glEnd();
01604 
01605     glStencilFunc(GL_ALWAYS, RIGHTEYE, RIGHTEYE);
01606     glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
01607     glBegin(GL_LINES);
01608     for( i = 1; i < gYsize; i+=2 ) {
01609         glVertex2f( 0.0,       (float)(i+offset) );
01610         glVertex2f( gWinXsize, (float)(i+offset) );
01611     }
01612     glEnd();
01613 #else
01614     glStencilFunc(GL_ALWAYS, LEFTEYE, LEFTEYE);
01615     glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
01616     glBegin(GL_LINES);
01617     for( i = 1; i < gYsize; i+=2 ) {
01618         glVertex2f( 0.0,       (float)(i+offset) );
01619         glVertex2f( gWinXsize, (float)(i+offset) );
01620     }
01621     glEnd();
01622 
01623     glStencilFunc(GL_ALWAYS, RIGHTEYE, RIGHTEYE);
01624     glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
01625     glBegin(GL_LINES);
01626     for( i = 0; i < gYsize; i+=2 ) {
01627         glVertex2f( 0.0,       (float)(i+offset) );
01628         glVertex2f( gWinXsize, (float)(i+offset) );
01629     }
01630     glEnd();
01631 #endif
01632 
01633     glStencilFunc (GL_ALWAYS, 0, 0);
01634     glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
01635     glDisable(GL_STENCIL_TEST);
01636 }
01637 
01638 void argLoadHMDparam( ARParam *lparam, ARParam *rparam )
01639 {
01640     argConvGLcpara( lparam, AR_GL_CLIP_NEAR, AR_GL_CLIP_FAR, gl_lpara );
01641     argConvGLcpara( rparam, AR_GL_CLIP_NEAR, AR_GL_CLIP_FAR, gl_rpara );
01642 
01643     gl_hmd_para_flag = 1;
01644 }
01645 
01646 
01647 static void argSetStencil( int flag )
01648 {
01649     if( flag == 0 ) {
01650         glDisable(GL_STENCIL_TEST);
01651         glStencilFunc (GL_ALWAYS, 0, 0);
01652         glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
01653     }
01654     else {
01655         glEnable(GL_STENCIL_TEST);
01656         glStencilFunc (GL_EQUAL, flag, flag);
01657         glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP);
01658     }
01659 }
01660 
01661 void argConvGLcpara( ARParam *param, double gnear, double gfar, double m[16] )
01662 {
01663     argConvGLcpara2( param->mat, param->xsize, param->ysize, gnear, gfar, m );
01664 }
01665 
01666 static void argConvGLcpara2( double cparam[3][4], int width, int height, double gnear, double gfar, double m[16] )
01667 {
01668     double   icpara[3][4];
01669     double   trans[3][4];
01670     double   p[3][3], q[4][4];
01671     int      i, j;
01672 
01673     if( arParamDecompMat(cparam, icpara, trans) < 0 ) {
01674         printf("gConvGLcpara: Parameter error!!\n");
01675         exit(0);
01676     }
01677 
01678     for( i = 0; i < 3; i++ ) {
01679         for( j = 0; j < 3; j++ ) {
01680             p[i][j] = icpara[i][j] / icpara[2][2];
01681         }
01682     }
01683     q[0][0] = (2.0 * p[0][0] / width);
01684     q[0][1] = (2.0 * p[0][1] / width);
01685     q[0][2] = ((2.0 * p[0][2] / width)  - 1.0);
01686     q[0][3] = 0.0;
01687 
01688     q[1][0] = 0.0;
01689     q[1][1] = (2.0 * p[1][1] / height);
01690     q[1][2] = ((2.0 * p[1][2] / height) - 1.0);
01691     q[1][3] = 0.0;
01692 
01693     q[2][0] = 0.0;
01694     q[2][1] = 0.0;
01695     q[2][2] = (gfar + gnear)/(gfar - gnear);
01696     q[2][3] = -2.0 * gfar * gnear / (gfar - gnear);
01697 
01698     q[3][0] = 0.0;
01699     q[3][1] = 0.0;
01700     q[3][2] = 1.0;
01701     q[3][3] = 0.0;
01702 
01703     for( i = 0; i < 4; i++ ) {
01704         for( j = 0; j < 3; j++ ) {
01705             m[i+j*4] = q[i][0] * trans[0][j]
01706                      + q[i][1] * trans[1][j]
01707                      + q[i][2] * trans[2][j];
01708         }
01709         m[i+3*4] = q[i][0] * trans[0][3]
01710                  + q[i][1] * trans[1][3]
01711                  + q[i][2] * trans[2][3]
01712                  + q[i][3];
01713     }
01714 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00