From 2b29d6b81b8e20fc6c903fe839abbb833c5f18bd Mon Sep 17 00:00:00 2001
From: Kyle K <kylek389@gmail.com>
Date: Thu, 7 Jul 2011 23:14:03 -0500
Subject: create a gldraw.[ch] for models, also introduce few functions

---
 sdl/Makefile   |   9 +-
 sdl/gldraw.c   | 516 +++++++++++++++++++++++++++++++++++++++++++++++++++
 sdl/gldraw.h   |  14 ++
 sdl/gltools.c  | 574 ++++++++-------------------------------------------------
 sdl/gltools.h  |  27 ++-
 sdl/platform.c |   6 +-
 sdl/pyramid.c  |  10 +-
 7 files changed, 638 insertions(+), 518 deletions(-)
 create mode 100644 sdl/gldraw.c
 create mode 100644 sdl/gldraw.h

diff --git a/sdl/Makefile b/sdl/Makefile
index a2309bb..e7dfefd 100644
--- a/sdl/Makefile
+++ b/sdl/Makefile
@@ -1,7 +1,7 @@
 BIN = pyramid
-SRC = pyramid.c math3d.c gltools.c glframe.c shader.c platform.c window.c
+SRC = pyramid.c math3d.c gltools.c glframe.c shader.c platform.c window.c gldraw.c
 CC = gcc
-CFLAGS = -Wall -std=c99
+CFLAGS = -Wall -std=gnu99
 DBGFLAGS = -g -O0
 ifdef DEBUG
     CFLAGS += $(DBGFLAGS)
@@ -26,7 +26,7 @@ $(OBJ_DIR)/pyramid.o: $(OBJ_DIR)/%.o: %.c math3d.h gltools.h glframe.h platform.
 $(OBJ_DIR)/math3d.o: $(OBJ_DIR)/%.o: %.c %.h
 	$(CC) -c $(CFLAGS) $< -o $@
 
-$(OBJ_DIR)/gltools.o: $(OBJ_DIR)/%.o: %.c %.h math3d.h
+$(OBJ_DIR)/gltools.o: $(OBJ_DIR)/%.o: %.c %.h
 	$(CC) -c $(CFLAGS) $< -o $@
 
 $(OBJ_DIR)/glframe.o: $(OBJ_DIR)/%.o: %.c %.h math3d.h
@@ -41,6 +41,9 @@ $(OBJ_DIR)/platform.o: $(OBJ_DIR)/%.o: %.c %.h
 $(OBJ_DIR)/window.o: $(OBJ_DIR)/%.o: %.c %.h
 	$(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $< -o $@
 
+$(OBJ_DIR)/gldraw.o: $(OBJ_DIR)/%.o: %.c %.h math3d.h
+	$(CC) -c $(CFLAGS) $< -o $@
+
 $(OBJ_DIR):
 	mkdir -p $(OBJ_DIR)
 
diff --git a/sdl/gldraw.c b/sdl/gldraw.c
new file mode 100644
index 0000000..67f317b
--- /dev/null
+++ b/sdl/gldraw.c
@@ -0,0 +1,516 @@
+/* draw.c
+ *
+ * Draw
+ *
+ *
+ */
+
+#include <GL/glew.h>
+#include <GL/freeglut.h>
+#include <math.h>
+#include "math3d.h"
+#include "gldraw.h"
+
+void glDrawSnowman(void)
+{
+    GLUquadricObj *pObj; /* quadric object */
+
+    /* main body */
+    glPushMatrix();
+        pObj = gluNewQuadric();
+        gluQuadricNormals(pObj, GLU_SMOOTH);
+
+        glPushMatrix();
+            glColor3f(1.0f, 1.0f, 1.0f);
+            gluSphere(pObj, .40f, 26, 13); /* bottom */
+
+            /* mid section */
+            glTranslatef(0.0f, .550f, 0.0f);
+            gluSphere(pObj, .3f, 26, 13);
+        
+            /* head */
+            glTranslatef(0.0f, 0.45f, 0.0f);
+            gluSphere(pObj, 0.24f, 26, 13);
+        
+            /* eyes */
+            glColor3f(0.0f, 0.0f, 0.0f);
+            glTranslatef(0.1f, 0.1f, 0.21f);
+            gluSphere(pObj, 0.02f, 26, 13);
+        
+            glTranslatef(-0.2f, 0.0f, 0.0f);
+            gluSphere(pObj, 0.02f, 26, 13);
+        
+            /* nose */
+            glColor3f(1.0f, 0.3f, 0.3f);
+            glTranslatef(0.1f, -0.12f, 0.0f);
+            gluCylinder(pObj, 0.04f, 0.0f, 0.3f, 26, 13);
+        glPopMatrix();
+        
+        /* hat */
+        glPushMatrix();
+            glColor3f(0.0f, 0.0f, 0.0f);
+            glTranslatef(0.0f, 1.17f, 0.0f);
+            glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
+            gluCylinder(pObj, 0.17f, 0.17f, 0.4f, 26, 13);
+            
+            /* hat brim */
+            glDisable(GL_CULL_FACE);
+            gluDisk(pObj, 0.17f, 0.28f, 26, 13);
+            glEnable(GL_CULL_FACE);
+            
+            glTranslatef(0.0f, 0.0f, 0.40f);
+            gluDisk(pObj, 0.0f, 0.17f, 26, 13);
+        glPopMatrix();
+    glPopMatrix();
+
+    /* delete the quadric */
+    gluDeleteQuadric(pObj);
+}
+
+/* this screws up the rendering, possibly becasue it's glut? */
+void glDrawFigures(void)
+{
+    glDisable(GL_TEXTURE_2D);
+    glDisable(GL_LIGHTING);
+    glPushMatrix();
+        /* scale the figures */
+        glScalef(0.02f, 0.02f, 0.02f);
+
+        /* draw red cube */
+        glColor3f(1.0f, 0.0f, 0.0f);
+        glPushMatrix();
+        glutSolidCube(48.0f);
+        glPopMatrix();
+
+        /* draw green sphere */
+        glColor3f(0.0f, 1.0f, 0.0f);
+        glPushMatrix();
+        glTranslatef(-60.0f, 0.0f, 0.0f);
+        glutSolidSphere(25.0f, 50, 50);
+        glPopMatrix();
+
+        /* draw magenta torus */
+        glColor3f(1.0f, 0.0f, 1.0f);
+        glPushMatrix();
+        glTranslatef(0.0f, 0.0f, 60.0f);
+        glutSolidTorus(8.0f, 16.0f, 50, 50);
+        glPopMatrix();
+
+        /* draw yellow cone */
+        glColor3f(1.0f, 1.0f, 0.0f);
+        glPushMatrix();
+        glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
+        glTranslatef(60.0f, 0.0f, -24.0f);
+        glutSolidCone(25.0f, 50.0f, 50, 50);
+        glPopMatrix();
+
+        /* draw cyan teapot */
+        glColor3f(0.0f, 1.0f, 1.0f);
+        glPushMatrix();
+        glTranslatef(0.0f, 0.0f, -60.0f);
+        glutSolidTeapot(25.0f);
+        glPopMatrix();
+    glPopMatrix();
+    glEnable(GL_LIGHTING);
+    glEnable(GL_TEXTURE_2D);
+}
+
+void glDrawTriangle(void)
+{
+    M3DVector3f vNormal;
+    M3DVector3f vCorners[5] = {
+        { 0.0f, 0.6f, 0.0f },       /* top           0 */
+        { -0.5f, -0.2f, -.50f },    /* back left     1 */
+        { 0.5f, -0.2f, -0.50f },    /* back right    2 */
+        { 0.5f, -0.2f, 0.5f },      /* front right   3 */
+        { -0.5f, -0.2f, 0.5f }      /* front left    4 */
+    };
+
+    glBegin(GL_TRIANGLES);
+        /* bottom section - two triangles */
+        glNormal3f(0.0f, -1.0f, 0.0f);
+
+        /* map texture to geometry */
+        glTexCoord2f(1.0f, 1.0f);
+        glVertex3fv(vCorners[2]);
+        glTexCoord2f(0.0f, 1.0f);
+        glVertex3fv(vCorners[4]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[1]);
+        glTexCoord2f(1.0f, 1.0f);
+        glVertex3fv(vCorners[2]);
+        glTexCoord2f(1.0f, 0.0f);
+        glVertex3fv(vCorners[3]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[4]);
+        
+        /* front face */
+        m3dFindNormalf(vNormal, vCorners[0], vCorners[4], vCorners[3]);
+        glNormal3fv(vNormal);
+        glTexCoord2f(0.5f, 1.0f);
+        glVertex3fv(vCorners[0]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[4]);
+        glTexCoord2f(1.0f, 0.0f);
+        glVertex3fv(vCorners[3]);
+        
+        /* left face */
+        m3dFindNormalf(vNormal, vCorners[0], vCorners[1], vCorners[4]);
+        glNormal3fv(vNormal);
+        glTexCoord2f(0.5f, 1.0f);
+        glVertex3fv(vCorners[0]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[1]);
+        glTexCoord2f(1.0f, 0.0f);
+        glVertex3fv(vCorners[4]);
+
+        /* back face */
+        m3dFindNormalf(vNormal, vCorners[0], vCorners[2], vCorners[1]);
+        glNormal3fv(vNormal);
+        glTexCoord2f(0.5f, 1.0f);
+        glVertex3fv(vCorners[0]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[2]);
+        glTexCoord2f(1.0f, 0.0f);
+        glVertex3fv(vCorners[1]);
+        
+        /* right face */
+        m3dFindNormalf(vNormal, vCorners[0], vCorners[3], vCorners[2]);
+        glNormal3fv(vNormal);
+        glTexCoord2f(0.5f, 1.0f);
+        glVertex3fv(vCorners[0]);
+        glTexCoord2f(0.0f, 0.0f);
+        glVertex3fv(vCorners[3]);
+        glTexCoord2f(1.0f, 0.0f);
+        glVertex3fv(vCorners[2]);
+    glEnd();
+}
+
+void glDrawGround(void)
+{
+    GLfloat fExtent = 20.0f;
+    GLfloat fStep = 0.5f;
+    GLfloat y = -0.4f;
+    GLfloat iLine;
+
+    glLineWidth(1.0f);
+    glBegin(GL_LINES);
+    for (iLine = -fExtent; iLine <= fExtent; iLine += fStep)
+    {
+        glVertex3f(iLine, y, fExtent);
+        glVertex3f(iLine, y, -fExtent);
+        glVertex3f(fExtent, y, iLine);
+        glVertex3f(-fExtent, y, iLine);
+    }
+    glEnd();
+}
+
+void glDrawUnitAxes(void)
+{
+    GLUquadricObj *pObj; /* temporary, used for quadrics */
+
+    /* measurements */
+    float fAxisRadius = 0.025f;
+    float fAxisHeight = 1.0f;
+    float fArrowRadius = 0.06f;
+    float fArrowHeight = 0.1f;
+
+    /* setup the quadric object */
+    pObj = gluNewQuadric();
+    gluQuadricDrawStyle(pObj, GLU_FILL);
+    gluQuadricNormals(pObj, GLU_SMOOTH);
+    gluQuadricOrientation(pObj, GLU_OUTSIDE);
+    gluQuadricTexture(pObj, GLU_FALSE);
+
+    /* draw the blue z axis first with arrowed head */
+    glColor3f(0.0f, 0.0f, 1.0f);
+    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
+    glPushMatrix();
+    glTranslatef(0.0f, 0.0f, 1.0f);
+    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
+    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
+    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
+    glPopMatrix();
+
+    /* draw the red x axis 2nd with arrowed head */
+    glColor3f(1.0f, 0.0f, 0.0f);
+    glPushMatrix();
+    glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
+    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
+    glPushMatrix();
+    glTranslatef(0.0f, 0.0f, 1.0f);
+    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
+    glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
+    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
+    glPopMatrix();
+    glPopMatrix();
+
+    /* draw the green y axis 3rd with arrowed head */
+    glColor3f(0.0f, 1.0f, 0.0f);
+    glPushMatrix();
+    glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
+    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
+    glPushMatrix();
+    glTranslatef(0.0f, 0.0f, 1.0f);
+    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
+    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
+    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
+    glPopMatrix();
+    glPopMatrix();
+
+    /* white sphere at origin */
+    glColor3f(1.0f, 1.0f, 1.0f);
+    gluSphere(pObj, 0.05f, 15, 15);
+
+    /* delete the quadric */
+    gluDeleteQuadric(pObj);
+}
+
+/* draw a torus (doughnut), using the current 1d texture for light shading */
+void glDrawTorus(GLfloat majorRadius, GLfloat minorRadius, GLint numMajor, 
+                  GLint numMinor)
+{
+    M3DVector3f vNormal;
+    double majorStep = 2.0f * M3D_PI / numMajor;
+    double minorStep = 2.0f * M3D_PI / numMinor;
+    int i, j;
+
+    for (i = 0; i < numMajor; ++i)
+    {
+        double a0 = i * majorStep;
+        double a1 = a0 + majorStep;
+        GLfloat x0 = (GLfloat) cos(a0);
+        GLfloat y0 = (GLfloat) sin(a0);
+        GLfloat x1 = (GLfloat) cos(a1);
+        GLfloat y1 = (GLfloat) sin(a1);
+
+        glBegin(GL_TRIANGLE_STRIP);
+        for (j = 0; j <= numMinor; ++j)
+        {
+            double b = j * minorStep;
+            GLfloat c = (GLfloat) cos(b);
+            GLfloat r = minorRadius * c + majorRadius;
+            GLfloat z = minorRadius * (GLfloat) sin(b);
+
+            glTexCoord2f((float) (i) / (float) (numMajor), (float) (j) \
+                         / (float) (numMinor));
+            vNormal[0] = x0 * c;
+            vNormal[1] = y0 * c;
+            vNormal[2] = z / minorRadius;
+            m3dNormalizeVectorf(vNormal);
+            glNormal3fv(vNormal);
+            glVertex3f(x0 * r, y0 * r, z);
+
+            glTexCoord2f((float) (i + 1) / (float) (numMajor), (float) (j) \
+                         / (float) (numMinor));
+            vNormal[0] = x1 * c;
+            vNormal[1] = y1 * c;
+            vNormal[2] = z / minorRadius;
+            m3dNormalizeVectorf(vNormal);
+            glNormal3fv(vNormal);
+            glVertex3f(x1 * r, y1 * r, z);
+        }
+        glEnd();
+    }
+}
+
+void glDrawJet(void)
+{
+    M3DVector3f vNormal;
+
+    /* nose cone, points straight down, set material color */
+    /* follow few lines use manual approach */
+    glBegin(GL_TRIANGLES);
+    glNormal3f(0.0f, -1.0f, 0.0f);
+    glNormal3f(0.0f, -1.0f, 0.0f);
+    glVertex3f(0.0f, 0.0f, 60.0f);
+    glVertex3f(-15.0f, 0.0f, 30.0f);
+    glVertex3f(15.0f, 0.0f, 30.0f);
+
+    /* verticies for this panel */
+    {
+    M3DVector3f vPoints[3] = { { 15.0f, 0.0f, 30.0f },
+                               { 0.0f, 15.0f, 30.0f },
+                               { 0.0f, 0.0f, 60.0f  } };
+
+    /* calculate the normal for the plane */
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 0.0f, 60.0f   },
+                               { 0.0f, 15.0f, 30.0f  },
+                               { -15.0f, 0.0f, 30.0f } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    /* body of the plane */
+    {
+    M3DVector3f vPoints[3] = { { -15.0f, 0.0f, 30.0f },
+                               { 0.0f, 15.0f, 30.0f  },
+                               { 0.0f, 0.0f, -56.0f  }};
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 0.0f, -56.0f },
+                               { 0.0f, 15.0f, 30.0f },
+                               { 15.0f, 0.0f, 30.0f } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    glNormal3f(0.0f, -1.0f, 0.0f);
+    glVertex3f(15.0f, 0.0f, 30.0f);
+    glVertex3f(-15.0f, 0.0f, 30.0f);
+    glVertex3f(0.0f, 0.0f, -56.0f);
+
+    /* left wing, large triangle for bottom of wing */
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 2.0f, 27.0f   },
+                               { -60.0f, 2.0f, -8.0f },
+                               { 60.0f, 2.0f, -8.0f  } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 60.0f, 2.0f, -8.0f },
+                               { 0.0f, 7.0f, -8.0f  },
+                               { 0.0f, 2.0f, 27.0f  } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 60.0f, 2.0f, -8.0f  },
+                               { -60.0f, 2.0f, -8.0f },
+                               { 0.0f, 7.0f, -8.0f   } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 2.0f, 27.0f   },
+                               { 0.0f, 7.0f, -8.0f   },
+                               { -60.0f, 2.0f, -8.0f } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    /* tail section */
+    /* bottom of back fin */
+    glNormal3f(0.0f, -1.0f, 0.0f);
+    glVertex3f(-30.0f, -0.50f, -57.0f);
+    glVertex3f(30.0f, -0.50f, -57.0f);
+    glVertex3f(0.0f, -0.50f, -40.0f);
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, -0.5f, -40.0f  },
+                               { 30.0f, -0.5f, -57.0f },
+                               { 0.0f, 4.0f, -57.0f   } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 4.0f, -57.0f    },
+                               { -30.0f, -0.5f, -57.0f },
+                               { 0.0f, -0.5f, -40.0f   } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 30.0f, -0.5f, -57.0f  },
+                               { -30.0f, -0.5f, -57.0f },
+                               { 0.0f, 4.0f, -57.0f    } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 0.5f, -40.0f  },
+                               { 3.0f, 0.5f, -57.0f  },
+                               { 0.0f, 25.0f, -65.0f } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 0.0f, 25.0f, -65.0f },
+                               { -3.0f, 0.5f, -57.0f },
+                               { 0.0f, 0.5f, -40.0f  } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    {
+    M3DVector3f vPoints[3] = { { 3.0f, 0.5f, -57.0f  },
+                               { -3.0f, 0.5f, -57.0f },
+                               { 0.0f, 25.0f, -65.0f } };
+
+    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
+    glNormal3fv(vNormal);
+    glVertex3fv(vPoints[0]);
+    glVertex3fv(vPoints[1]);
+    glVertex3fv(vPoints[2]);
+    }
+
+    glEnd();
+}
+
diff --git a/sdl/gldraw.h b/sdl/gldraw.h
new file mode 100644
index 0000000..4f64236
--- /dev/null
+++ b/sdl/gldraw.h
@@ -0,0 +1,14 @@
+#ifndef _GLDRAW_H_
+#define _GLDRAW_H_
+
+/* function prototypes */
+void glDrawSnowman(void);
+void glDrawFigures(void);
+void glDrawTriangle(void);
+void glDrawGround(void);
+void glDrawUnitAxes(void);
+void glDrawTorus(GLfloat, GLfloat, GLint, GLint);
+void glDrawJet(void);
+
+#endif
+
diff --git a/sdl/gltools.c b/sdl/gltools.c
index 2c2c0c4..afb0777 100644
--- a/sdl/gltools.c
+++ b/sdl/gltools.c
@@ -2,18 +2,74 @@
  *
  * OpenGL Tools
  *
- * notes: some function modify current color, just FYI
  *
  */
 
 #include <GL/glew.h>
-#include <GL/freeglut.h>
-#include <math.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "math3d.h"
+#include <string.h>
 #include "gltools.h"
 
+void gltListExtensions(void)
+{
+    const GLubyte *ext_str;
+    char *ext_str_copy;
+
+    ext_str = glGetString(GL_EXTENSIONS);
+    if (!ext_str)
+        return;
+
+    ext_str_copy = (char *) malloc(strlen((char *) ext_str) + 1);
+    if (!ext_str_copy)
+    {
+        fprintf(stderr, "gltListExtensions failed, %s:%d\n", __FILE__, __LINE__);
+        perror("malloc");
+        exit(-1);
+    }
+
+    strcpy(ext_str_copy, (char *) ext_str);
+
+    char *tok;
+    while ((tok = strsep(&ext_str_copy, " ")))
+        printf("%s\n", tok);
+
+    if (ext_str_copy)
+        free(ext_str_copy);
+}
+
+void gltOpenGLInfo(void)
+{
+    const GLubyte *str;
+
+    str = glGetString(GL_VENDOR);
+    fprintf(stdout, "OpenGL vendor: %s\n", str ? (char *) str : "unknown");
+    str = glGetString(GL_RENDERER);
+    fprintf(stdout, "OpenGL renderer: %s\n", str ? (char *) str : "unknown");
+    str = glGetString(GL_VERSION);
+    fprintf(stdout, "OpenGL version: %s\n", str ? (char *) str : "unknown");
+    str = glGetString(GL_SHADING_LANGUAGE_VERSION);
+    fprintf(stdout, "GLSL version: %s\n", str ? (char *) str : "unknown");
+}
+
+GLboolean gltQueryExtension(const char *extName)
+{
+    char *p = (char *) glGetString(GL_EXTENSIONS);
+    char *end = p + strlen(p);
+
+    while (p < end)
+    {
+        int n = strcspn(p, " ");
+
+        if ((strlen(extName) == n) && (strncmp(extName, p, n) == 0))
+            return GL_TRUE;
+
+        p += (n + 1);
+    }
+
+    return GL_FALSE;
+}
+
 GLint gltWriteTGA(const char *szFileName)
 {
     FILE *pFile;              /* file pointer */
@@ -171,506 +227,26 @@ GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight,
     return pBits;
 }
 
-void gltDrawSnowman(void)
-{
-    GLUquadricObj *pObj; /* quadric object */
-
-    /* main body */
-    glPushMatrix();
-        pObj = gluNewQuadric();
-        gluQuadricNormals(pObj, GLU_SMOOTH);
-
-        glPushMatrix();
-            glColor3f(1.0f, 1.0f, 1.0f);
-            gluSphere(pObj, .40f, 26, 13); /* bottom */
-
-            /* mid section */
-            glTranslatef(0.0f, .550f, 0.0f);
-            gluSphere(pObj, .3f, 26, 13);
-        
-            /* head */
-            glTranslatef(0.0f, 0.45f, 0.0f);
-            gluSphere(pObj, 0.24f, 26, 13);
-        
-            /* eyes */
-            glColor3f(0.0f, 0.0f, 0.0f);
-            glTranslatef(0.1f, 0.1f, 0.21f);
-            gluSphere(pObj, 0.02f, 26, 13);
-        
-            glTranslatef(-0.2f, 0.0f, 0.0f);
-            gluSphere(pObj, 0.02f, 26, 13);
-        
-            /* nose */
-            glColor3f(1.0f, 0.3f, 0.3f);
-            glTranslatef(0.1f, -0.12f, 0.0f);
-            gluCylinder(pObj, 0.04f, 0.0f, 0.3f, 26, 13);
-        glPopMatrix();
-        
-        /* hat */
-        glPushMatrix();
-            glColor3f(0.0f, 0.0f, 0.0f);
-            glTranslatef(0.0f, 1.17f, 0.0f);
-            glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
-            gluCylinder(pObj, 0.17f, 0.17f, 0.4f, 26, 13);
-            
-            /* hat brim */
-            glDisable(GL_CULL_FACE);
-            gluDisk(pObj, 0.17f, 0.28f, 26, 13);
-            glEnable(GL_CULL_FACE);
-            
-            glTranslatef(0.0f, 0.0f, 0.40f);
-            gluDisk(pObj, 0.0f, 0.17f, 26, 13);
-        glPopMatrix();
-    glPopMatrix();
-
-    /* delete the quadric */
-    gluDeleteQuadric(pObj);
-}
-
-/* this screws up the rendering, possibly becasue it's glut? */
-void gltDrawFigures(void)
-{
-    glDisable(GL_TEXTURE_2D);
-    glDisable(GL_LIGHTING);
-    glPushMatrix();
-        /* scale the figures */
-        glScalef(0.02f, 0.02f, 0.02f);
-
-        /* draw red cube */
-        glColor3f(1.0f, 0.0f, 0.0f);
-        glPushMatrix();
-        glutSolidCube(48.0f);
-        glPopMatrix();
-
-        /* draw green sphere */
-        glColor3f(0.0f, 1.0f, 0.0f);
-        glPushMatrix();
-        glTranslatef(-60.0f, 0.0f, 0.0f);
-        glutSolidSphere(25.0f, 50, 50);
-        glPopMatrix();
-
-        /* draw magenta torus */
-        glColor3f(1.0f, 0.0f, 1.0f);
-        glPushMatrix();
-        glTranslatef(0.0f, 0.0f, 60.0f);
-        glutSolidTorus(8.0f, 16.0f, 50, 50);
-        glPopMatrix();
-
-        /* draw yellow cone */
-        glColor3f(1.0f, 1.0f, 0.0f);
-        glPushMatrix();
-        glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
-        glTranslatef(60.0f, 0.0f, -24.0f);
-        glutSolidCone(25.0f, 50.0f, 50, 50);
-        glPopMatrix();
-
-        /* draw cyan teapot */
-        glColor3f(0.0f, 1.0f, 1.0f);
-        glPushMatrix();
-        glTranslatef(0.0f, 0.0f, -60.0f);
-        glutSolidTeapot(25.0f);
-        glPopMatrix();
-    glPopMatrix();
-    glEnable(GL_LIGHTING);
-    glEnable(GL_TEXTURE_2D);
-}
-
-void gltDrawTriangle(void)
-{
-    M3DVector3f vNormal;
-    M3DVector3f vCorners[5] = {
-        { 0.0f, 0.6f, 0.0f },       /* top           0 */
-        { -0.5f, -0.2f, -.50f },    /* back left     1 */
-        { 0.5f, -0.2f, -0.50f },    /* back right    2 */
-        { 0.5f, -0.2f, 0.5f },      /* front right   3 */
-        { -0.5f, -0.2f, 0.5f }      /* front left    4 */
-    };
-
-    glBegin(GL_TRIANGLES);
-        /* bottom section - two triangles */
-        glNormal3f(0.0f, -1.0f, 0.0f);
-
-        /* map texture to geometry */
-        glTexCoord2f(1.0f, 1.0f);
-        glVertex3fv(vCorners[2]);
-        glTexCoord2f(0.0f, 1.0f);
-        glVertex3fv(vCorners[4]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[1]);
-        glTexCoord2f(1.0f, 1.0f);
-        glVertex3fv(vCorners[2]);
-        glTexCoord2f(1.0f, 0.0f);
-        glVertex3fv(vCorners[3]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[4]);
-        
-        /* front face */
-        m3dFindNormalf(vNormal, vCorners[0], vCorners[4], vCorners[3]);
-        glNormal3fv(vNormal);
-        glTexCoord2f(0.5f, 1.0f);
-        glVertex3fv(vCorners[0]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[4]);
-        glTexCoord2f(1.0f, 0.0f);
-        glVertex3fv(vCorners[3]);
-        
-        /* left face */
-        m3dFindNormalf(vNormal, vCorners[0], vCorners[1], vCorners[4]);
-        glNormal3fv(vNormal);
-        glTexCoord2f(0.5f, 1.0f);
-        glVertex3fv(vCorners[0]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[1]);
-        glTexCoord2f(1.0f, 0.0f);
-        glVertex3fv(vCorners[4]);
-
-        /* back face */
-        m3dFindNormalf(vNormal, vCorners[0], vCorners[2], vCorners[1]);
-        glNormal3fv(vNormal);
-        glTexCoord2f(0.5f, 1.0f);
-        glVertex3fv(vCorners[0]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[2]);
-        glTexCoord2f(1.0f, 0.0f);
-        glVertex3fv(vCorners[1]);
-        
-        /* right face */
-        m3dFindNormalf(vNormal, vCorners[0], vCorners[3], vCorners[2]);
-        glNormal3fv(vNormal);
-        glTexCoord2f(0.5f, 1.0f);
-        glVertex3fv(vCorners[0]);
-        glTexCoord2f(0.0f, 0.0f);
-        glVertex3fv(vCorners[3]);
-        glTexCoord2f(1.0f, 0.0f);
-        glVertex3fv(vCorners[2]);
-    glEnd();
-}
-
-void gltDrawGround(void)
-{
-    GLfloat fExtent = 20.0f;
-    GLfloat fStep = 0.5f;
-    GLfloat y = -0.4f;
-    GLfloat iLine;
-
-    glLineWidth(1.0f);
-    glBegin(GL_LINES);
-    for (iLine = -fExtent; iLine <= fExtent; iLine += fStep)
-    {
-        glVertex3f(iLine, y, fExtent);
-        glVertex3f(iLine, y, -fExtent);
-        glVertex3f(fExtent, y, iLine);
-        glVertex3f(-fExtent, y, iLine);
-    }
-    glEnd();
-}
-
-void gltDrawUnitAxes(void)
-{
-    GLUquadricObj *pObj; /* temporary, used for quadrics */
-
-    /* measurements */
-    float fAxisRadius = 0.025f;
-    float fAxisHeight = 1.0f;
-    float fArrowRadius = 0.06f;
-    float fArrowHeight = 0.1f;
-
-    /* setup the quadric object */
-    pObj = gluNewQuadric();
-    gluQuadricDrawStyle(pObj, GLU_FILL);
-    gluQuadricNormals(pObj, GLU_SMOOTH);
-    gluQuadricOrientation(pObj, GLU_OUTSIDE);
-    gluQuadricTexture(pObj, GLU_FALSE);
-
-    /* draw the blue z axis first with arrowed head */
-    glColor3f(0.0f, 0.0f, 1.0f);
-    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
-    glPushMatrix();
-    glTranslatef(0.0f, 0.0f, 1.0f);
-    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
-    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
-    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
-    glPopMatrix();
-
-    /* draw the red x axis 2nd with arrowed head */
-    glColor3f(1.0f, 0.0f, 0.0f);
-    glPushMatrix();
-    glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
-    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
-    glPushMatrix();
-    glTranslatef(0.0f, 0.0f, 1.0f);
-    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
-    glRotatef(180.0f, 0.0f, 1.0f, 0.0f);
-    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
-    glPopMatrix();
-    glPopMatrix();
-
-    /* draw the green y axis 3rd with arrowed head */
-    glColor3f(0.0f, 1.0f, 0.0f);
-    glPushMatrix();
-    glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
-    gluCylinder(pObj, fAxisRadius, fAxisRadius, fAxisHeight, 10, 1);
-    glPushMatrix();
-    glTranslatef(0.0f, 0.0f, 1.0f);
-    gluCylinder(pObj, fArrowRadius, 0.0f, fArrowHeight, 10, 1);
-    glRotatef(180.0f, 1.0f, 0.0f, 0.0f);
-    gluDisk(pObj, fAxisRadius, fArrowRadius, 10, 1);
-    glPopMatrix();
-    glPopMatrix();
-
-    /* white sphere at origin */
-    glColor3f(1.0f, 1.0f, 1.0f);
-    gluSphere(pObj, 0.05f, 15, 15);
-
-    /* delete the quadric */
-    gluDeleteQuadric(pObj);
-}
-
-/* draw a torus (doughnut), using the current 1d texture for light shading */
-void gltDrawTorus(GLfloat majorRadius, GLfloat minorRadius, GLint numMajor, 
-                  GLint numMinor)
-{
-    M3DVector3f vNormal;
-    double majorStep = 2.0f * M3D_PI / numMajor;
-    double minorStep = 2.0f * M3D_PI / numMinor;
-    int i, j;
-
-    for (i = 0; i < numMajor; ++i)
-    {
-        double a0 = i * majorStep;
-        double a1 = a0 + majorStep;
-        GLfloat x0 = (GLfloat) cos(a0);
-        GLfloat y0 = (GLfloat) sin(a0);
-        GLfloat x1 = (GLfloat) cos(a1);
-        GLfloat y1 = (GLfloat) sin(a1);
-
-        glBegin(GL_TRIANGLE_STRIP);
-        for (j = 0; j <= numMinor; ++j)
-        {
-            double b = j * minorStep;
-            GLfloat c = (GLfloat) cos(b);
-            GLfloat r = minorRadius * c + majorRadius;
-            GLfloat z = minorRadius * (GLfloat) sin(b);
-
-            glTexCoord2f((float) (i) / (float) (numMajor), (float) (j) \
-                         / (float) (numMinor));
-            vNormal[0] = x0 * c;
-            vNormal[1] = y0 * c;
-            vNormal[2] = z / minorRadius;
-            m3dNormalizeVectorf(vNormal);
-            glNormal3fv(vNormal);
-            glVertex3f(x0 * r, y0 * r, z);
-
-            glTexCoord2f((float) (i + 1) / (float) (numMajor), (float) (j) \
-                         / (float) (numMinor));
-            vNormal[0] = x1 * c;
-            vNormal[1] = y1 * c;
-            vNormal[2] = z / minorRadius;
-            m3dNormalizeVectorf(vNormal);
-            glNormal3fv(vNormal);
-            glVertex3f(x1 * r, y1 * r, z);
-        }
-        glEnd();
-    }
-}
-
-void gltDrawJet(void)
+#ifdef _WIN32
+/* this function is insane in a good way */
+char *strsep(char **stringp, const char *delim)
 {
-    M3DVector3f vNormal;
-
-    /* nose cone, points straight down, set material color */
-    /* follow few lines use manual approach */
-    glBegin(GL_TRIANGLES);
-    glNormal3f(0.0f, -1.0f, 0.0f);
-    glNormal3f(0.0f, -1.0f, 0.0f);
-    glVertex3f(0.0f, 0.0f, 60.0f);
-    glVertex3f(-15.0f, 0.0f, 30.0f);
-    glVertex3f(15.0f, 0.0f, 30.0f);
-
-    /* verticies for this panel */
-    {
-    M3DVector3f vPoints[3] = { { 15.0f, 0.0f, 30.0f },
-                               { 0.0f, 15.0f, 30.0f },
-                               { 0.0f, 0.0f, 60.0f  } };
-
-    /* calculate the normal for the plane */
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 0.0f, 60.0f   },
-                               { 0.0f, 15.0f, 30.0f  },
-                               { -15.0f, 0.0f, 30.0f } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    /* body of the plane */
-    {
-    M3DVector3f vPoints[3] = { { -15.0f, 0.0f, 30.0f },
-                               { 0.0f, 15.0f, 30.0f  },
-                               { 0.0f, 0.0f, -56.0f  }};
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
+    char *result;
 
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 0.0f, -56.0f },
-                               { 0.0f, 15.0f, 30.0f },
-                               { 15.0f, 0.0f, 30.0f } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    glNormal3f(0.0f, -1.0f, 0.0f);
-    glVertex3f(15.0f, 0.0f, 30.0f);
-    glVertex3f(-15.0f, 0.0f, 30.0f);
-    glVertex3f(0.0f, 0.0f, -56.0f);
-
-    /* left wing, large triangle for bottom of wing */
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 2.0f, 27.0f   },
-                               { -60.0f, 2.0f, -8.0f },
-                               { 60.0f, 2.0f, -8.0f  } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 60.0f, 2.0f, -8.0f },
-                               { 0.0f, 7.0f, -8.0f  },
-                               { 0.0f, 2.0f, 27.0f  } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 60.0f, 2.0f, -8.0f  },
-                               { -60.0f, 2.0f, -8.0f },
-                               { 0.0f, 7.0f, -8.0f   } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 2.0f, 27.0f   },
-                               { 0.0f, 7.0f, -8.0f   },
-                               { -60.0f, 2.0f, -8.0f } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    /* tail section */
-    /* bottom of back fin */
-    glNormal3f(0.0f, -1.0f, 0.0f);
-    glVertex3f(-30.0f, -0.50f, -57.0f);
-    glVertex3f(30.0f, -0.50f, -57.0f);
-    glVertex3f(0.0f, -0.50f, -40.0f);
-
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, -0.5f, -40.0f  },
-                               { 30.0f, -0.5f, -57.0f },
-                               { 0.0f, 4.0f, -57.0f   } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 4.0f, -57.0f    },
-                               { -30.0f, -0.5f, -57.0f },
-                               { 0.0f, -0.5f, -40.0f   } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
-
-    {
-    M3DVector3f vPoints[3] = { { 30.0f, -0.5f, -57.0f  },
-                               { -30.0f, -0.5f, -57.0f },
-                               { 0.0f, 4.0f, -57.0f    } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
+    if ((stringp == NULL) || (*stringp == NULL))
+        return NULL;
 
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 0.5f, -40.0f  },
-                               { 3.0f, 0.5f, -57.0f  },
-                               { 0.0f, 25.0f, -65.0f } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
+    result = *stringp;
 
-    {
-    M3DVector3f vPoints[3] = { { 0.0f, 25.0f, -65.0f },
-                               { -3.0f, 0.5f, -57.0f },
-                               { 0.0f, 0.5f, -40.0f  } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
+    while (**stringp && !strchr(delim, **stringp))
+        ++*stringp;
 
-    {
-    M3DVector3f vPoints[3] = { { 3.0f, 0.5f, -57.0f  },
-                               { -3.0f, 0.5f, -57.0f },
-                               { 0.0f, 25.0f, -65.0f } };
-
-    m3dFindNormalf(vNormal, vPoints[0], vPoints[1], vPoints[2]);
-    glNormal3fv(vNormal);
-    glVertex3fv(vPoints[0]);
-    glVertex3fv(vPoints[1]);
-    glVertex3fv(vPoints[2]);
-    }
+    if (**stringp)
+        *(*stringp)++ = '\0';
+    else
+        *stringp = NULL;
 
-    glEnd();
+    return result;
 }
+#endif
 
diff --git a/sdl/gltools.h b/sdl/gltools.h
index 0a53555..608b8aa 100644
--- a/sdl/gltools.h
+++ b/sdl/gltools.h
@@ -19,18 +19,29 @@ typedef struct
     GLbyte bits;                   /* bits per pixel (8 16, 24, 32) */
     GLbyte descriptor;             /* image descriptor */
 } TGAHEADER;
-#pragma pack(1)
+#pragma pack()
 
 /* function prototypes */
+void gltListExtensions(void);
+void gltOpenGLInfo(void);
+GLboolean gltQueryExtension(const char *);
 GLint gltWriteTGA(const char *);
 GLbyte *gltLoadTGA(const char *, GLint *, GLint *, GLint *, GLenum *);
-void gltDrawSnowman(void);
-void gltDrawFigures(void);
-void gltDrawTriangle(void);
-void gltDrawGround(void);
-void gltDrawUnitAxes(void);
-void gltDrawTorus(GLfloat, GLfloat, GLint, GLint);
-void gltDrawJet(void);
+#ifdef _WIN32
+char *strsep(char**, const char*);
+#endif
+
+static inline void gltErrorCheck(void)
+{
+    GLenum err_code;
+    const GLubyte *err_str;
+
+    while ((err_code = glGetError()) != GL_NO_ERROR)
+    {
+        err_str = gluErrorString(err_code);
+        fprintf(stderr, "OpenGL error: %s\n", err_str);
+    }
+}
 
 #endif
 
diff --git a/sdl/platform.c b/sdl/platform.c
index 7542d11..69235bd 100644
--- a/sdl/platform.c
+++ b/sdl/platform.c
@@ -136,18 +136,18 @@ void setup_glew(void)
     GLenum glewerr = glewInit();
     if (GLEW_OK != glewerr)
     {
-        fprintf(stderr, "error: %s\n", glewGetErrorString(glewerr));
+        fprintf(stderr, "GLEW error: %s\n", glewGetErrorString(glewerr));
         exit(-1);
     }
     else
-        fprintf(stdout, "status: using GLEW %s\n", glewGetString(GLEW_VERSION));
+        fprintf(stdout, "GLEW: using version %s\n", glewGetString(GLEW_VERSION));
 
     /* display OpenGL version */
     GLint major;
     GLint minor;
     glGetIntegerv(GL_MAJOR_VERSION, &major);
     glGetIntegerv(GL_MINOR_VERSION, &minor);
-    fprintf(stdout, "version: OpenGL %d.%d detected\n", major, minor);
+    fprintf(stdout, "GLEW: detected OpenGL %d.%d\n", major, minor);
 }
 
 inline void fps_control(const unsigned int startclock)
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index fc95fd6..566c976 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -21,6 +21,7 @@
 #include <GL/glew.h>
 #include <GL/freeglut.h>
 #include <sys/time.h>
+#include "gldraw.h"
 #include "glframe.h"
 #include "gltools.h"
 #include "math3d.h"
@@ -207,14 +208,14 @@ static void platform_init(void)
     glNewList(p.ground_list, GL_COMPILE);
        //glBindTexture(GL_TEXTURE_2D, p.textures[1]);
        glColor3ub(255, 0, 255);
-       gltDrawGround();
+       glDrawGround();
     glEndList();
 
     /* a triangle with a texture */
     glNewList(p.triangle_list, GL_COMPILE);
        glBindTexture(GL_TEXTURE_2D, p.textures[0]);
        glColor3f(1.0f, 1.0f, 1.0f);
-       gltDrawTriangle();
+       glDrawTriangle();
     glEndList();
 }
 
@@ -248,7 +249,7 @@ static void render(void)
 
         /* draw a snowman */
         glTranslatef(0.0f, 0.0f, -7.0f);
-        gltDrawSnowman();
+        glDrawSnowman();
 
     /* restore the matrix state */
     glPopMatrix();
@@ -263,9 +264,9 @@ int main(int argc, char **argv)
     setup_glew();
     setup_opengl();
     platform_init();
+    gltErrorCheck();
 
     unsigned int startclock;
-
     while (program_running)
     {
         startclock = SDL_GetTicks();
@@ -274,7 +275,6 @@ int main(int argc, char **argv)
         render();
 
         fps_control(startclock);
-
         /* need some sort of a timer to trigger this */
         /* gl_frame_normalize(&p.camera); */
     }
-- 
cgit v1.2.3