graphicsTest.c
Go to the documentation of this file.
00001 #ifdef _WIN32
00002 #  include <windows.h>
00003 #endif
00004 #include <stdio.h>
00005 #include <stdlib.h>
00006 #ifndef __APPLE__
00007 #  include <GL/gl.h>
00008 #  include <GL/glut.h>
00009 #else
00010 #  include <OpenGL/gl.h>
00011 #  include <GLUT/glut.h>
00012 #endif
00013 #include <AR/gsub.h>
00014 #include <AR/param.h>
00015 #include <AR/ar.h>
00016 
00017 
00018 int             count = 0;
00019 char           *cparam_name    = "Data/camera_para.dat";
00020 ARParam         cparam;
00021 
00022 int             xsize = 320;
00023 int             ysize = 240;
00024 
00025 float              rotate_angle=0.;
00026 
00027 static void   init(void);
00028 static void   cleanup(void);
00029 static void   keyEvent( unsigned char key, int x, int y);
00030 static void   mainLoop(void);
00031 static void   draw( void );
00032 
00033 int main(int argc, char **argv)
00034 {
00035         glutInit(&argc, argv);
00036     init();
00037 
00038     argMainLoop( NULL, keyEvent, mainLoop );
00039         return (0);
00040 }
00041 
00042 static void   keyEvent( unsigned char key, int x, int y)
00043 {
00044     /* quit if the ESC key is pressed */
00045     if( key == 0x1b ) {
00046         printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00047         cleanup();
00048         exit(0);
00049     }
00050 }
00051 
00052 /* main loop */
00053 static void mainLoop(void)
00054 {
00055 
00056         if( count == 100 ) {
00057         printf("*** %f (frame/sec)\n", (double)count/arUtilTimer());
00058         count = 0;
00059     }
00060         if( count == 0 ) arUtilTimerReset();
00061     count++;
00062 
00063         rotate_angle+=1.;
00064         if (rotate_angle>360)
00065         {
00066                 rotate_angle=0.;
00067         }
00068     draw();
00069 
00070     argSwapBuffers();
00071 }
00072 
00073 static void init( void )
00074 {
00075         ARParam  wparam;
00076 
00077     /* set the initial camera parameters */
00078     if( arParamLoad(cparam_name, 1, &wparam) < 0 ) {
00079        printf("Camera parameter load error !!\n");
00080         exit(0);
00081     }
00082     arParamChangeSize( &wparam, xsize, ysize, &cparam );
00083 
00084     arInitCparam( &cparam );
00085     printf("*** Camera Parameter ***\n");
00086     arParamDisp( &cparam );
00087 
00088     /* open the graphics window */
00089     argInit( &cparam, 1.0, 0, 0, 0, 0 );
00090 }
00091 
00092 /* cleanup function called when program exits */
00093 static void cleanup(void)
00094 {
00095     argCleanup();
00096 }
00097 
00098 static void draw( void )
00099 {
00100 
00101     GLfloat   mat_ambient[]     = {0.0, 0.0, 1.0, 1.0};
00102     GLfloat   mat_flash[]       = {0.0, 0.0, 1.0, 1.0};
00103     GLfloat   mat_flash_shiny[] = {50.0};
00104     GLfloat   light_position[]  = {100.0,-200.0,200.0,0.0};
00105     GLfloat   ambi[]            = {0.1, 0.1, 0.1, 0.1};
00106     GLfloat   lightZeroColor[]  = {0.9, 0.9, 0.9, 0.1};
00107     
00108         argDrawMode3D();
00109     argDraw3dCamera( 0, 0 );
00110     glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
00111     glEnable(GL_DEPTH_TEST);
00112     glDepthFunc(GL_LEQUAL);
00113     
00114     glEnable(GL_LIGHTING);
00115     glEnable(GL_LIGHT0);
00116     glLightfv(GL_LIGHT0, GL_POSITION, light_position);
00117     glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
00118     glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
00119     glMaterialfv(GL_FRONT, GL_SPECULAR, mat_flash);
00120     glMaterialfv(GL_FRONT, GL_SHININESS, mat_flash_shiny);      
00121     glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
00122 
00123     glMatrixMode(GL_MODELVIEW);
00124         glLoadIdentity();
00125     glTranslatef( 0.0, 0.0, 500.0 );
00126         glRotatef(rotate_angle,0.,1.,0.);
00127         glRotatef(180.,1.,0.,0.);
00128     glutSolidTeapot(100.0);
00129 
00130     glDisable( GL_LIGHTING );
00131 
00132     glDisable( GL_DEPTH_TEST );
00133 }
 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