(no commit message)
[atyndall/cits2231.git] / scene.c
diff --git a/scene.c b/scene.c
index f8dbc57..e667b02 100644 (file)
--- a/scene.c
+++ b/scene.c
+/**\r
+ * CITS2231 Graphics Scene Editor\r
+ * @author Ashley Tyndall (20915779)\r
+ */\r
 \r
-/* Copyright (c) Mark J. Kilgard, 1994, 1997.  */\r
-\r
-/* This program is freely distributable without licensing fees\r
-   and is provided without guarantee or warrantee expressed or\r
-   implied. This program is -not- in the public domain. */\r
-\r
-/* Example for PC game developers to show how to *combine* texturing,\r
-   reflections, and projected shadows all in real-time with OpenGL.\r
-   Robust reflections use stenciling.  Robust projected shadows\r
-   use both stenciling and polygon offset.  PC game programmers\r
-   should realize that neither stenciling nor polygon offset are\r
-   supported by Direct3D, so these real-time rendering algorithms\r
-   are only really viable with OpenGL.\r
-\r
-   The program has modes for disabling the stenciling and polygon\r
-   offset uses.  It is worth running this example with these features\r
-   toggled off so you can see the sort of artifacts that result.\r
-\r
-   Notice that the floor texturing, reflections, and shadowing\r
-   all co-exist properly. */\r
-\r
-/* When you run this program:  Left mouse button controls the\r
-   view.  Middle mouse button controls light position (left &\r
-   right rotates light around dino; up & down moves light\r
-   position up and down).  Right mouse button pops up menu. */\r
-\r
-/* Check out the comments in the "redraw" routine to see how the\r
-   reflection blending and surface stenciling is done.  You can\r
-   also see in "redraw" how the projected shadows are rendered,\r
-\r
-   including the use of stenciling and polygon offset. */\r
-\r
-/* This program is derived from glutdino.c */\r
-\r
-/* Compile: cc -o dinoshade dinoshade.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm */\r
-\r
-#include <stdio.h>\r
 #include <stdlib.h>\r
+#include <stdio.h>\r
+#include <dirent.h>\r
 #include <string.h>\r
-#include <math.h>       /* for cos(), sin(), and sqrt() */\r
-#include <GL/glut.h>    /* OpenGL Utility Toolkit header */\r
-\r
-/* Some <math.h> files do not define M_PI... */\r
-#ifndef M_PI\r
-#define M_PI 3.14159265\r
-#endif\r
-\r
-/* Variable controlling various rendering modes. */\r
-static int stencilReflection = 1, stencilShadow = 1, offsetShadow = 1;\r
-static int renderShadow = 1, renderDinosaur = 1, renderReflection = 1;\r
-static int linearFiltering = 0, useMipmaps = 0, useTexture = 1;\r
-static int reportSpeed = 0;\r
-static int animation = 1;\r
-static GLboolean lightSwitch = GL_TRUE;\r
-static int directionalLight = 1;\r
-static int forceExtension = 0;\r
-\r
-/* Time varying or user-controled variables. */\r
-static float jump = 0.0;\r
-static float lightAngle = 0.0, lightHeight = 20;\r
-GLfloat angle = -150;   /* in degrees */\r
-GLfloat angle2 = 30;   /* in degrees */\r
-\r
-int moving, startx, starty;\r
-int lightMoving = 0, lightStartX, lightStartY;\r
-\r
-enum {\r
-  MISSING, EXTENSION, ONE_DOT_ONE\r
-};\r
-int polygonOffsetVersion;\r
-\r
-static GLdouble bodyWidth = 3.0;\r
-/* *INDENT-OFF* */\r
-static GLfloat body[][2] = { {0, 3}, {1, 1}, {5, 1}, {8, 4}, {10, 4}, {11, 5},\r
-  {11, 11.5}, {13, 12}, {13, 13}, {10, 13.5}, {13, 14}, {13, 15}, {11, 16},\r
-  {8, 16}, {7, 15}, {7, 13}, {8, 12}, {7, 11}, {6, 6}, {4, 3}, {3, 2},\r
-  {1, 2} };\r
-static GLfloat arm[][2] = { {8, 10}, {9, 9}, {10, 9}, {13, 8}, {14, 9}, {16, 9},\r
-  {15, 9.5}, {16, 10}, {15, 10}, {15.5, 11}, {14.5, 10}, {14, 11}, {14, 10},\r
-  {13, 9}, {11, 11}, {9, 11} };\r
-static GLfloat leg[][2] = { {8, 6}, {8, 4}, {9, 3}, {9, 2}, {8, 1}, {8, 0.5}, {9, 0},\r
-  {12, 0}, {10, 1}, {10, 2}, {12, 4}, {11, 6}, {10, 7}, {9, 7} };\r
-static GLfloat eye[][2] = { {8.75, 15}, {9, 14.7}, {9.6, 14.7}, {10.1, 15},\r
-  {9.6, 15.25}, {9, 15.25} };\r
-static GLfloat lightPosition[4];\r
-static GLfloat lightColor[] = {0.8, 1.0, 0.8, 1.0}; /* green-tinted */\r
-static GLfloat skinColor[] = {0.1, 1.0, 0.1, 1.0}, eyeColor[] = {1.0, 0.2, 0.2, 1.0};\r
-/* *INDENT-ON* */\r
-\r
-/* Nice floor texture tiling pattern. */\r
-static char *circles[] = {\r
-  "....xxxx........",\r
-  "..xxxxxxxx......",\r
-  ".xxxxxxxxxx.....",\r
-  ".xxx....xxx.....",\r
-  "xxx......xxx....",\r
-  "xxx......xxx....",\r
-  "xxx......xxx....",\r
-  "xxx......xxx....",\r
-  ".xxx....xxx.....",\r
-  ".xxxxxxxxxx.....",\r
-  "..xxxxxxxx......",\r
-  "....xxxx........",\r
-  "................",\r
-  "................",\r
-  "................",\r
-  "................",\r
-};\r
-\r
-static void\r
-makeFloorTexture(void)\r
-{\r
-  GLubyte floorTexture[16][16][3];\r
-  GLubyte *loc;\r
-  int s, t;\r
-\r
-  /* Setup RGB image for the texture. */\r
-  loc = (GLubyte*) floorTexture;\r
-  for (t = 0; t < 16; t++) {\r
-    for (s = 0; s < 16; s++) {\r
-      if (circles[t][s] == 'x') {\r
-       /* Nice green. */\r
-        loc[0] = 0x1f;\r
-        loc[1] = 0x8f;\r
-        loc[2] = 0x1f;\r
-      } else {\r
-       /* Light gray. */\r
-        loc[0] = 0xaa;\r
-        loc[1] = 0xaa;\r
-        loc[2] = 0xaa;\r
-      }\r
-      loc += 3;\r
-    }\r
-  }\r
+#include <math.h>\r
+#include <GL/gl.h>\r
+#include <GL/glut.h>\r
+#include <time.h>\r
+\r
+#include "bitmap.h"\r
+#include "globals.h"\r
+#include "helper.h"\r
+#include "types.h"\r
+#include "scene.h"\r
+\r
+/**\r
+ * Event hander for main menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processMainEvents(int id) {\r
+  switch (id) {\r
+    case M_ROTATE_MOVE_CAMERA:\r
+      // Do stuff\r
+      break;\r
+\r
+    case M_POSITION_SCALE:\r
+      // Do stuff\r
+      break;\r
+\r
+    case M_ROTATION_TEXTURE_SCALE:\r
+      // Do stuff\r
+      break;\r
+\r
+    case M_EXIT:\r
+      exit(EXIT_SUCCESS);\r
 \r
-  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);\r
-\r
-  if (useMipmaps) {\r
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,\r
-      GL_LINEAR_MIPMAP_LINEAR);\r
-    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 16, 16,\r
-      GL_RGB, GL_UNSIGNED_BYTE, floorTexture);\r
-  } else {\r
-    if (linearFiltering) {\r
-      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);\r
-    } else {\r
-      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
-    }\r
-    glTexImage2D(GL_TEXTURE_2D, 0, 3, 16, 16, 0,\r
-      GL_RGB, GL_UNSIGNED_BYTE, floorTexture);\r
   }\r
 }\r
 \r
-enum {\r
-  X, Y, Z, W\r
-};\r
-enum {\r
-  A, B, C, D\r
-};\r
-\r
-/* Create a matrix that will project the desired shadow. */\r
-void\r
-shadowMatrix(GLfloat shadowMat[4][4],\r
-  GLfloat groundplane[4],\r
-  GLfloat lightpos[4])\r
-{\r
-  GLfloat dot;\r
-\r
-  /* Find dot product between light position vector and ground plane normal. */\r
-  dot = groundplane[X] * lightpos[X] +\r
-    groundplane[Y] * lightpos[Y] +\r
-    groundplane[Z] * lightpos[Z] +\r
-    groundplane[W] * lightpos[W];\r
-\r
-  shadowMat[0][0] = dot - lightpos[X] * groundplane[X];\r
-  shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];\r
-  shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];\r
-  shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];\r
-\r
-  shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];\r
-  shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];\r
-  shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];\r
-  shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];\r
-\r
-  shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];\r
-  shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];\r
-  shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];\r
-  shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];\r
-\r
-  shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];\r
-  shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];\r
-  shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];\r
-  shadowMat[3][3] = dot - lightpos[W] * groundplane[W];\r
+/**\r
+ * Event hander for materials menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processMaterialEvents(int id) {\r
+  switch (id) {\r
+    case M_MATERIAL_ALL_RGB:\r
+      // Do stuff\r
+      break;\r
 \r
-}\r
+    case M_MATERIAL_AMBIENT_RGB:\r
+      // Do stuff\r
+      break;\r
 \r
-/* Find the plane equation given 3 points. */\r
-void\r
-findPlane(GLfloat plane[4],\r
-  GLfloat v0[3], GLfloat v1[3], GLfloat v2[3])\r
-{\r
-  GLfloat vec0[3], vec1[3];\r
+    case M_MATERIAL_DIFFUSE_RGB:\r
+      // Do stuff\r
+      break;\r
 \r
-  /* Need 2 vectors to find cross product. */\r
-  vec0[X] = v1[X] - v0[X];\r
-  vec0[Y] = v1[Y] - v0[Y];\r
-  vec0[Z] = v1[Z] - v0[Z];\r
+    case M_MATERIAL_SPECULAR_RGB:\r
+      // Do stuff\r
+      break;\r
 \r
-  vec1[X] = v2[X] - v0[X];\r
-  vec1[Y] = v2[Y] - v0[Y];\r
-  vec1[Z] = v2[Z] - v0[Z];\r
+    case M_MATERIAL_ALL_ADSS:\r
+      // Do stuff\r
+      break;\r
 \r
-  /* find cross product to get A, B, and C of plane equation */\r
-  plane[A] = vec0[Y] * vec1[Z] - vec0[Z] * vec1[Y];\r
-  plane[B] = -(vec0[X] * vec1[Z] - vec0[Z] * vec1[X]);\r
-  plane[C] = vec0[X] * vec1[Y] - vec0[Y] * vec1[X];\r
+    case M_MATERIAL_RED_ADSS:\r
+      // Do stuff\r
+      break;\r
 \r
-  plane[D] = -(plane[A] * v0[X] + plane[B] * v0[Y] + plane[C] * v0[Z]);\r
-}\r
+    case M_MATERIAL_GREEN_ADSS:\r
+      // Do stuff\r
+      break;\r
 \r
-void\r
-extrudeSolidFromPolygon(GLfloat data[][2], unsigned int dataSize,\r
-  GLdouble thickness, GLuint side, GLuint edge, GLuint whole)\r
-{\r
-  static GLUtriangulatorObj *tobj = NULL;\r
-  GLdouble vertex[3], dx, dy, len;\r
-  int i;\r
-  int count = (int) (dataSize / (2 * sizeof(GLfloat)));\r
-\r
-  if (tobj == NULL) {\r
-    tobj = gluNewTess();  /* create and initialize a GLU\r
-                             polygon tesselation object */\r
-    gluTessCallback(tobj, GLU_BEGIN, glBegin);\r
-    gluTessCallback(tobj, GLU_VERTEX, glVertex2fv);  /* semi-tricky */\r
-    gluTessCallback(tobj, GLU_END, glEnd);\r
-  }\r
-  glNewList(side, GL_COMPILE);\r
-  glShadeModel(GL_SMOOTH);  /* smooth minimizes seeing\r
-                               tessellation */\r
-  gluBeginPolygon(tobj);\r
-  for (i = 0; i < count; i++) {\r
-    vertex[0] = data[i][0];\r
-    vertex[1] = data[i][1];\r
-    vertex[2] = 0;\r
-    gluTessVertex(tobj, vertex, data[i]);\r
-  }\r
-  gluEndPolygon(tobj);\r
-  glEndList();\r
-  glNewList(edge, GL_COMPILE);\r
-  glShadeModel(GL_FLAT);  /* flat shade keeps angular hands\r
-                             from being "smoothed" */\r
-  glBegin(GL_QUAD_STRIP);\r
-  for (i = 0; i <= count; i++) {\r
-    /* mod function handles closing the edge */\r
-    glVertex3f(data[i % count][0], data[i % count][1], 0.0);\r
-    glVertex3f(data[i % count][0], data[i % count][1], thickness);\r
-    /* Calculate a unit normal by dividing by Euclidean\r
-       distance. We * could be lazy and use\r
-       glEnable(GL_NORMALIZE) so we could pass in * arbitrary\r
-       normals for a very slight performance hit. */\r
-    dx = data[(i + 1) % count][1] - data[i % count][1];\r
-    dy = data[i % count][0] - data[(i + 1) % count][0];\r
-    len = sqrt(dx * dx + dy * dy);\r
-    glNormal3f(dx / len, dy / len, 0.0);\r
-  }\r
-  glEnd();\r
-  glEndList();\r
-  glNewList(whole, GL_COMPILE);\r
-  glFrontFace(GL_CW);\r
-  glCallList(edge);\r
-  glNormal3f(0.0, 0.0, -1.0);  /* constant normal for side */\r
-  glCallList(side);\r
-  glPushMatrix();\r
-  glTranslatef(0.0, 0.0, thickness);\r
-  glFrontFace(GL_CCW);\r
-  glNormal3f(0.0, 0.0, 1.0);  /* opposite normal for other side */\r
-  glCallList(side);\r
-  glPopMatrix();\r
-  glEndList();\r
-}\r
-\r
-/* Enumerants for refering to display lists. */\r
-typedef enum {\r
-  RESERVED, BODY_SIDE, BODY_EDGE, BODY_WHOLE, ARM_SIDE, ARM_EDGE, ARM_WHOLE,\r
-  LEG_SIDE, LEG_EDGE, LEG_WHOLE, EYE_SIDE, EYE_EDGE, EYE_WHOLE\r
-} displayLists;\r
-\r
-static void\r
-makeDinosaur(void)\r
-{\r
-  extrudeSolidFromPolygon(body, sizeof(body), bodyWidth,\r
-    BODY_SIDE, BODY_EDGE, BODY_WHOLE);\r
-  extrudeSolidFromPolygon(arm, sizeof(arm), bodyWidth / 4,\r
-    ARM_SIDE, ARM_EDGE, ARM_WHOLE);\r
-  extrudeSolidFromPolygon(leg, sizeof(leg), bodyWidth / 2,\r
-    LEG_SIDE, LEG_EDGE, LEG_WHOLE);\r
-  extrudeSolidFromPolygon(eye, sizeof(eye), bodyWidth + 0.2,\r
-    EYE_SIDE, EYE_EDGE, EYE_WHOLE);\r
-}\r
-\r
-static void\r
-drawDinosaur(void)\r
-\r
-{\r
-  glPushMatrix();\r
-  /* Translate the dinosaur to be at (0,8,0). */\r
-  glTranslatef(-8, 0, -bodyWidth / 2);\r
-  glTranslatef(0.0, jump, 0.0);\r
-  glMaterialfv(GL_FRONT, GL_DIFFUSE, skinColor);\r
-  glCallList(BODY_WHOLE);\r
-  glTranslatef(0.0, 0.0, bodyWidth);\r
-  glCallList(ARM_WHOLE);\r
-  glCallList(LEG_WHOLE);\r
-  glTranslatef(0.0, 0.0, -bodyWidth - bodyWidth / 4);\r
-  glCallList(ARM_WHOLE);\r
-  glTranslatef(0.0, 0.0, -bodyWidth / 4);\r
-  glCallList(LEG_WHOLE);\r
-  glTranslatef(0.0, 0.0, bodyWidth / 2 - 0.1);\r
-  glMaterialfv(GL_FRONT, GL_DIFFUSE, eyeColor);\r
-  glCallList(EYE_WHOLE);\r
-  glPopMatrix();\r
-}\r
+    case M_MATERIAL_BLUE_ADSS:\r
+      // Do stuff\r
+      break;\r
 \r
-static GLfloat floorVertices[4][3] = {\r
-  { -20.0, 0.0, 20.0 },\r
-  { 20.0, 0.0, 20.0 },\r
-  { 20.0, 0.0, -20.0 },\r
-  { -20.0, 0.0, -20.0 },\r
-};\r
-\r
-/* Draw a floor (possibly textured). */\r
-static void\r
-drawFloor(void)\r
-{\r
-  glDisable(GL_LIGHTING);\r
-\r
-  if (useTexture) {\r
-    glEnable(GL_TEXTURE_2D);\r
   }\r
-\r
-  glBegin(GL_QUADS);\r
-    glTexCoord2f(0.0, 0.0);\r
-    glVertex3fv(floorVertices[0]);\r
-    glTexCoord2f(0.0, 16.0);\r
-    glVertex3fv(floorVertices[1]);\r
-    glTexCoord2f(16.0, 16.0);\r
-    glVertex3fv(floorVertices[2]);\r
-    glTexCoord2f(16.0, 0.0);\r
-    glVertex3fv(floorVertices[3]);\r
-  glEnd();\r
-\r
-  if (useTexture) {\r
-    glDisable(GL_TEXTURE_2D);\r
-  }\r
-\r
-  glEnable(GL_LIGHTING);\r
 }\r
 \r
-static GLfloat floorPlane[4];\r
-static GLfloat floorShadow[4][4];\r
+/**\r
+ * Event hander for light menu events\r
+ * @param id ID of menu item selected\r
+ */\r
+void processLightEvents(int id) {\r
+  switch (id) {\r
+    case M_LIGHT_MOVE_LIGHT_1:\r
+      // Do stuff\r
+      break;\r
 \r
-static void\r
-redraw(void)\r
-{\r
-  int start, end;\r
+    case M_LIGHT_RGBALL_LIGHT_1:\r
+      // Do stuff\r
+      break;\r
 \r
-  if (reportSpeed) {\r
-    start = glutGet(GLUT_ELAPSED_TIME);\r
-  }\r
+    case M_LIGHT_MOVE_LIGHT_2:\r
+      // Do stuff\r
+      break;\r
 \r
-  /* Clear; default stencil clears to zero. */\r
-  if ((stencilReflection && renderReflection) || (stencilShadow && renderShadow)) {\r
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);\r
-  } else {\r
-    /* Avoid clearing stencil when not using it. */\r
-    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
-  }\r
+    case M_LIGHT_RGBALL_LIGHT_2:\r
+      // Do stuff\r
+      break;\r
 \r
-  /* Reposition the light source. */\r
-  lightPosition[0] = 12*cos(lightAngle);\r
-  lightPosition[1] = lightHeight;\r
-  lightPosition[2] = 12*sin(lightAngle);\r
-  if (directionalLight) {\r
-    lightPosition[3] = 0.0;\r
-  } else {\r
-    lightPosition[3] = 1.0;\r
   }\r
+}\r
 \r
-  shadowMatrix(floorShadow, floorPlane, lightPosition);\r
-\r
-  glPushMatrix();\r
-    /* Perform scene rotations based on user mouse input. */\r
-    glRotatef(angle2, 1.0, 0.0, 0.0);\r
-    glRotatef(angle, 0.0, 1.0, 0.0);\r
-\r
-    /* Tell GL new light source position. */\r
-    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
-\r
-    if (renderReflection) {\r
-      if (stencilReflection) {\r
-        /* We can eliminate the visual "artifact" of seeing the "flipped"\r
-          dinosaur underneath the floor by using stencil.  The idea is\r
-          draw the floor without color or depth update but so that\r
-          a stencil value of one is where the floor will be.  Later when\r
-          rendering the dinosaur reflection, we will only update pixels\r
-          with a stencil value of 1 to make sure the reflection only\r
-          lives on the floor, not below the floor. */\r
-\r
-        /* Don't update color or depth. */\r
-        glDisable(GL_DEPTH_TEST);\r
-        glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);\r
-\r
-        /* Draw 1 into the stencil buffer. */\r
-        glEnable(GL_STENCIL_TEST);\r
-        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);\r
-        glStencilFunc(GL_ALWAYS, 1, 0xffffffff);\r
-\r
-        /* Now render floor; floor pixels just get their stencil set to 1. */\r
-        drawFloor();\r
-\r
-        /* Re-enable update of color and depth. */\r
-        glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);\r
-        glEnable(GL_DEPTH_TEST);\r
-\r
-        /* Now, only render where stencil is set to 1. */\r
-        glStencilFunc(GL_EQUAL, 1, 0xffffffff);  /* draw if ==1 */\r
-        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);\r
-      }\r
-\r
-      glPushMatrix();\r
-\r
-        /* The critical reflection step: Reflect dinosaur through the floor\r
-           (the Y=0 plane) to make a relection. */\r
-        glScalef(1.0, -1.0, 1.0);\r
-\r
-       /* Reflect the light position. */\r
-        glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
-\r
-        /* To avoid our normals getting reversed and hence botched lighting\r
-          on the reflection, turn on normalize.  */\r
-        glEnable(GL_NORMALIZE);\r
-        glCullFace(GL_FRONT);\r
-\r
-        /* Draw the reflected dinosaur. */\r
-        drawDinosaur();\r
-\r
-        /* Disable noramlize again and re-enable back face culling. */\r
-        glDisable(GL_NORMALIZE);\r
-        glCullFace(GL_BACK);\r
-\r
-      glPopMatrix();\r
-\r
-      /* Switch back to the unreflected light position. */\r
-      glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
-\r
-      if (stencilReflection) {\r
-        glDisable(GL_STENCIL_TEST);\r
-      }\r
-    }\r
-\r
-    /* Back face culling will get used to only draw either the top or the\r
-       bottom floor.  This let's us get a floor with two distinct\r
-       appearances.  The top floor surface is reflective and kind of red.\r
-       The bottom floor surface is not reflective and blue. */\r
-\r
-    /* Draw "bottom" of floor in blue. */\r
-    glFrontFace(GL_CW);  /* Switch face orientation. */\r
-    glColor4f(0.1, 0.1, 0.7, 1.0);\r
-    drawFloor();\r
-    glFrontFace(GL_CCW);\r
-\r
-    if (renderShadow) {\r
-      if (stencilShadow) {\r
-       /* Draw the floor with stencil value 3.  This helps us only\r
-          draw the shadow once per floor pixel (and only on the\r
-          floor pixels). */\r
-        glEnable(GL_STENCIL_TEST);\r
-        glStencilFunc(GL_ALWAYS, 3, 0xffffffff);\r
-        glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);\r
-      }\r
-    }\r
-\r
-    /* Draw "top" of floor.  Use blending to blend in reflection. */\r
-    glEnable(GL_BLEND);\r
-    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
-    glColor4f(0.7, 0.0, 0.0, 0.3);\r
-    glColor4f(1.0, 1.0, 1.0, 0.3);\r
-    drawFloor();\r
-    glDisable(GL_BLEND);\r
+/**\r
+ * Event hander for object menu events\r
+ * @param id ID of object selected\r
+ */\r
+void processObjectEvents(int id) {\r
 \r
-    if (renderDinosaur) {\r
-      /* Draw "actual" dinosaur, not its reflection. */\r
-      drawDinosaur();\r
-    }\r
-\r
-    if (renderShadow) {\r
-\r
-      /* Render the projected shadow. */\r
-\r
-      if (stencilShadow) {\r
-\r
-        /* Now, only render where stencil is set above 2 (ie, 3 where\r
-          the top floor is).  Update stencil with 2 where the shadow\r
-          gets drawn so we don't redraw (and accidently reblend) the\r
-          shadow). */\r
-        glStencilFunc(GL_LESS, 2, 0xffffffff);  /* draw if ==1 */\r
-        glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);\r
-      }\r
-\r
-      /* To eliminate depth buffer artifacts, we use polygon offset\r
-        to raise the depth of the projected shadow slightly so\r
-        that it does not depth buffer alias with the floor. */\r
-      if (offsetShadow) {\r
-       switch (polygonOffsetVersion) {\r
-       case EXTENSION:\r
-#ifdef GL_EXT_polygon_offset\r
-         glEnable(GL_POLYGON_OFFSET_EXT);\r
-         break;\r
-#endif\r
-#ifdef GL_VERSION_1_1\r
-       case ONE_DOT_ONE:\r
-          glEnable(GL_POLYGON_OFFSET_FILL);\r
-         break;\r
-#endif\r
-       case MISSING:\r
-         /* Oh well. */\r
-         break;\r
-       }\r
-      }\r
-\r
-      /* Render 50% black shadow color on top of whatever the\r
-         floor appareance is. */\r
-      glEnable(GL_BLEND);\r
-      glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);\r
-      glDisable(GL_LIGHTING);  /* Force the 50% black. */\r
-      glColor4f(0.0, 0.0, 0.0, 0.5);\r
-\r
-      glPushMatrix();\r
-       /* Project the shadow. */\r
-        glMultMatrixf((GLfloat *) floorShadow);\r
-        drawDinosaur();\r
-      glPopMatrix();\r
-\r
-      glDisable(GL_BLEND);\r
-      glEnable(GL_LIGHTING);\r
+}\r
 \r
-      if (offsetShadow) {\r
-       switch (polygonOffsetVersion) {\r
-#ifdef GL_EXT_polygon_offset\r
-       case EXTENSION:\r
-         glDisable(GL_POLYGON_OFFSET_EXT);\r
-         break;\r
-#endif\r
-#ifdef GL_VERSION_1_1\r
-       case ONE_DOT_ONE:\r
-          glDisable(GL_POLYGON_OFFSET_FILL);\r
-         break;\r
-#endif\r
-       case MISSING:\r
-         /* Oh well. */\r
-         break;\r
-       }\r
-      }\r
-      if (stencilShadow) {\r
-        glDisable(GL_STENCIL_TEST);\r
-      }\r
-    }\r
+/**\r
+ * Event hander for texture menu events\r
+ * @param id ID of texutre selected\r
+ */\r
+void processTextureEvents(int id) {\r
 \r
-    glPushMatrix();\r
-    glDisable(GL_LIGHTING);\r
-    glColor3f(1.0, 1.0, 0.0);\r
-    if (directionalLight) {\r
-      /* Draw an arrowhead. */\r
-      glDisable(GL_CULL_FACE);\r
-      glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);\r
-      glRotatef(lightAngle * -180.0 / M_PI, 0, 1, 0);\r
-      glRotatef(atan(lightHeight/12) * 180.0 / M_PI, 0, 0, 1);\r
-      glBegin(GL_TRIANGLE_FAN);\r
-       glVertex3f(0, 0, 0);\r
-       glVertex3f(2, 1, 1);\r
-       glVertex3f(2, -1, 1);\r
-       glVertex3f(2, -1, -1);\r
-       glVertex3f(2, 1, -1);\r
-       glVertex3f(2, 1, 1);\r
-      glEnd();\r
-      /* Draw a white line from light direction. */\r
-      glColor3f(1.0, 1.0, 1.0);\r
-      glBegin(GL_LINES);\r
-       glVertex3f(0, 0, 0);\r
-       glVertex3f(5, 0, 0);\r
-      glEnd();\r
-      glEnable(GL_CULL_FACE);\r
-    } else {\r
-      /* Draw a yellow ball at the light source. */\r
-      glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);\r
-      glutSolidSphere(1.0, 5, 5);\r
-    }\r
-    glEnable(GL_LIGHTING);\r
-    glPopMatrix();\r
+}\r
 \r
-  glPopMatrix();\r
+/**\r
+ * Event hander for ground texture menu events\r
+ * @param id ID of ground texture selected\r
+ */\r
+void processGTextureEvents(int id) {\r
 \r
-  if (reportSpeed) {\r
-    glFinish();\r
-    end = glutGet(GLUT_ELAPSED_TIME);\r
-    printf("Speed %.3g frames/sec (%d ms)\n", 1000.0/(end-start), end-start);\r
-  }\r
+}\r
 \r
-  glutSwapBuffers();\r
+/**\r
+ * Creates menu for program\r
+ */\r
+void makeMenu() {\r
+  // Construct material menu\r
+  int materialMenu = glutCreateMenu(processMaterialEvents);\r
+  glutAddMenuEntry("All R/G/B", M_MATERIAL_ALL_RGB);\r
+  glutAddMenuEntry("Ambient R/G/B", M_MATERIAL_AMBIENT_RGB);\r
+  glutAddMenuEntry("Diffuse R/G/B", M_MATERIAL_DIFFUSE_RGB);\r
+  glutAddMenuEntry("Specular R/G/B", M_MATERIAL_SPECULAR_RGB);\r
+  glutAddMenuEntry("All Amb/Diff/Spec/Shine", M_MATERIAL_ALL_ADSS);\r
+  glutAddMenuEntry("Red Amb/Diff/Spec/Shine", M_MATERIAL_RED_ADSS);\r
+  glutAddMenuEntry("Green Amb/Diff/Spec/Shine", M_MATERIAL_GREEN_ADSS);\r
+  glutAddMenuEntry("Blue Amb/Diff/Spec/Shine", M_MATERIAL_BLUE_ADSS);\r
+\r
+  // Construct light menu\r
+  int lightMenu = glutCreateMenu(processLightEvents);\r
+  glutAddMenuEntry("Move Light 1", M_LIGHT_MOVE_LIGHT_1);\r
+  glutAddMenuEntry("R/G/B/All Light 1", M_LIGHT_RGBALL_LIGHT_1);\r
+  glutAddMenuEntry("Move Light 2", M_LIGHT_MOVE_LIGHT_2);\r
+  glutAddMenuEntry("R/G/B/All Light 2", M_LIGHT_RGBALL_LIGHT_2);\r
+\r
+  // Construct object menu\r
+  int objectMenu = makeSubmenuFromArray( objectMenuEntries, NMESH, processObjectEvents );\r
+\r
+  // Construct texture / ground texture menus\r
+  int textureMenu = makeSubmenuFromArray( textureMenuEntries, NTEXTURE, processTextureEvents );\r
+  int gTextureMenu = makeSubmenuFromArray( textureMenuEntries, NTEXTURE, processGTextureEvents );\r
+\r
+  // Construct main menu\r
+  glutCreateMenu(processMainEvents);\r
+  //glutAddMenuEntry("Rotate/Move Camera", M_ROTATE_MOVE_CAMERA);\r
+  //glutAddSubMenu("Add object", objectMenu);\r
+  //glutAddMenuEntry("Position/Scale", M_POSITION_SCALE);\r
+  //glutAddMenuEntry("Rotation/Texture Scale", M_ROTATION_TEXTURE_SCALE);\r
+  //glutAddSubMenu("Material", materialMenu);\r
+  //glutAddSubMenu("Texture", textureMenu);\r
+  //glutAddSubMenu("Ground texture", gTextureMenu);\r
+  //glutAddSubMenu("Lights", lightMenu);\r
+  glutAddMenuEntry("Exit", M_EXIT);\r
+\r
+  // Bind to right mouse button\r
+  glutAttachMenu(GLUT_RIGHT_BUTTON);\r
 }\r
 \r
-/* ARGSUSED2 */\r
-static void\r
-mouse(int button, int state, int x, int y)\r
-{\r
+/**\r
+ * Called when window is resized\r
+ * @param w New width\r
+ * @param h New height\r
+ */\r
+/*void windowReshape(int w, int h) {\r
+  glViewport(0, 0, (GLsizei) w, (GLsizei) h);\r
+  glMatrixMode(GL_PROJECTION);\r
+  glLoadIdentity();\r
+  if (w <= h) \r
+    glOrtho(near, far, near*(GLfloat)h/(GLfloat)w,\r
+             far*(GLfloat)h/(GLfloat)w, -100, 100);\r
+  else\r
+    glOrtho(near*(GLfloat)w/(GLfloat)h,\r
+             far*(GLfloat)w/(GLfloat)h, near, far, nearClip, farClip);\r
+   glMatrixMode(GL_MODELVIEW);\r
+   glLoadIdentity();\r
+}*/\r
+\r
+/**\r
+ * Called when mouse event occurs\r
+ * @param btn Mouse button\r
+ * @param state State of mouse button\r
+ * @param x Mouse x position\r
+ * @param y Mouse y position\r
+ */\r
+void mouse(int button, int state, int x, int y) {\r
   if (button == GLUT_LEFT_BUTTON) {\r
     if (state == GLUT_DOWN) {\r
       moving = 1;\r
@@ -636,10 +226,46 @@ mouse(int button, int state, int x, int y)
   }\r
 }\r
 \r
-/* ARGSUSED1 */\r
-static void\r
-motion(int x, int y)\r
-{\r
+/**\r
+ * Keybord event handler\r
+ * w/s increase/decrease the z\r
+ * a/d increase/decrease the x\r
+ * q/e increase/decrease the y\r
+ * @param key Key pressed\r
+ * @param x x co-ordinate of mouse\r
+ * @param y y co-ordinate of mouse\r
+ */\r
+void keyboard(unsigned char key, int x, int y) {\r
+  switch(key) {\r
+    case 'w':\r
+      camz = camz - 1;\r
+      break;\r
+    case 'a':\r
+      camx = camx - 1;\r
+      break;\r
+    case 's':\r
+      camz = camz + 1;\r
+      break;\r
+    case 'd':\r
+      camx = camx + 1;\r
+      break;\r
+    case 'q':\r
+      camy = camy + 1;\r
+      break;\r
+    case 'e':\r
+      camy = camy - 1;\r
+      break;\r
+  }\r
+  printf("Camera is now at (%f, %f, %f)\n", camx, camy, camz);\r
+  glutPostRedisplay();\r
+}\r
+\r
+/**\r
+ * Called when motion event occurs\r
+ * @param x Mouse x position\r
+ * @param y Mouse y position\r
+ */\r
+void motion(int x, int y) {\r
   if (moving) {\r
     angle = angle + (x - startx);\r
     angle2 = angle2 + (y - starty);\r
@@ -656,237 +282,141 @@ motion(int x, int y)
   }\r
 }\r
 \r
-/* Advance time varying state when idle callback registered. */\r
-static void\r
-idle(void)\r
-{\r
-  static float time = 0.0;\r
+/**\r
+ * Display function\r
+ */\r
+void display() {\r
+  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);\r
+  glLoadIdentity();\r
+  gluLookAt(\r
+    0.0, 100.0, 100.0,  /* eye is at (x,y,z) */\r
+    0.0, 0.0,  0.0,  /* center is at (x,y,z) */\r
+    0.0, 1.0,  0.0   /* up is in postivie Y direction */\r
+    );\r
+\r
+  glTranslatef(camx, camy, camz);\r
+  \r
+  // **NOTE: Currently this rotation function is all that moves the camera off\r
+  //         the flat surface. Need to integrate function into gluLookAt\r
+  //glRotatef(30.0, 1.0, 0.0, 0.0);\r
 \r
-  time = glutGet(GLUT_ELAPSED_TIME) / 500.0;\r
+  /* Reposition the light source. */\r
+  lightPosition[0] = 12*cos(lightAngle);\r
+  lightPosition[1] = lightHeight;\r
+  lightPosition[2] = 12*sin(lightAngle);\r
+  lightPosition[3] = 0.0;\r
 \r
-  jump = 4.0 * fabs(sin(time)*0.5);\r
-  if (!lightMoving) {\r
-    lightAngle += 0.03;\r
-  }\r
-  glutPostRedisplay();\r
-}\r
+  glPushMatrix();\r
 \r
-enum {\r
-  M_NONE, M_MOTION, M_LIGHT, M_TEXTURE, M_SHADOWS, M_REFLECTION, M_DINOSAUR,\r
-  M_STENCIL_REFLECTION, M_STENCIL_SHADOW, M_OFFSET_SHADOW,\r
-  M_POSITIONAL, M_DIRECTIONAL, M_PERFORMANCE\r
-};\r
-\r
-static void\r
-controlLights(int value)\r
-{\r
-  switch (value) {\r
-  case M_NONE:\r
-    return;\r
-  case M_MOTION:\r
-    animation = 1 - animation;\r
-    if (animation) {\r
-      glutIdleFunc(idle);\r
-    } else {\r
-      glutIdleFunc(NULL);\r
-    }\r
-    break;\r
-  case M_LIGHT:\r
-    lightSwitch = !lightSwitch;\r
-    if (lightSwitch) {\r
-      glEnable(GL_LIGHT0);\r
-    } else {\r
-      glDisable(GL_LIGHT0);\r
-    }\r
-    break;\r
-  case M_TEXTURE:\r
-    useTexture = !useTexture;\r
-    break;\r
-  case M_SHADOWS:\r
-    renderShadow = 1 - renderShadow;\r
-    break;\r
-  case M_REFLECTION:\r
-    renderReflection = 1 - renderReflection;\r
-    break;\r
-  case M_DINOSAUR:\r
-    renderDinosaur = 1 - renderDinosaur;\r
-    break;\r
-  case M_STENCIL_REFLECTION:\r
-    stencilReflection = 1 - stencilReflection;\r
-    break;\r
-  case M_STENCIL_SHADOW:\r
-    stencilShadow = 1 - stencilShadow;\r
-    break;\r
-  case M_OFFSET_SHADOW:\r
-    offsetShadow = 1 - offsetShadow;\r
-    break;\r
-  case M_POSITIONAL:\r
-    directionalLight = 0;\r
-    break;\r
-  case M_DIRECTIONAL:\r
-    directionalLight = 1;\r
-    break;\r
-  case M_PERFORMANCE:\r
-    reportSpeed = 1 - reportSpeed;\r
-    break;\r
-  }\r
-  glutPostRedisplay();\r
-}\r
+    /* Perform scene rotations based on user mouse input. */\r
+    glRotatef(angle, 0.0, 1.0, 0.0);\r
+    //glRotatef(angle2, 1.0, 0.0, 0.0); **NOTE: Only one degree of freedom\r
 \r
-/* When not visible, stop animating.  Restart when visible again. */\r
-static void\r
-visible(int vis)\r
-{\r
-  if (vis == GLUT_VISIBLE) {\r
-    if (animation)\r
-      glutIdleFunc(idle);\r
-  } else {\r
-    if (!animation)\r
-      glutIdleFunc(NULL);\r
-  }\r
-}\r
+    glLightfv(GL_LIGHT0, GL_POSITION, lightPosition);\r
 \r
-/* Press any key to redraw; good when motion stopped and\r
-   performance reporting on. */\r
-/* ARGSUSED */\r
-static void\r
-key(unsigned char c, int x, int y)\r
-{\r
-  if (c == 27) {\r
-    exit(0);  /* IRIS GLism, Escape quits. */\r
-  }\r
-  glutPostRedisplay();\r
-}\r
+    drawFloor();\r
 \r
-/* Press any key to redraw; good when motion stopped and\r
-   performance reporting on. */\r
-/* ARGSUSED */\r
-static void\r
-special(int k, int x, int y)\r
-{\r
-  glutPostRedisplay();\r
-}\r
+    drawLine();\r
+    \r
+    // Draw teapot for a test object\r
+    glPushMatrix();\r
+      glTranslatef(0.0, 1.0, 0.0); // **NOTE: Teapot does not rest on surface\r
+      glColor3f(0.5, 0.5, 0.5);\r
+      glutSolidTeapot(100);\r
+    glPopMatrix();\r
 \r
-static int\r
-supportsOneDotOne(void)\r
-{\r
-  const char *version;\r
-  int major, minor;\r
+    // Draw a white ball over the light source\r
+    glPushMatrix();\r
+      glDisable(GL_LIGHTING);\r
+      glColor3f(1.0, 1.0, 1.0);\r
+      glTranslatef(lightPosition[0], lightPosition[1], lightPosition[2]);\r
+      glutSolidSphere(1.0, 50, 50);\r
+      glEnable(GL_LIGHTING);\r
+    glPopMatrix();\r
+\r
+  glPopMatrix();\r
 \r
-  version = (char *) glGetString(GL_VERSION);\r
-  if (sscanf(version, "%d.%d", &major, &minor) == 2)\r
-    return major >= 1 && minor >= 1;\r
-  return 0;            /* OpenGL version string malformed! */\r
+  glutSwapBuffers();\r
 }\r
 \r
-int\r
-main(int argc, char **argv)\r
-{\r
-  int i;\r
+/**\r
+ * init function; sets initial OpenGL state\r
+ */\r
+void init() {\r
+  glMatrixMode(GL_PROJECTION);\r
+  glLoadIdentity();\r
+\r
+   gluPerspective(\r
+    60.0,  /* field of view in degree */\r
+     1.0,  /* aspect ratio */\r
+    nearClip,  /* Z near */\r
+     farClip   /* Z far */\r
+    );\r
+  \r
+  glMatrixMode(GL_MODELVIEW);\r
+  glLoadIdentity();\r
 \r
-  glutInit(&argc, argv);\r
+  glLightfv(GL_LIGHT0, GL_POSITION, light0_pos);\r
+  glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);\r
+  glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);\r
+  glLightfv(GL_LIGHT0, GL_SPECULAR, specular0);\r
+  glLightModelfv(GL_LIGHT_MODEL_AMBIENT, glightmodel);\r
+  glEnable(GL_LIGHT0);\r
+  glEnable(GL_LIGHTING);\r
+  glEnable(GL_COLOR_MATERIAL);\r
+  glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE );\r
+  glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular0);\r
+  glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission0);\r
 \r
-  for (i=1; i<argc; i++) {\r
-    if (!strcmp("-linear", argv[i])) {\r
-      linearFiltering = 1;\r
-    } else if (!strcmp("-mipmap", argv[i])) {\r
-      useMipmaps = 1;\r
-    } else if (!strcmp("-ext", argv[i])) {\r
-      forceExtension = 1;\r
-    }\r
-  }\r
+  \r
 \r
-  glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_STENCIL | GLUT_MULTISAMPLE);\r
+}\r
 \r
-#if 1\r
-  /* In GLUT 4.0, you'll be able to do this an be sure to\r
-     get 2 bits of stencil if the machine has it for you. */\r
-  glutInitDisplayString("samples stencil>=2 rgb double depth");\r
-#endif\r
+/**\r
+ * Main function\r
+ * @param argc Number of arguments\r
+ * @param argv Array of arguments\r
+ * @return Program exit code\r
+ */\r
+int main(int argc, char **argv) {\r
+  if(argc>1)\r
+    strcpy(dataDir, argv[1]);\r
+  else if(opendir(dirDefault1))\r
+    strcpy(dataDir, dirDefault1);\r
+  else if(opendir(dirDefault2))\r
+    strcpy(dataDir, dirDefault2);\r
+  else fileErr(dirDefault1);\r
+\r
+  for(int i=0; i<NMESH; i++) meshes[i]=NULL;\r
+  for(int i=0; i<NTEXTURE; i++) textures[i]=NULL;\r
 \r
-  glutCreateWindow("Shadowy Leapin' Lizards");\r
+  glutInit(&argc, argv);\r
 \r
-  if (glutGet(GLUT_WINDOW_STENCIL_SIZE) <= 1) {\r
-    printf("dinoshade: Sorry, I need at least 2 bits of stencil.\n");\r
-    exit(1);\r
-  }\r
+  glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);\r
 \r
-  /* Register GLUT callbacks. */\r
-  glutDisplayFunc(redraw);\r
-  glutMouseFunc(mouse);\r
-  glutMotionFunc(motion);\r
-  glutVisibilityFunc(visible);\r
-  glutKeyboardFunc(key);\r
-  glutSpecialFunc(special);\r
-\r
-  glutCreateMenu(controlLights);\r
-\r
-  glutAddMenuEntry("Toggle motion", M_MOTION);\r
-  glutAddMenuEntry("-----------------------", M_NONE);\r
-  glutAddMenuEntry("Toggle light", M_LIGHT);\r
-  glutAddMenuEntry("Toggle texture", M_TEXTURE);\r
-  glutAddMenuEntry("Toggle shadows", M_SHADOWS);\r
-  glutAddMenuEntry("Toggle reflection", M_REFLECTION);\r
-  glutAddMenuEntry("Toggle dinosaur", M_DINOSAUR);\r
-  glutAddMenuEntry("-----------------------", M_NONE);\r
-  glutAddMenuEntry("Toggle reflection stenciling", M_STENCIL_REFLECTION);\r
-  glutAddMenuEntry("Toggle shadow stenciling", M_STENCIL_SHADOW);\r
-  glutAddMenuEntry("Toggle shadow offset", M_OFFSET_SHADOW);\r
-  glutAddMenuEntry("----------------------", M_NONE);\r
-  glutAddMenuEntry("Positional light", M_POSITIONAL);\r
-  glutAddMenuEntry("Directional light", M_DIRECTIONAL);\r
-  glutAddMenuEntry("-----------------------", M_NONE);\r
-  glutAddMenuEntry("Toggle performance", M_PERFORMANCE);\r
-  glutAttachMenu(GLUT_RIGHT_BUTTON);\r
-  makeDinosaur();\r
-\r
-#ifdef GL_VERSION_1_1\r
-  if (supportsOneDotOne() && !forceExtension) {\r
-    polygonOffsetVersion = ONE_DOT_ONE;\r
-    glPolygonOffset(-2.0, -1.0);\r
-  } else\r
-#endif\r
-  {\r
-#ifdef GL_EXT_polygon_offset\r
-  /* check for the polygon offset extension */\r
-  if (glutExtensionSupported("GL_EXT_polygon_offset")) {\r
-    polygonOffsetVersion = EXTENSION;\r
-    glPolygonOffsetEXT(-0.1, -0.002);\r
-  } else\r
-#endif\r
-    {\r
-      polygonOffsetVersion = MISSING;\r
-      printf("\ndinoshine: Missing polygon offset.\n");\r
-      printf("           Expect shadow depth aliasing artifacts.\n\n");\r
-    }\r
-  }\r
+  glutInitWindowSize(500, 500);\r
+  glutCreateWindow("Scene Editor");\r
 \r
+  glShadeModel(GL_SMOOTH); // Enables Smooth Shading\r
+  glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background\r
+  glClearDepth(1.0f); // Depth Buffer Setup\r
+  glEnable(GL_DEPTH_TEST); // Enables Depth Testing\r
+  glDepthFunc(GL_LEQUAL);  // the type\r
   glEnable(GL_CULL_FACE);\r
-  glEnable(GL_DEPTH_TEST);\r
   glEnable(GL_TEXTURE_2D);\r
-  glLineWidth(3.0);\r
+  glLineWidth(1.0);\r
 \r
-  glMatrixMode(GL_PROJECTION);\r
-  gluPerspective( /* field of view in degree */ 40.0,\r
-  /* aspect ratio */ 1.0,\r
-    /* Z near */ 20.0, /* Z far */ 100.0);\r
-  glMatrixMode(GL_MODELVIEW);\r
-  gluLookAt(0.0, 8.0, 60.0,  /* eye is at (0,8,60) */\r
-    0.0, 8.0, 0.0,      /* center is at (0,8,0) */\r
-    0.0, 1.0, 0.);      /* up is in postivie Y direction */\r
-\r
-  glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);\r
-  glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor);\r
-  glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1);\r
-  glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05);\r
-  glEnable(GL_LIGHT0);\r
-  glEnable(GL_LIGHTING);\r
+  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);\r
 \r
-  makeFloorTexture();\r
+  //glutReshapeFunc(windowReshape);\r
+  glutDisplayFunc(display);\r
+  glutMouseFunc(mouse);\r
+  glutKeyboardFunc(keyboard);\r
+  glutMotionFunc(motion);\r
 \r
-  /* Setup floor plane for projected shadow calculations. */\r
-  findPlane(floorPlane, floorVertices[1], floorVertices[2], floorVertices[3]);\r
+  makeMenu();\r
+\r
+  init();\r
 \r
   glutMainLoop();\r
-  return 0;             /* ANSI C requires main to return int. */\r
-}
\ No newline at end of file
+}\r

UCC git Repository :: git.ucc.asn.au