- Main Page
- Namespaces
- Classes
- Files

# VCRA-SZCZERBACKI-PointBasedRendering/VCRA-SZCZERBACKI-PointBasedRendering.cpp

    00001
    00018 #include "stopwatch.h"
    00019 #include "splatting.h"
    00020
    00021 extern void analyticPipeline( const std::vector<Splat> &splats, ABuffer *abuffer, const Matrix4x4 &objectToCamera, const Matrix4x4 &projection, const Vector4 &viewport, float front, float back );
    00022
    00023 const float PI = 3.14159265358979323846f;
    00024
    00025 Mesh    *lwo     = NULL;
    00026 Color   *buffer  = NULL;
    00027 ABuffer *abuffer = NULL;
    00028
    00029 std::vector<Splat>      splats;
    00030
    00031
    00032 #include <fstream>
    00033 #include <windows.h>
    00034
    00035 #include <glut.h>   /* includes glut and OpenGL */
    00036
    00037 #include <stdlib.h>  /* libs ANSI C */
    00038 #include <stdio.h>
    00039
    00040
    00041
    00042 /* Global variables */
    00043 bool inputFile = false;
    00044 char inputFileName[200];
    00045
    00046 float xRotation = 0.0f, yRotation = 0.0f, zRotation = 0.0f;
    00047 float yRotationAcc = 0.0f;
    00048 float rotationStep = 10.0f;
    00049 float xEye, yEye, zEye, zEyeStep,
    00050       xCenter, yCenter, zCenter,
    00051       xUp, yUp, zUp,
    00052       xLight, yLight, zLight,
    00053       nearValue, farValue,
    00054       normalSizeFactor;
    00055
    00056 float xAxis[3] = {1.0f, 0.0f, 0.0f},
    00057       yAxis[3] = {0.0f, 1.0f, 0.0f},
    00058       zAxis[3] = {0.0f, 0.0f, 1.0f};
    00059
    00060 GLdouble modelview[16], modelviewSplatting[16];
    00061
    00062 int width = 800-50;
    00063 int height = 770-50;
    00064 int textHeight = 160;
    00065 int currentStep = 0;
    00067 int LEFT_COL_SIZE = 130;
    00068 int TOP_ROW_SIZE = 100;
    00069
    00070 int widthImage3D = width - 3 - LEFT_COL_SIZE - 3 - 1 - 1 - 3;
    00071 int heightImage3D = height - 3 - 1 - 1 - 3 - TOP_ROW_SIZE - 3;
    00072
    00073 float xMin, yMin, zMin, xMax, yMax, zMax, maxDimension;
    00074
    00075
    00076 void __cdecl svPrint(const char *format, ...)
    00077 {
    00078         static char     text[1000];
    00079         ULONG i;
    00080
    00081         va_list argptr;
    00082         va_start(argptr, format);
    00083         vsprintf(text, format, argptr);
    00084         va_end(argptr);
    00085
    00086         WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),text,strlen(text),&i,0);
    00087 }
    00088
    00089 void __cdecl svError(const char *format, ...)
    00090 {
    00091         static char     text[1000];
    00092         ULONG i;
    00093
    00094         va_list argptr;
    00095         va_start(argptr, format);
    00096         vsprintf(text, format, argptr);
    00097         va_end(argptr);
    00098
    00099         WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),text,strlen(text),&i,0);
    00100     exit( -1 );
    00101 }
    00102
    00103 const char *__cdecl STR( const char *format, ... )
    00104 {
    00105         static char string[1024];
    00106
    00107         va_list arg;
    00108
    00109     va_start( arg, format );
    00110     vsprintf( string, format, arg );
    00111     va_end( arg );
    00112
    00113         return string;
    00114 }
    00115
    00116
    00117 void initCamera()
    00118 {
    00119   lwo->calculateBoundingBox();
    00120   xMin = lwo->getBoundingBoxMin().x;
    00121   yMin = lwo->getBoundingBoxMin().y;
    00122   zMin = lwo->getBoundingBoxMin().z;
    00123   xMax = lwo->getBoundingBoxMax().x;
    00124   yMax = lwo->getBoundingBoxMax().y;
    00125   zMax = lwo->getBoundingBoxMax().z;
    00126   if ((xMax - xMin) > (yMax - yMin))
    00127     if ((xMax - xMin) > (zMax - zMin))
    00128       maxDimension = xMax - xMin;
    00129     else
    00130       maxDimension = zMax - zMin;
    00131   else if ((yMax - yMin) > (zMax - zMin))
    00132       maxDimension = yMax - yMin;
    00133     else
    00134       maxDimension = zMax - zMin;
    00135
    00136   xEye     = (xMax + xMin)/2;
    00137   yEye     = (yMax + yMin)/2,
    00138   zEye     = maxDimension*2;
    00139   zEyeStep = zEye/10;
    00140
    00141   xCenter = (xMax + xMin)/2;
    00142   yCenter = (yMax + yMin)/2;
    00143   zCenter = (zMax + zMin)/2;
    00144
    00145   xUp     = 0.0;
    00146   yUp     = 1.0;
    00147   zUp     = 0.0;
    00148
    00149   nearValue = maxDimension/10;
    00150   farValue  = 10*maxDimension;
    00151
    00152   normalSizeFactor = maxDimension/50;
    00153
    00154   xLight    = xMax + (xMax - xMin);
    00155   yLight    = yMax + (yMax - yMin);
    00156   zLight    = -2*maxDimension;
    00157
    00158   glMatrixMode(GL_MODELVIEW);
    00159   glLoadIdentity();
    00160
    00161   glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    00162 }
    00163
    00167 void executeNextStep()
    00168 {
    00169   if (currentStep == 0) {
    00170     loadLwoFile(lwoFileName);
    00171     initCamera();
    00172   }
    00173
    00174   if (++currentStep == 7)
    00175     exit(0);
    00176 }
    00177
    00181 void executePreviousStep()
    00182 {
    00183   if (currentStep > 0)
    00184     currentStep--;
    00185 }
    00186
    00190 void drawText(int x, int y, char *string) {
    00191   int len, i;
    00192
    00193   glRasterPos2f(x, y);
    00194   len = (int) strlen(string);
    00195   for (i = 0; i < len; i++)
    00196           glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12 , string[i]);
    00197 }
    00198
    00199
    00200 /* ************************
    00201  * Application callbacks  *
    00202  **************************/
    00203
    00204 void display_cb(void)
    00205 {
    00206   glutSetCursor(GLUT_CURSOR_WAIT);
    00207
    00208   Stopwatch watch;
    00209   double renderingTime;
    00210   char output[200];
    00211   int yStep, yDetails, yCommands,
    00212       xStep, xDetails, xCommands;
    00213
    00214   glClearColor(0.0f, 0.0f, 0.0f, 1.0f);  /* black */
    00215   glClear(GL_COLOR_BUFFER_BIT);          /* set background color to black*/
    00216
    00217
    00218
    00219   /* -------------------------------------------------------------------------- */
    00220   /* Draw 3D polygon based rendering (if step 1 is the current one)             */
    00221   /* -------------------------------------------------------------------------- */
    00222   if (currentStep == 1) {
    00223     watch.start();
    00224
    00225     glViewport(3 + LEFT_COL_SIZE + 3 + 1, 3 + 1, widthImage3D, heightImage3D);
    00226     glMatrixMode(GL_PROJECTION);
    00227     glLoadIdentity();
    00228
    00229     gluPerspective(90,(double)widthImage3D/(double)heightImage3D, nearValue, farValue);
    00230     gluLookAt(xEye, yEye, -zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
    00231
    00232     glMatrixMode(GL_MODELVIEW);
    00233     glLoadIdentity();
    00234
    00235     float light_ambient[]=  { 0.02f, 0.02f, 0.02f, 1.0f };
    00236     float light_diffuse[]=  { 1.0f, 1.0f, 1.0f };
    00237     float light_position0[]= { 1.0, 1.0, zLight, 1.0f };
    00238
    00239     glEnable(GL_LIGHTING);
    00240     glEnable(GL_LIGHT0);
    00241     glEnable(GL_COLOR_MATERIAL);
    00242     glEnable(GL_CULL_FACE);
    00243
    00244     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    00245     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    00246     glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    00247
    00248     glLoadMatrixd(modelview);
    00249
    00250     if (yRotation) {
    00251       glRotatef(yRotation, yAxis[0], yAxis[1], yAxis[2]);
    00252       yRotation = 0.0f;
    00253     }
    00254
    00255     glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    00256
    00257     glPushMatrix();
    00258     glScalef(2.0, 2.0, 2.0);
    00259     glBegin(GL_TRIANGLES);
    00260       glColor3f(0.55,0.72,0.85);
    00261       int t;
    00262       Mesh::Triangle *triangle;
    00263       for (t = 0; t < lwo->getTriangleCount(); t++) {
    00264         triangle = &lwo->getTriangle(t);
    00265         glNormal3f(triangle->m_normal.x, triangle->m_normal.y, triangle->m_normal.z);
    00266         glVertex3f(lwo->getVertex(triangle->m_v[0]).m_position.x, lwo->getVertex(triangle->m_v[0]).m_position.y, lwo->getVertex(triangle->m_v[0]).m_position.z);
    00267         glVertex3f(lwo->getVertex(triangle->m_v[1]).m_position.x, lwo->getVertex(triangle->m_v[1]).m_position.y, lwo->getVertex(triangle->m_v[1]).m_position.z);
    00268         glVertex3f(lwo->getVertex(triangle->m_v[2]).m_position.x, lwo->getVertex(triangle->m_v[2]).m_position.y, lwo->getVertex(triangle->m_v[2]).m_position.z);
    00269       }
    00270
    00271     glEnd();
    00272     glPopMatrix();
    00273     renderingTime = watch.stop();
    00274   }
    00275
    00276   /* -------------------------------------------------------------------------- */
    00277   /* Draw 3D vertex representation (if step 2 is the current one)               */
    00278   /* -------------------------------------------------------------------------- */
    00279
    00280   if (currentStep == 2) {
    00281     watch.start();
    00282
    00283     glViewport(3 + LEFT_COL_SIZE + 3 + 1, 3 + 1, widthImage3D, heightImage3D);
    00284     glMatrixMode(GL_PROJECTION);
    00285     glLoadIdentity();
    00286
    00287     gluPerspective(90,(double)widthImage3D/(double)heightImage3D, nearValue, farValue);
    00288     gluLookAt(xEye, yEye, -zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
    00289
    00290     glMatrixMode(GL_MODELVIEW);
    00291     glLoadMatrixd(modelview);
    00292
    00293
    00294     if (yRotation) {
    00295       glRotatef(yRotation, yAxis[0], yAxis[1], yAxis[2]);
    00296       yRotation = 0.0f;
    00297     }
    00298
    00299     glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    00300
    00301     float light_ambient[]=  { 0.15f, 0.15f, 0.15f, 1.0f };
    00302     float light_diffuse[]=  { 0.4f, 0.4f, 0.4f };
    00303     float light_position0[]= { xLight, yLight, zLight, 1.0f };
    00304
    00305     glEnable(GL_LIGHTING);
    00306     glEnable(GL_LIGHT0);
    00307     glEnable(GL_COLOR_MATERIAL);
    00308     glEnable(GL_CULL_FACE);
    00309     glPointSize(2.0f);
    00310
    00311     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    00312     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    00313     glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    00314
    00315     glPushMatrix();
    00316     glScalef(2.0, 2.0, 2.0);
    00317     glBegin(GL_POINTS);
    00318       glColor3f(0.55,0.72,0.85);
    00319       int v;
    00320       Mesh::Vertex *vertex;
    00321       for (v = 0; v < lwo->getVertexCount(); v++) {
    00322         vertex = &lwo->getVertex(v);
    00323         glNormal3f(vertex->m_normal.x, vertex->m_normal.y, vertex->m_normal.z);
    00324         glVertex3f(vertex->m_position.x, vertex->m_position.y, vertex->m_position.z);
    00325       }
    00326
    00327     glEnd();
    00328     glPopMatrix();
    00329     renderingTime = watch.stop();
    00330   }
    00331
    00332   /* -------------------------------------------------------------------------- */
    00333   /* Draw 3D normal representation (if step 3 is the current one)                */
    00334   /* -------------------------------------------------------------------------- */
    00335
    00336   if (currentStep == 3) {
    00337     watch.start();
    00338
    00339     glViewport(3 + LEFT_COL_SIZE + 3 + 1, 3 + 1, widthImage3D, heightImage3D);
    00340     glMatrixMode(GL_PROJECTION);
    00341     glLoadIdentity();
    00342
    00343     gluPerspective(90,(double)widthImage3D/(double)heightImage3D, nearValue, farValue);
    00344     gluLookAt(xEye, yEye, -zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
    00345
    00346     glMatrixMode(GL_MODELVIEW);
    00347     glLoadMatrixd(modelview);
    00348
    00349
    00350     if (yRotation) {
    00351       glRotatef(yRotation, yAxis[0], yAxis[1], yAxis[2]);
    00352       yRotation = 0.0f;
    00353     }
    00354
    00355     glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    00356
    00357     float light_ambient[]=  { 0.15f, 0.15f, 0.15f, 1.0f };
    00358     float light_diffuse[]=  { 0.4f, 0.4f, 0.4f };
    00359     float light_position0[]= { xLight, yLight, zLight, 1.0f };
    00360
    00361     glEnable(GL_LIGHTING);
    00362     glEnable(GL_LIGHT0);
    00363     glEnable(GL_COLOR_MATERIAL);
    00364     glEnable(GL_CULL_FACE);
    00365     glEnable(GL_NORMALIZE);
    00366     glPointSize(2.0f);
    00367     glLineWidth(0.5f);
    00368
    00369     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    00370     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    00371     glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    00372
    00373     glPushMatrix();
    00374     glScalef(2.0, 2.0, 2.0);
    00375     glBegin(GL_POINTS);
    00376       glColor3f(0.55,0.72,0.85);
    00377       int v;
    00378       Mesh::Vertex *vertex;
    00379       for (v = 0; v < lwo->getVertexCount(); v++) {
    00380         vertex = &lwo->getVertex(v);
    00381         glNormal3f(vertex->m_normal.x, vertex->m_normal.y, vertex->m_normal.z);
    00382         glVertex3f(vertex->m_position.x, vertex->m_position.y, vertex->m_position.z);
    00383       }
    00384
    00385       glEnd();
    00386
    00387     glBegin(GL_LINES);
    00388       float resizedNormal[3];
    00389       glColor3f(1.0,0.15,0.15);
    00390       for (v = 0; v < lwo->getVertexCount(); v++) {
    00391         vertex = &lwo->getVertex(v);
    00392         resizedNormal[0] = vertex->m_normal.x * normalSizeFactor;
    00393         resizedNormal[1] = vertex->m_normal.y * normalSizeFactor;
    00394         resizedNormal[2] = vertex->m_normal.z * normalSizeFactor;
    00395         glNormal3f(vertex->m_normal.x, vertex->m_normal.y, vertex->m_normal.z);
    00396         glVertex3f(vertex->m_position.x, vertex->m_position.y, vertex->m_position.z);
    00397         glVertex3f(vertex->m_position.x + resizedNormal[0], vertex->m_position.y + resizedNormal[1], vertex->m_position.z + resizedNormal[2]);
    00398       }
    00399
    00400     glEnd();
    00401     glPopMatrix();
    00402     renderingTime = watch.stop();
    00403   }
    00404
    00405
    00406
    00407   /* -------------------------------------------------------------------------- */
    00408   /* Draw 3D splat representation (if step 4 is the current one)                */
    00409   /* -------------------------------------------------------------------------- */
    00410
    00411   if ((currentStep == 4) || (currentStep == 5)) {
    00412     watch.start();
    00413
    00414     glViewport(3 + LEFT_COL_SIZE + 3 + 1, 3 + 1, widthImage3D, heightImage3D);
    00415     glMatrixMode(GL_PROJECTION);
    00416     glLoadIdentity();
    00417
    00418     gluPerspective(90,(double)widthImage3D/(double)heightImage3D, nearValue, farValue);
    00419     gluLookAt(xEye, yEye, -zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
    00420
    00421     glMatrixMode(GL_MODELVIEW);
    00422     glLoadMatrixd(modelview);
    00423
    00424
    00425     if (yRotation) {
    00426       glRotatef(yRotation, yAxis[0], yAxis[1], yAxis[2]);
    00427       yRotation = 0.0f;
    00428     }
    00429
    00430     glGetDoublev(GL_MODELVIEW_MATRIX, modelview);
    00431
    00432     float light_ambient[]=  { 0.15f, 0.15f, 0.15f, 1.0f };
    00433     float light_diffuse[]=  { 0.4f, 0.4f, 0.4f };
    00434     float light_position0[]= { xLight, yLight, zLight, 1.0f };
    00435
    00436     glEnable(GL_LIGHTING);
    00437     glEnable(GL_LIGHT0);
    00438     glEnable(GL_COLOR_MATERIAL);
    00439     glEnable(GL_CULL_FACE);
    00440     glEnable(GL_NORMALIZE);
    00441     glPointSize(2.0f);
    00442     glLineWidth(0.5f);
    00443
    00444     glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    00445     glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    00446     glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    00447
    00448     glColor3f(0.55,0.72,0.85);
    00449
    00450     GLUquadric *quadric = gluNewQuadric();
    00451
    00452     int s;
    00453     float angle;
    00454     float rotationVector[3];
    00455     glPushMatrix();
    00456     glScalef(2.0, 2.0, 2.0);
    00457     for (s = 0; s < splats.size(); s++) {
    00458       glPushMatrix();
    00459
    00460       angle = acos(splats[s].m_normal.z/sqrt(splats[s].m_normal.x*splats[s].m_normal.x +
    00461                                              splats[s].m_normal.y*splats[s].m_normal.y +
    00462                                              splats[s].m_normal.z*splats[s].m_normal.z)) * 360/(2*PI);
    00463
    00464       rotationVector[0] = -splats[s].m_normal.y;
    00465       rotationVector[1] = splats[s].m_normal.x;
    00466       rotationVector[2] = 0;
    00467
    00468       glTranslatef(splats[s].m_position.x, splats[s].m_position.y, splats[s].m_position.z);
    00469       glRotatef(angle, rotationVector[0], rotationVector[1], rotationVector[2]);
    00470       if (currentStep == 4)
    00471         gluDisk(quadric, 0.0f, splats[s].m_size/3, 30, 1);
    00472       if (currentStep == 5)
    00473         gluDisk(quadric, splats[s].m_size*0.95, splats[s].m_size, 30, 1);
    00474
    00475       glPopMatrix();
    00476     }
    00477     glPopMatrix();
    00478
    00479
    00480     renderingTime = watch.stop();
    00481   }
    00482
    00483   /* -------------------------------------------------------------------------- */
    00484   /* Draw 3D splat based rendering (if step 6 is the current one)               */
    00485   /* -------------------------------------------------------------------------- */
    00486
    00487   if (currentStep == 6)
    00488   {
    00489     watch.start();
    00490
    00491     glViewport(3 + LEFT_COL_SIZE + 3 + 1, 3 + 1, widthImage3D, heightImage3D);
    00492
    00493     glEnable(GL_TEXTURE_2D);
    00494
    00495     glClearColor( 0, 0, 0, 0 );
    00496     glClear(GL_COLOR_BUFFER_BIT);
    00497     glColor3f(1.0f,1.0f,1.0f);
    00498     glEnable(GL_BLEND);
    00499     glBlendFunc(GL_ONE,GL_ONE);
    00500
    00501     glMatrixMode( GL_PROJECTION );
    00502     glLoadIdentity();
    00503     gluPerspective(90,(float)widthImage3D/(float)heightImage3D,0.01,1000);
    00504     gluLookAt(xEye, yEye, -zEye, xCenter, yCenter, zCenter, xUp, yUp, zUp);
    00505     glMatrixMode( GL_MODELVIEW );
    00506     glPushMatrix();
    00507     glLoadIdentity();
    00508
    00509     float sx = pixelScale * (float)sizex / defaultWidth;
    00510     float sy = pixelScale * (float)sizey / defaultWidth;
    00511
    00512     figsx = sx*2.0f/(float)sizex;
    00513     figsy = sy*2.0f/(float)sizey;
    00514
    00515     static Timer t;
    00516     t.sample();
    00517
    00518     static CameraControls cameraControls(1.0f,1.0f,0.f,false);//rotationScale,translationScale,inertia,framerateDependent);
    00519     Matrix4x4 cameraToWorld = cameraControls.getCameraMatrix();
    00520     Matrix4x4 worldToCamera;
    00521     worldToCamera = cameraToWorld;
    00522     worldToCamera.invert();
    00523
    00524     static float a = 0.0f;
    00525     Matrix4x4 objectToCamera;
    00526     objectToCamera.ident();
    00527     objectToCamera *= MatrixFactory::rotateY( -yRotationAcc * (2*PI)/360 );
    00528     objectToCamera *= 3.0f;
    00529     objectToCamera.setColumn(3,Vector4(0,0,10,1.0f));
    00530     objectToCamera.transpose();
    00531     worldToCamera.transpose();
    00532     objectToCamera *= worldToCamera;
    00533
    00534     const float hfov = 90.0f;
    00535     const float vfov = 90.0f;
    00536     const float front = nearValue; /*0.1f*/
    00537     const float back = farValue; /*100.0f*/
    00538
    00539     float hx = 1.0f / float(tan(degreeToRad(hfov)*0.5f));
    00540     float hy = 1.0f / float(tan(degreeToRad(vfov)*0.5f));
    00541     float Q = back / (back - front);
    00542
    00543     Matrix4x4 projection(
    00544       hx, 0,   0,        0,
    00545       0,  -hy, 0,        0,
    00546       0,  0,   Q,                  1,
    00547       0,  0,   -Q*front, 0);
    00548
    00549     Vector4 viewport(0,0,(float)sizex,(float)sizey);
    00550
    00551     static bool zrange = true;
    00552
    00553     static float zthreshold = 0.1f;
    00554
    00555     glScalef(4.0 + maxDimension/2.0, 4.0 + maxDimension/2.0,1.0);
    00556
    00557     abuffer->clear();
    00558
    00559     analyticPipeline(splats,abuffer,objectToCamera,projection,viewport,front,back);
    00560
    00561     abuffer->collapseToFrameBuffer(buffer, Vector4(0.0f,0.0f,0.0f,1.0f),zrange,zthreshold);
    00562
    00563     //render texture mapped quad
    00564     glTexImage2D(GL_TEXTURE_2D, 0, 4, sizex, sizey, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    00565     glBegin(GL_TRIANGLE_FAN);
    00566       glTexCoord2f(0,0);
    00567       glVertex3f(-sx,sy,-1);
    00568       glTexCoord2f(1,0);
    00569       glVertex3f(sx,sy,-1);
    00570       glTexCoord2f(1,1);
    00571       glVertex3f(sx,-sy,-1);
    00572       glTexCoord2f(0,1);
    00573       glVertex3f(-sx,-sy,-1);
    00574           glEnd();
    00575
    00576           glPopMatrix();
    00577
    00578     renderingTime = watch.stop();
    00579
    00580     glDisable(GL_TEXTURE_2D);
    00581   }
    00582
    00583   /* -------------------------------------------------------------------------- */
    00584   /* Draw user interface, external to 3D rendering (always)                     */
    00585   /* -------------------------------------------------------------------------- */
    00586
    00587   glViewport(0, 0, width, height);
    00588
    00589   glDisable(GL_LIGHTING);
    00590   glDisable(GL_LIGHT0);
    00591   glDisable(GL_CULL_FACE);
    00592   glDisable(GL_NORMALIZE);
    00593   glDisable(GL_BLEND);
    00594
    00595   glMatrixMode(GL_PROJECTION);
    00596   glLoadIdentity();
    00597   gluOrtho2D (0.0, width, 0.0, height);
    00598
    00599   glMatrixMode(GL_MODELVIEW);
    00600   glLoadIdentity();
    00601
    00602   // Draw text backgrounds
    00603   glBegin(GL_QUADS);
    00604     // Step title display (upper left)
    00605     glColor3f(0.15,0.2,0.2);
    00606     glVertex2i(3, height - 3);
    00607     glVertex2i(LEFT_COL_SIZE, height - 3);
    00608     glVertex2i(LEFT_COL_SIZE, height - 3 - TOP_ROW_SIZE);
    00609     glVertex2i(3, height - 3 - TOP_ROW_SIZE);
    00610
    00611     // Step details display (upper right)
    00612     glColor3f(0.22,0.30,0.30);
    00613     glVertex2i(3 + LEFT_COL_SIZE, height - 3);
    00614     glVertex2i(width - 3, height - 3);
    00615     glVertex2i(width - 3, height - 3 - TOP_ROW_SIZE);
    00616     glVertex2i(3 + LEFT_COL_SIZE, height - 3 - TOP_ROW_SIZE);
    00617
    00618     // Commands display (buttom left)
    00619     glVertex2i(3, height - 3 - TOP_ROW_SIZE - 3);
    00620     glVertex2i(LEFT_COL_SIZE, height - 3 - TOP_ROW_SIZE - 3);
    00621     glVertex2i(LEFT_COL_SIZE, 3);
    00622     glVertex2i(3, 3);
    00623   glEnd();
    00624
    00625   // Draw 3D image border
    00626   glBegin(GL_LINES);
    00627     glColor3f(0.5,0.5,0.5);
    00628     glVertex2i(3 + LEFT_COL_SIZE, height - 3 - TOP_ROW_SIZE - 3);
    00629     glVertex2i(width - 3, height - 3 - TOP_ROW_SIZE - 3);
    00630
    00631     glVertex2i(width - 3, height - 3 - TOP_ROW_SIZE - 3);
    00632     glVertex2i(width - 3, 3);
    00633
    00634     glVertex2i(width - 3, 3);
    00635     glVertex2i(3 + LEFT_COL_SIZE, 3);
    00636
    00637     glVertex2i(3 + LEFT_COL_SIZE, 3);
    00638     glVertex2i(3 + LEFT_COL_SIZE, height - 3 - TOP_ROW_SIZE - 3);
    00639   glEnd();
    00640
    00641   // Draw all texts
    00642   // fixed texts first
    00643   xStep     = 3 + 7;
    00644   xDetails  = 3 + LEFT_COL_SIZE + 3 + 7;
    00645   xCommands = 3 + 7;
    00646
    00647   yStep = height - 3 - 13;
    00648   yDetails = height - 3 - 13;
    00649   glColor3f(0.0,1.0,1.0);
    00650   drawText(xDetails, yDetails, "DETAILS");
    00651
    00652   yCommands = height - 3 - TOP_ROW_SIZE - 3 - 13;
    00653   drawText(xCommands, yCommands, "COMMANDS");
    00654
    00655   // ENTER command
    00656   if (currentStep < 6) {
    00657     yCommands -= 25;
    00658     glColor3f(1.0,1.0,1.0);
    00659     drawText(xCommands, yCommands, "ENTER");
    00660     yCommands -= 15;
    00661     glColor3f(0.7,0.9,0.8);
    00662     drawText(xCommands, yCommands, "Go to next step");
    00663   }
    00664
    00665
    00666   // BACKSPACE command
    00667   yCommands -= 25;
    00668   glColor3f(1.0,1.0,1.0);
    00669   drawText(xCommands, yCommands, "BACKSPACE");
    00670   yCommands -= 15;
    00671   glColor3f(0.7,0.9,0.8);
    00672   drawText(xCommands, yCommands, "Go to previous step");
    00673
    00674   // ESC command
    00675   yCommands -= 25;
    00676   glColor3f(1.0,1.0,1.0);
    00677   drawText(xCommands, yCommands, "ESC");
    00678   yCommands -= 15;
    00679   glColor3f(0.7,0.9,0.8);
    00680   drawText(xCommands, yCommands, "Exit program");
    00681   yCommands -= 25;
    00682   yCommands -= 25;
    00683
    00684
    00685   // dynamic (step dependent) texts
    00686   switch (currentStep)
    00687   {
    00688     case 0:
    00689       // Step title
    00690       glColor3f(0.0,1.0,1.0);
    00691       drawText(xStep, yStep, "SELECTED FILE");
    00692       yStep -= 20;
    00693       glColor3f(0.5,0.8,0.7);
    00694       drawText(xStep, yStep, lwoFileName);
    00695
    00696       // Details
    00697       yDetails -= 20;
    00698       glColor3f(0.5,0.8,0.7);
    00699       drawText(xDetails, yDetails, "Choose the model to be rendered. The sphere model contains near 5,000 triangles (press 's' to choose).");
    00700       yDetails -= 13;
    00701       drawText(xDetails, yDetails, "The venus model conains almost 100,000 triangles (press 'v' to choose).");
    00702       yDetails -= 13;
    00703       yDetails -= 13;
    00704       drawText(xDetails, yDetails, "This application will first render the mesh using the OpenGL pipeline and then convert the mesh to splats ");
    00705       yDetails -= 13;
    00706       drawText(xDetails, yDetails, "to apply a splatting rendering algorithm.");
    00707
    00708       //Commands
    00709       yCommands -= 25;
    00710       glColor3f(1.0,1.0,1.0);
    00711       drawText(xCommands, yCommands, "S");
    00712       yCommands -= 15;
    00713       glColor3f(0.7,0.9,0.8);
    00714       drawText(xCommands, yCommands, "Choose SPHERE file");
    00715
    00716       yCommands -= 25;
    00717       glColor3f(1.0,1.0,1.0);
    00718       drawText(xCommands, yCommands, "V");
    00719       yCommands -= 15;
    00720       glColor3f(0.7,0.9,0.8);
    00721       drawText(xCommands, yCommands, "Choose VENUS file");
    00722
    00723       if (inputFile) {
    00724         yCommands -= 25;
    00725         glColor3f(1.0,1.0,1.0);
    00726         drawText(xCommands, yCommands, "P");
    00727         yCommands -= 15;
    00728         glColor3f(0.7,0.9,0.8);
    00729         drawText(xCommands, yCommands, "Choose file passed");
    00730         yCommands -= 13;
    00731         drawText(xCommands, yCommands, "as parameter");
    00732       }
    00733     break;
    00734
    00735     case 1:
    00736       // Step title
    00737       glColor3f(0.0,1.0,1.0);
    00738       drawText(xStep, yStep, "STEP 1");
    00739
    00740       yStep -= 20;
    00741       glColor3f(0.5,0.8,0.7);
    00742       drawText(xStep, yStep, "Obtain the");
    00743       yStep -= 13;
    00744       drawText(xStep, yStep, "original mesh.");
    00745
    00746       // Details
    00747       yDetails -= 20;
    00748       glColor3f(0.5,0.8,0.7);
    00749       drawText(xDetails, yDetails, "Read a lwo file (LightWave format) containing the input mesh.");
    00750       yDetails -= 13;
    00751       yDetails -= 13;
    00752       sprintf (output, "Showing below the model, using OpenGL pipeline to render the mesh. Renderig time %.4fs (%.2f fps).", renderingTime, 1/renderingTime);
    00753       drawText(xDetails, yDetails, output);
    00754
    00755       //Commands
    00756       yCommands -= 25;
    00757       glColor3f(1.0,1.0,1.0);
    00758       drawText(xCommands, yCommands, "LEFT ARROW");
    00759       yCommands -= 15;
    00760       glColor3f(0.7,0.9,0.8);
    00761       drawText(xCommands, yCommands, "Rotate left");
    00762
    00763       yCommands -= 25;
    00764       glColor3f(1.0,1.0,1.0);
    00765       drawText(xCommands, yCommands, "RIGHT ARROW");
    00766       yCommands -= 15;
    00767       glColor3f(0.7,0.9,0.8);
    00768       drawText(xCommands, yCommands, "Rotate right");
    00769
    00770       yCommands -= 25;
    00771       glColor3f(1.0,1.0,1.0);
    00772       drawText(xCommands, yCommands, "UP ARROW");
    00773       yCommands -= 15;
    00774       glColor3f(0.7,0.9,0.8);
    00775       drawText(xCommands, yCommands, "Zoom in");
    00776
    00777       yCommands -= 25;
    00778       glColor3f(1.0,1.0,1.0);
    00779       drawText(xCommands, yCommands, "DOWN ARROW");
    00780       yCommands -= 15;
    00781       glColor3f(0.7,0.9,0.8);
    00782       drawText(xCommands, yCommands, "Zoom out");
    00783     break;
    00784
    00785     case 2:
    00786       // Step title
    00787       glColor3f(0.0,1.0,1.0);
    00788       drawText(xStep, yStep, "STEP 2a");
    00789
    00790       yStep -= 20;
    00791       glColor3f(0.5,0.8,0.7);
    00792       drawText(xStep, yStep, "CREATE SPLATS:");
    00793       yStep -= 13;
    00794       yStep -= 13;
    00795       drawText(xStep, yStep, "Define splats");
    00796       yStep -= 13;
    00797       drawText(xStep, yStep, "positions.");
    00798
    00799       // Details
    00800       yDetails -= 20;
    00801       glColor3f(0.5,0.8,0.7);
    00802       drawText(xDetails, yDetails, "Create the splats using the vertex positions of original mesh as center for generated splats.");
    00803       yDetails -= 13;
    00804       yDetails -= 13;
    00805       drawText(xDetails, yDetails, "Showing below the splats positions (as points).");
    00806
    00807       //Commands
    00808       yCommands -= 25;
    00809       glColor3f(1.0,1.0,1.0);
    00810       drawText(xCommands, yCommands, "LEFT ARROW");
    00811       yCommands -= 15;
    00812       glColor3f(0.7,0.9,0.8);
    00813       drawText(xCommands, yCommands, "Rotate left");
    00814
    00815       yCommands -= 25;
    00816       glColor3f(1.0,1.0,1.0);
    00817       drawText(xCommands, yCommands, "RIGHT ARROW");
    00818       yCommands -= 15;
    00819       glColor3f(0.7,0.9,0.8);
    00820       drawText(xCommands, yCommands, "Rotate right");
    00821
    00822       yCommands -= 25;
    00823       glColor3f(1.0,1.0,1.0);
    00824       drawText(xCommands, yCommands, "UP ARROW");
    00825       yCommands -= 15;
    00826       glColor3f(0.7,0.9,0.8);
    00827       drawText(xCommands, yCommands, "Zoom in");
    00828
    00829       yCommands -= 25;
    00830       glColor3f(1.0,1.0,1.0);
    00831       drawText(xCommands, yCommands, "DOWN ARROW");
    00832       yCommands -= 15;
    00833       glColor3f(0.7,0.9,0.8);
    00834       drawText(xCommands, yCommands, "Zoom out");
    00835     break;
    00836
    00837     case 3:
    00838       // Step title
    00839       glColor3f(0.0,1.0,1.0);
    00840       drawText(xStep, yStep, "STEP 2b");
    00841
    00842       yStep -= 20;
    00843       glColor3f(0.5,0.8,0.7);
    00844       drawText(xStep, yStep, "CREATE SPLATS:");
    00845       yStep -= 13;
    00846       yStep -= 13;
    00847       drawText(xStep, yStep, "Define splats");
    00848       yStep -= 13;
    00849       drawText(xStep, yStep, "normals.");
    00850
    00851       // Details
    00852       yDetails -= 20;
    00853       glColor3f(0.5,0.8,0.7);
    00854       drawText(xDetails, yDetails, "Define splats normals as the original mesh vertex normals.");
    00855       yDetails -= 13;
    00856       yDetails -= 13;
    00857       drawText(xDetails, yDetails, "Showing below the generated splats positions with normals.");
    00858
    00859       //Commands
    00860       yCommands -= 25;
    00861       glColor3f(1.0,1.0,1.0);
    00862       drawText(xCommands, yCommands, "LEFT ARROW");
    00863       yCommands -= 15;
    00864       glColor3f(0.7,0.9,0.8);
    00865       drawText(xCommands, yCommands, "Rotate left");
    00866
    00867       yCommands -= 25;
    00868       glColor3f(1.0,1.0,1.0);
    00869       drawText(xCommands, yCommands, "RIGHT ARROW");
    00870       yCommands -= 15;
    00871       glColor3f(0.7,0.9,0.8);
    00872       drawText(xCommands, yCommands, "Rotate right");
    00873
    00874       yCommands -= 25;
    00875       glColor3f(1.0,1.0,1.0);
    00876       drawText(xCommands, yCommands, "UP ARROW");
    00877       yCommands -= 15;
    00878       glColor3f(0.7,0.9,0.8);
    00879       drawText(xCommands, yCommands, "Zoom in");
    00880
    00881       yCommands -= 25;
    00882       glColor3f(1.0,1.0,1.0);
    00883       drawText(xCommands, yCommands, "DOWN ARROW");
    00884       yCommands -= 15;
    00885       glColor3f(0.7,0.9,0.8);
    00886       drawText(xCommands, yCommands, "Zoom out");
    00887     break;
    00888
    00889     case 4:
    00890       // Step title
    00891       glColor3f(0.0,1.0,1.0);
    00892       drawText(xStep, yStep, "STEP 2c");
    00893
    00894       yStep -= 20;
    00895       glColor3f(0.5,0.8,0.7);
    00896       drawText(xStep, yStep, "CREATE SPLATS:");
    00897       yStep -= 13;
    00898       yStep -= 13;
    00899       drawText(xStep, yStep, "Define splats");
    00900       yStep -= 13;
    00901       drawText(xStep, yStep, "sizes.");
    00902
    00903       // Details
    00904       yDetails -= 20;
    00905       glColor3f(0.5,0.8,0.7);
    00906       drawText(xDetails, yDetails, "Calculate each splat size evaluating the maximum distance to it's neighbors.");
    00907       yDetails -= 13;
    00908       yDetails -= 13;
    00909       drawText(xDetails, yDetails, "Showing below, just to illustrate, the generated splats as solid disks with a smaller size ");
    00910       yDetails -= 13;
    00911       drawText(xDetails, yDetails, "(1/3 of calculated splat size). Next step will show the real size.");
    00912
    00913       //Commands
    00914       yCommands -= 25;
    00915       glColor3f(1.0,1.0,1.0);
    00916       drawText(xCommands, yCommands, "LEFT ARROW");
    00917       yCommands -= 15;
    00918       glColor3f(0.7,0.9,0.8);
    00919       drawText(xCommands, yCommands, "Rotate left");
    00920
    00921       yCommands -= 25;
    00922       glColor3f(1.0,1.0,1.0);
    00923       drawText(xCommands, yCommands, "RIGHT ARROW");
    00924       yCommands -= 15;
    00925       glColor3f(0.7,0.9,0.8);
    00926       drawText(xCommands, yCommands, "Rotate right");
    00927
    00928       yCommands -= 25;
    00929       glColor3f(1.0,1.0,1.0);
    00930       drawText(xCommands, yCommands, "UP ARROW");
    00931       yCommands -= 15;
    00932       glColor3f(0.7,0.9,0.8);
    00933       drawText(xCommands, yCommands, "Zoom in");
    00934
    00935       yCommands -= 25;
    00936       glColor3f(1.0,1.0,1.0);
    00937       drawText(xCommands, yCommands, "DOWN ARROW");
    00938       yCommands -= 15;
    00939       glColor3f(0.7,0.9,0.8);
    00940       drawText(xCommands, yCommands, "Zoom out");
    00941     break;
    00942
    00943     case 5:
    00944       // Step title
    00945       glColor3f(0.0,1.0,1.0);
    00946       drawText(xStep, yStep, "STEP 2c");
    00947
    00948       yStep -= 20;
    00949       glColor3f(0.5,0.8,0.7);
    00950       drawText(xStep, yStep, "CREATE SPLATS:");
    00951       yStep -= 13;
    00952       yStep -= 13;
    00953       drawText(xStep, yStep, "Define splats");
    00954       yStep -= 13;
    00955       drawText(xStep, yStep, "sizes.");
    00956
    00957       // Details
    00958       yDetails -= 20;
    00959       glColor3f(0.5,0.8,0.7);
    00960       drawText(xDetails, yDetails, "Calculate each splat size evaluating the maximum distance to it's neighbors.");
    00961       yDetails -= 13;
    00962       yDetails -= 13;
    00963       drawText(xDetails, yDetails, "Showing below the generated splats as circles, with the calculated size.");
    00964
    00965       //Commands
    00966       yCommands -= 25;
    00967       glColor3f(1.0,1.0,1.0);
    00968       drawText(xCommands, yCommands, "LEFT ARROW");
    00969       yCommands -= 15;
    00970       glColor3f(0.7,0.9,0.8);
    00971       drawText(xCommands, yCommands, "Rotate left");
    00972
    00973       yCommands -= 25;
    00974       glColor3f(1.0,1.0,1.0);
    00975       drawText(xCommands, yCommands, "RIGHT ARROW");
    00976       yCommands -= 15;
    00977       glColor3f(0.7,0.9,0.8);
    00978       drawText(xCommands, yCommands, "Rotate right");
    00979
    00980       yCommands -= 25;
    00981       glColor3f(1.0,1.0,1.0);
    00982       drawText(xCommands, yCommands, "UP ARROW");
    00983       yCommands -= 15;
    00984       glColor3f(0.7,0.9,0.8);
    00985       drawText(xCommands, yCommands, "Zoom in");
    00986
    00987       yCommands -= 25;
    00988       glColor3f(1.0,1.0,1.0);
    00989       drawText(xCommands, yCommands, "DOWN ARROW");
    00990       yCommands -= 15;
    00991       glColor3f(0.7,0.9,0.8);
    00992       drawText(xCommands, yCommands, "Zoom out");
    00993     break;
    00994
    00995     case 6:
    00996       // Step title
    00997       glColor3f(0.0,1.0,1.0);
    00998       drawText(xStep, yStep, "STEP 3");
    00999
    01000       yStep -= 20;
    01001       glColor3f(0.5,0.8,0.7);
    01002       drawText(xStep, yStep, "Render model using");
    01003       yStep -= 13;
    01004       drawText(xStep, yStep, "splatting algorithm");
    01005       yStep -= 13;
    01006       yStep -= 13;
    01007       drawText(xStep, yStep, "(last step)");
    01008
    01009       // Details
    01010       yDetails -= 20;
    01011       glColor3f(0.5,0.8,0.7);
    01012       drawText(xDetails, yDetails, "Generate the final image from obtained splats, using a approximation for a resampling filter,");
    01013       yDetails -= 13;
    01014       drawText(xDetails, yDetails, "that represents the convolution of a prefilter and a reconstruction filter, both Gaussians.");
    01015       yDetails -= 13;
    01016       yDetails -= 13;
    01017       sprintf (output, "Showing below the final image rendered using splatting. Renderig time %.4fs (%.2f fps).", renderingTime, 1/renderingTime);
    01018       drawText(xDetails, yDetails, output);
    01019       yDetails -= 13;
    01020       drawText(xDetails, yDetails, "Using different camera settings.");
    01021
    01022       //Commands
    01023       yCommands -= 25;
    01024       glColor3f(1.0,1.0,1.0);
    01025       drawText(xCommands, yCommands, "LEFT ARROW");
    01026       yCommands -= 15;
    01027       glColor3f(0.7,0.9,0.8);
    01028       drawText(xCommands, yCommands, "Rotate left");
    01029
    01030       yCommands -= 25;
    01031       glColor3f(1.0,1.0,1.0);
    01032       drawText(xCommands, yCommands, "RIGHT ARROW");
    01033       yCommands -= 15;
    01034       glColor3f(0.7,0.9,0.8);
    01035       drawText(xCommands, yCommands, "Rotate right");
    01036
    01037       yCommands -= 25;
    01038       glColor3f(1.0,1.0,1.0);
    01039       drawText(xCommands, yCommands, "UP ARROW");
    01040       yCommands -= 15;
    01041       glColor3f(0.7,0.9,0.8);
    01042       drawText(xCommands, yCommands, "Zoom in");
    01043
    01044       yCommands -= 25;
    01045       glColor3f(1.0,1.0,1.0);
    01046       drawText(xCommands, yCommands, "DOWN ARROW");
    01047       yCommands -= 15;
    01048       glColor3f(0.7,0.9,0.8);
    01049       drawText(xCommands, yCommands, "Zoom out");
    01050     break;
    01051
    01052     default:
    01053     break;
    01054   };
    01055
    01056
    01057
    01058   glutSwapBuffers();
    01059
    01060   glutSetCursor(GLUT_CURSOR_INHERIT);
    01061 } /* REDISPLAY callback  */
    01062
    01063
    01064 void resizeABuffer(int width, int height, int subpixels)
    01065 {
    01066         if( width < 1 || width > maxResolution || height < 1 || height > maxResolution || subpixels < 1 || subpixels > 64 ) return;
    01067         if( abuffer )
    01068         {
    01069                 if( width != abuffer->getWidth() || height != abuffer->getHeight() || subpixels != abuffer->getSubpixels() )
    01070                 {
    01071                         delete abuffer;
    01072                         delete buffer;
    01073                 }
    01074                 else return;
    01075         }
    01076         if( subpixels != abuffer->getSubpixels() ) makeJitter(subpixels);
    01077         abuffer = new ABuffer(width, height, subpixels );
    01078         buffer = new Color[width * height];
    01079 }
    01080
    01081
    01082 void reshape_cb(int new_width, int new_height)
    01083 {
    01084   glutReshapeWindow(width, height);
    01085
    01086   glutPostRedisplay(); /* force redisplay */
    01087 }
    01088
    01089 void keyboard_cb(unsigned char key, int x, int y) {
    01090   if ((currentStep < 6) && (key == 13)) {
    01091     executeNextStep();
    01092     glutPostRedisplay();
    01093   }
    01094
    01095   if (key == 8) {
    01096     executePreviousStep();
    01097     glutPostRedisplay();
    01098   }
    01099
    01100   if (key == 27)
    01101     exit(0);
    01102
    01103   if (currentStep == 0) {
    01104     if ((key == 's') || (key == 'S'))
    01105       strcpy(lwoFileName, "sphere.lwo");
    01106
    01107     if ((key == 'v') || (key == 'V'))
    01108       strcpy(lwoFileName, "venus.lwo");
    01109
    01110     if (inputFile && ((key == 'p') || (key == 'P')))
    01111       strcpy(lwoFileName, inputFileName);
    01112
    01113     glutPostRedisplay();
    01114   }
    01115
    01116 }
    01117
    01118
    01119 void special_cb(int key, int x, int y)
    01120 {
    01121   if ((currentStep >= 1) && (currentStep <= 6)) {
    01122     switch (key) {
    01123       case GLUT_KEY_LEFT:
    01124         yRotation    -= rotationStep;
    01125         yRotationAcc -= rotationStep;
    01126       break;
    01127
    01128       case GLUT_KEY_RIGHT:
    01129         yRotation    += rotationStep;
    01130         yRotationAcc += rotationStep;
    01131       break;
    01132
    01133       case GLUT_KEY_UP:
    01134         if ((zEye - zEyeStep) > 0)
    01135           zEye -= zEyeStep;
    01136       break;
    01137
    01138       case GLUT_KEY_DOWN:
    01139         if ((zEye + zEyeStep) < 20*zEye)
    01140           zEye += zEyeStep;
    01141       break;
    01142
    01143     }
    01144
    01145     glutPostRedisplay(); /* force window redraw */
    01146   }
    01147
    01148 }
    01149
    01150
    01151 int main(int argc, char **argv)
    01152 {
    01153   int i;
    01154
    01155   sizex = widthImage3D;
    01156   sizey = heightImage3D;
    01157
    01158   abuffer = new ABuffer(sizex,sizey,subpixels);
    01159         buffer = new Color[sizex * sizey];
    01160         makeJitter(subpixels);
    01161
    01162         int c = 1;
    01163
    01164   /* Initializing GLUT */
    01165   glutInit(&argc, argv);
    01166   glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE);
    01167   glutInitWindowSize(width, height);
    01168   glutCreateWindow("VCRA: Point Based Rendering Steps");
    01169
    01170   /* Registering callbacks */
    01171   glutDisplayFunc(display_cb);
    01172   glutReshapeFunc(reshape_cb);
    01173   glutKeyboardFunc(keyboard_cb);
    01174   glutSpecialFunc(special_cb);
    01175
    01176
    01177   if (argc > 1) {
    01178     strcpy(lwoFileName , (char *)argv[1]);
    01179     strcpy(inputFileName, lwoFileName);
    01180     inputFile = true;
    01181   } else
    01182     strcpy(lwoFileName , "sphere.lwo");
    01183
    01184
    01185   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    01186   glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    01187   glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
    01188
    01189   /* GLUT main loop */
    01190   glutMainLoop();             /* wait for user events*/
    01191
    01192   return 0;
    01193 }