summaryrefslogtreecommitdiffstats
path: root/sdl/pyramid.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl/pyramid.c')
-rw-r--r--sdl/pyramid.c64
1 files changed, 28 insertions, 36 deletions
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index c8595b2..5959e02 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -9,6 +9,9 @@
* pass we would draw with black color and multiply by squished matrix, we should
* get to this later with better approach
*
+ * so far we have been using immediate mode rendering, we should begin using
+ * display lists / batch processing to reduce overhead, aka compiling commands
+ *
*/
#include <SDL/SDL.h>
@@ -20,6 +23,8 @@
#include <sys/time.h>
#define FRAMES_PER_SECOND 60
+/* function prototypes */
+
/* global */
int program_running = 1;
GLFrame camera;
@@ -55,7 +60,7 @@ static void resize(int w, int h)
SDL_SetVideoMode(w, h, 32, SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_RESIZABLE);
}
-static void SetupRC()
+static void setup_opengl(void)
{
GLbyte *pBytes;
GLint iWidth, iHeight, iComponents;
@@ -71,11 +76,11 @@ static void SetupRC()
glFogfv(GL_FOG_COLOR, fLowLight); /* set fog color to match background */
glFogf(GL_FOG_START, 4.0f);
glFogf(GL_FOG_END, 20.0f);
- glFogi(GL_FOG_MODE, GL_LINEAR); /* fog equation */
+ glFogi(GL_FOG_MODE, GL_LINEAR); /* fog equation */
- glEnable(GL_DEPTH_TEST); /* hidden surface removal */
- glFrontFace(GL_CCW); /* counter clock-wise polygons face out */
- glEnable(GL_CULL_FACE); /* do not calculate inside of a pyramid */
+ glEnable(GL_DEPTH_TEST);/* hidden surface removal */
+ glFrontFace(GL_CCW); /* counter clock-wise polygons face out */
+ glEnable(GL_CULL_FACE); /* do not calculate inside of a pyramid */
/* enable lighting */
glEnable(GL_LIGHTING);
@@ -87,7 +92,7 @@ static void SetupRC()
glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight);
glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
- glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
/* enable color tracking */
@@ -96,7 +101,7 @@ static void SetupRC()
/* set Material properties to follow glColor values */
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT, GL_SPECULAR, fBrightLight);
- glMateriali(GL_FRONT, GL_SHININESS, 128);
+ glMateriali(GL_FRONT, GL_SHININESS, 128);
/* turn on anti aliasing for points, lines, and polygons */
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -106,7 +111,7 @@ static void SetupRC()
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_POLYGON_SMOOTH);
- glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+ glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
/* gray background */
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
@@ -160,7 +165,7 @@ static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag)
case SDLK_UP: move_forward(&camera, 0.5f); break;
case SDLK_DOWN: move_forward(&camera, -0.5f); break;
case SDLK_LEFT: rotate_local_y(&camera, 0.1f); break;
- case SDLK_RIGHT: rotate_local_y(&camera, -0.1f); break;
+ case SDLK_RIGHT: rotate_local_y(&camera, -0.1f); break;
default: break;
}
}
@@ -182,7 +187,7 @@ static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag)
if (keys_held[SDLK_LEFT])
rotate_local_y(&camera, 0.02f);
if (keys_held[SDLK_RIGHT])
- rotate_local_y(&camera, -0.02f);
+ rotate_local_y(&camera, -0.02f);
}
xRot = (GLfloat) ((const int) xRot % 360);
@@ -190,7 +195,7 @@ static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag)
}
/* process SDL events */
-void processEvents()
+static void process_events()
{
SDL_Event event;
unsigned static int keys_held[323];
@@ -222,8 +227,7 @@ void processEvents()
}
}
- /* XXX below code has to be placed here */
- /* check for keys that are being constantly held */
+ /* below code has to be placed here, check for keys that are being constantly held */
if (keys_held[SDLK_w] || keys_held[SDLK_s] || keys_held[SDLK_a] || keys_held[SDLK_d] ||
keys_held[SDLK_UP] || keys_held[SDLK_DOWN] || keys_held[SDLK_LEFT] || keys_held[SDLK_RIGHT])
{
@@ -231,26 +235,7 @@ void processEvents()
keys(NULL, keys_held, flag);
}
else
- flag = !flag;
-}
-
-static void draw_ground(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();
+ flag = !flag;
}
static void render(void)
@@ -263,7 +248,7 @@ static void render(void)
/* apply camera transform, and draw the ground */
apply_camera_transform(&camera);
glColor3ub(255, 0, 255);
- draw_ground();
+ gltDrawGround();
/* move object back and do in place rotation */
glTranslatef(0.0f, 0.2f, -3.5f);
@@ -319,7 +304,14 @@ int main(int argc, char **argv)
else
fprintf(stdout, "status: using GLEW %s\n", glewGetString(GLEW_VERSION));
- SetupRC();
+ /* display OpenGL version */
+ GLint major;
+ GLint minor;
+ glGetIntegerv(GL_MAJOR_VERSION, &major);
+ glGetIntegerv(GL_MINOR_VERSION, &minor);
+ fprintf(stdout, "version: OpenGL %d.%d\n", major, minor);
+
+ setup_opengl();
#ifdef STAT_FPS
/* fps counter */
@@ -335,7 +327,7 @@ int main(int argc, char **argv)
#ifdef STAT_FPS
startclock = SDL_GetTicks();
#endif
- processEvents();
+ process_events();
render();
gettimeofday(&lcurrent, 0);