summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2011-07-02 14:59:16 -0500
committerKamil Kaminski <kamilkss@gmail.com>2011-07-02 14:59:16 -0500
commit01d6561d73d11a28fd339d46e73e12fd5658300a (patch)
tree4c421770be1b335f4ae38042480ed905f232c60c
parent616f2216d80848f88605be75fd03049f6d635378 (diff)
downloadGLPyramid-01d6561d73d11a28fd339d46e73e12fd5658300a.tar.gz
GLPyramid-01d6561d73d11a28fd339d46e73e12fd5658300a.tar.bz2
GLPyramid-01d6561d73d11a28fd339d46e73e12fd5658300a.zip
split more
-rw-r--r--sdl/Makefile12
-rw-r--r--sdl/gltools.c4
-rw-r--r--sdl/math3d.c2
-rw-r--r--sdl/mingw322
-rw-r--r--sdl/platform.c169
-rw-r--r--sdl/platform.h21
-rw-r--r--sdl/pyramid.c257
-rw-r--r--sdl/window.c37
-rw-r--r--sdl/window.h8
9 files changed, 289 insertions, 223 deletions
diff --git a/sdl/Makefile b/sdl/Makefile
index 1d881e9..7b878a9 100644
--- a/sdl/Makefile
+++ b/sdl/Makefile
@@ -1,5 +1,5 @@
BIN = pyramid
-SRC = pyramid.c math3d.c gltools.c glframe.c shader.c
+SRC = pyramid.c math3d.c gltools.c glframe.c shader.c platform.c window.c
CC = gcc
CFLAGS = -Wall -std=c99
DBGFLAGS = -g -O0
@@ -21,7 +21,7 @@ OBJ_ABS = $(addprefix $(OBJ_DIR)/, $(addsuffix .o, $(subst .c,,$(SRC))))
$(BIN): $(OBJ_DIR) $(OBJ_REL)
$(CC) $(LDFLAGS) $(SDL_LDFLAGS) $(SDL_image_LDFLAGS) $(OBJ_ABS) -o $@
-pyramid.o: %.o: %.c math3d.h gltools.h glframe.h
+pyramid.o: %.o: %.c math3d.h gltools.h glframe.h platform.h
$(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $< -o $(OBJ_DIR)/$@
math3d.o: %.o: %.c %.h
@@ -33,9 +33,15 @@ gltools.o: %.o: %.c %.h math3d.h
glframe.o: %.o: %.c %.h math3d.h
$(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
-shader.o: %.o: %.c %.h math3d.h
+shader.o: %.o: %.c %.h
$(CC) -c $(CFLAGS) $< -o $(OBJ_DIR)/$@
+platform.o: %.o: %.c %.h
+ $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $< -o $(OBJ_DIR)/$@
+
+window.o: %.o: %.c %.h
+ $(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $< -o $(OBJ_DIR)/$@
+
$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
diff --git a/sdl/gltools.c b/sdl/gltools.c
index 7bc85ef..7db2410 100644
--- a/sdl/gltools.c
+++ b/sdl/gltools.c
@@ -75,7 +75,7 @@ GLint gltWriteTGA(const char *szFileName)
free(pBits); /* free buffer and return error */
return 0;
}
-
+
/* write the header */
fwrite(&tgaHeader, sizeof(TGAHEADER), 1, pFile);
@@ -146,7 +146,7 @@ GLbyte *gltLoadTGA(const char *szFileName, GLint *iWidth, GLint *iHeight,
free(pBits);
return NULL;
}
-
+
/* set opengl format expected */
switch (sDepth)
{
diff --git a/sdl/math3d.c b/sdl/math3d.c
index e189a01..775dabd 100644
--- a/sdl/math3d.c
+++ b/sdl/math3d.c
@@ -196,7 +196,7 @@ void m3dMatrixMultiply44f(M3DMatrix44f product, const M3DMatrix44f a,
P(i, 2) = ai0 * B(0, 2) + ai1 * B(1, 2) + ai2 * B(2, 2) + ai3 * B(3, 2);
P(i, 3) = ai0 * B(0, 3) + ai1 * B(1, 3) + ai2 * B(2, 3) + ai3 * B(3, 3);
}
-
+
#undef A
#undef B
#undef P
diff --git a/sdl/mingw32 b/sdl/mingw32
index eb1cbbc..93d3bf3 100644
--- a/sdl/mingw32
+++ b/sdl/mingw32
@@ -1,5 +1,5 @@
BIN = pyramid
-SRC = pyramid.c math3d.c gltools.c glframe.c shader.c
+SRC = pyramid.c math3d.c gltools.c glframe.c shader.c platform.c window.c
CC = gcc
CFLAGS = -Wall -std=c99 -MD
DBGFLAGS = -g -O0
diff --git a/sdl/platform.c b/sdl/platform.c
new file mode 100644
index 0000000..55f6555
--- /dev/null
+++ b/sdl/platform.c
@@ -0,0 +1,169 @@
+/* platform.c
+ *
+ * Platform
+ *
+ *
+ */
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include <GL/glew.h>
+#include "platform.h"
+
+/* few light arrays */
+GLfloat fNoLight[] = { 0.0f, 0.0f, 0.0f, 0.0f };
+GLfloat fLowLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
+GLfloat fBrightLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
+
+/* light values and coordinates */
+GLfloat whiteLight[] = { 0.05f, 0.05f, 0.05f, 1.0f };
+GLfloat sourceLight[] = { 0.75f, 0.75f, 0.75f, 1.0f };
+GLfloat lightPos[] = { -10.f, 5.0f, 5.0f, 1.0f };
+
+/* variables that should be already defined and declared for us by main program */
+extern const unsigned int xres;
+extern const unsigned int yres;
+extern const unsigned int bpp;
+extern const char *window_caption;
+extern const char *window_icon_path;
+
+void setup_opengl(void)
+{
+ /* setup fog */
+ glEnable(GL_FOG);
+ 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 */
+
+ 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 */
+
+ /* setup and enable light 0 */
+ /* ambient RGBA intensity of the entire scene */
+ glLightModelfv(GL_LIGHT_MODEL_AMBIENT, whiteLight);
+ glLightfv(GL_LIGHT0, GL_AMBIENT, sourceLight);
+ glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight);
+ glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight);
+ glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
+
+ /* enable lighting */
+ glEnable(GL_LIGHTING);
+ glEnable(GL_LIGHT0);
+
+ /* enable color tracking */
+ glEnable(GL_COLOR_MATERIAL);
+
+ /* 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);
+
+ /* turn on anti aliasing for points, lines, and polygons */
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ glEnable(GL_POINT_SMOOTH);
+ glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
+ glEnable(GL_LINE_SMOOTH);
+ glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
+ /* screws up snowman */
+ //glEnable(GL_POLYGON_SMOOTH);
+ //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
+
+ /* gray background */
+ glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
+
+ /* original texture loading used to be here */
+
+ /* texture filtering, we modify default values since we don't have mipmaps */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+
+ /* how OpenGL combines the colors from texels with the color of the underlying
+ * geometry is controlled by the texture environment mode */
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
+
+ /* once texture is loaded and enabled, it will applied to every primitive
+ * that specifies coordinates */
+ glEnable(GL_TEXTURE_2D);
+
+ /* multisampling for polygons, conflicts with anti-aliasing */
+ //glEnable(GL_MULTISAMPLE);
+
+ /* don't know about this, but why not */
+ glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
+}
+
+void setup_sdl(void)
+{
+ SDL_Surface *screen;
+
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
+ {
+ fprintf(stderr, "unable to init SDL: %s\n", SDL_GetError());
+ exit(-1);
+ }
+ atexit(SDL_Quit);
+ SDL_WM_SetCaption(window_caption, NULL);
+ SDL_WM_SetIcon(IMG_Load(window_icon_path), NULL);
+
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+
+ if ((screen = SDL_SetVideoMode(xres, yres, bpp, SDL_OPENGL | SDL_RESIZABLE)) == NULL)
+ {
+ fprintf(stderr, "unable to set video mode: %s\n", SDL_GetError());
+ exit(-1);
+ }
+
+ SDL_EnableUNICODE(1);
+ /* SDL doesn't trigger off a ResizeEvent at startup, but as we need this
+ * for OpenGL, we do this ourselves */
+ SDL_Event resizeEvent;
+ resizeEvent.type = SDL_VIDEORESIZE;
+ resizeEvent.resize.w = xres;
+ resizeEvent.resize.h = yres;
+ SDL_PushEvent(&resizeEvent);
+}
+
+void setup_glew(void)
+{
+ /* initalize glew */
+ GLenum glewerr = glewInit();
+ if (GLEW_OK != glewerr)
+ {
+ fprintf(stderr, "error: %s\n", glewGetErrorString(glewerr));
+ exit(-1);
+ }
+ else
+ fprintf(stdout, "status: using GLEW %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);
+}
+
+inline void fps_control(const unsigned int startclock)
+{
+ unsigned int deltaclock = SDL_GetTicks() - startclock;
+ if (deltaclock < 1000 / FRAMES_PER_SECOND)
+ SDL_Delay((1000 / FRAMES_PER_SECOND) - deltaclock);
+
+#ifdef STAT_FPS
+ char buffer[30] = { 0 };
+ sprintf(buffer, "%s: %4d fps", window_caption,
+ 1000 / (SDL_GetTicks() - startclock));
+ SDL_WM_SetCaption(buffer, NULL);
+#endif
+}
+
diff --git a/sdl/platform.h b/sdl/platform.h
new file mode 100644
index 0000000..3428a90
--- /dev/null
+++ b/sdl/platform.h
@@ -0,0 +1,21 @@
+#ifndef _PLATFORM_H_
+#define _PLATFORM_H_
+
+#define FRAMES_PER_SECOND 60
+
+extern GLfloat fNoLight[];
+extern GLfloat fLowLight[];
+extern GLfloat fBrightLight[];
+
+extern GLfloat whiteLight[];
+extern GLfloat sourceLight[];
+extern GLfloat lightPos[];
+
+/* function prototypes */
+void setup_opengl(void);
+void setup_sdl(void);
+void setup_glew(void);
+extern void fps_control(unsigned int);
+
+#endif
+
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index 3b63168..b3e1b2e 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -24,35 +24,23 @@
#include "glframe.h"
#include "gltools.h"
#include "math3d.h"
-#define FRAMES_PER_SECOND 60
+#include "platform.h"
+#include "window.h"
/* function prototypes */
-static void window_resize(int, int);
-static void setup_opengl(void);
-static void setup_sdl(void);
-static void setup_glew(void);
-static inline void fps_control(unsigned int);
static void keys(SDL_keysym *, const unsigned int *, const int);
static void process_events(void);
-static void render(void);
static void platform_init(void);
static void platform_destroy(void);
+static void render(void);
/* global */
int program_running = 1;
const unsigned int xres = 640;
const unsigned int yres = 480;
-const unsigned int bpp = 32;
-
-/* few arrays, they could make into the header at some point */
-GLfloat fNoLight[] = { 0.0f, 0.0f, 0.0f, 0.0f };
-GLfloat fLowLight[] = { 0.25f, 0.25f, 0.25f, 1.0f };
-GLfloat fBrightLight[] = { 1.0f, 1.0f, 1.0f, 1.0f };
-
-/* light values and coordinates */
-GLfloat whiteLight[] = { 0.05f, 0.05f, 0.05f, 1.0f };
-GLfloat sourceLight[] = { 0.75f, 0.75f, 0.75f, 1.0f };
-GLfloat lightPos[] = { -10.f, 5.0f, 5.0f, 1.0f };
+const unsigned int bpp = 32;
+const char *window_caption = "Textured Pyramid";
+const char *window_icon_path = "tux.png";
/* platform struct */
static struct
@@ -67,169 +55,6 @@ static struct
GLfloat yrot;
} p;
-static void window_resize(int w, int h)
-{
- printf("window: resizing to %dx%d\n", w, h);
- GLfloat fAspect = (GLfloat) w / (GLfloat) h;
- if (h == 0)
- h = 1;
- glViewport(0, 0, w, h);
-
- /* reset coordinate system */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- /* produce the perspective projection */
- /* void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) */
- gluPerspective(40.0f, fAspect, 1.0, 40.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- /* this needs to be ran again, glut does it for you I suppose */
- SDL_SetVideoMode(w, h, bpp, SDL_OPENGL | SDL_RESIZABLE);
-}
-
-static void setup_opengl(void)
-{
- /* setup fog */
- glEnable(GL_FOG);
- 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 */
-
- 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 */
-
- /* setup and enable light 0 */
- /* ambient RGBA intensity of the entire scene */
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, whiteLight);
- glLightfv(GL_LIGHT0, GL_AMBIENT, sourceLight);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, fBrightLight);
- glLightfv(GL_LIGHT0, GL_SPECULAR, fBrightLight);
- glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
-
- /* enable lighting */
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
-
- /* enable color tracking */
- glEnable(GL_COLOR_MATERIAL);
-
- /* 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);
-
- /* turn on anti aliasing for points, lines, and polygons */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glEnable(GL_POINT_SMOOTH);
- glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
- glEnable(GL_LINE_SMOOTH);
- glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
- /* screws up snowman */
- //glEnable(GL_POLYGON_SMOOTH);
- //glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST);
-
- /* gray background */
- glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
-
- /* original texture loading used to be here */
-
- /* texture filtering, we modify default values since we don't have mipmaps */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- /* how OpenGL combines the colors from texels with the color of the underlying
- * geometry is controlled by the texture environment mode */
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- /* once texture is loaded and enabled, it will applied to every primitive
- * that specifies coordinates */
- glEnable(GL_TEXTURE_2D);
-
- /* multisampling for polygons, conflicts with anti-aliasing */
- //glEnable(GL_MULTISAMPLE);
-
- /* don't know about this, but why not */
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
-}
-
-static void setup_sdl(void)
-{
- SDL_Surface *screen;
-
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 )
- {
- fprintf(stderr, "unable to init SDL: %s\n", SDL_GetError());
- exit(-1);
- }
- atexit(SDL_Quit);
- SDL_WM_SetCaption("Textured Pyramid", NULL);
- SDL_WM_SetIcon(IMG_Load("tux.png"), NULL);
-
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
-
- if ((screen = SDL_SetVideoMode(xres, yres, bpp, SDL_OPENGL | SDL_RESIZABLE)) == NULL)
- {
- fprintf(stderr, "unable to set video mode: %s\n", SDL_GetError());
- exit(-1);
- }
-
- SDL_EnableUNICODE(1);
- /* SDL doesn't trigger off a ResizeEvent at startup, but as we need this
- * for OpenGL, we do this ourselves */
- SDL_Event resizeEvent;
- resizeEvent.type = SDL_VIDEORESIZE;
- resizeEvent.resize.w = xres;
- resizeEvent.resize.h = yres;
- SDL_PushEvent(&resizeEvent);
-}
-
-static void setup_glew(void)
-{
- /* initalize glew */
- GLenum glewerr = glewInit();
- if (GLEW_OK != glewerr)
- {
- fprintf(stderr, "error: %s\n", glewGetErrorString(glewerr));
- exit(-1);
- }
- else
- fprintf(stdout, "status: using GLEW %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);
-}
-
-static inline void fps_control(const unsigned int startclock)
-{
- unsigned int deltaclock = SDL_GetTicks() - startclock;
- if (deltaclock < 1000 / FRAMES_PER_SECOND)
- SDL_Delay((1000 / FRAMES_PER_SECOND) - deltaclock);
-
-#ifdef STAT_FPS
- char buffer[30] = { 0 };
- sprintf(buffer, "Textured Pyramid: %4d fps",
- 1000 / (SDL_GetTicks() - startclock));
- SDL_WM_SetCaption(buffer, NULL);
-#endif
-}
-
static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int flag)
{
if (!flag)
@@ -273,9 +98,9 @@ static void keys(SDL_keysym *keysym, const unsigned int *keys_held, const int fl
p.yrot = (GLfloat) ((const int) p.yrot % 360);
}
-/* process SDL events */
static void process_events(void)
{
+ /* process SDL events */
SDL_Event event;
unsigned static int keys_held[323];
SDLKey sym;
@@ -317,40 +142,6 @@ static void process_events(void)
flag = !flag;
}
-static void render(void)
-{
- /* clear the window with current clearing color */
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- /* save the matrix state and do the rotations */
- glPushMatrix();
- /* apply camera transform, and draw the ground */
- glframe_apply_camera_transform(&p.camera);
- glColor3ub(255, 0, 255);
- glCallList(p.ground_list);
-
- glPushMatrix();
- /* move object back and do in place rotation */
- glTranslatef(0.0f, 0.2f, -3.5f);
- glRotatef(p.xrot, 1.0f, 0.0f, 0.0f);
- glRotatef(p.yrot, 0.0f, 1.0f, 0.0f);
-
- /* draw the pyramid */
- glColor3f(1.0f, 1.0f, 1.0f);
- glCallList(p.triangle_list);
- glPopMatrix();
-
- /* draw a snowman */
- glTranslatef(0.0f, 0.0f, -7.0f);
- gltDrawSnowman();
-
- /* restore the matrix state */
- glPopMatrix();
-
- /* buffer swap */
- SDL_GL_SwapBuffers();
-}
-
static void platform_init(void)
{
/* variables used for texture loading */
@@ -392,6 +183,40 @@ static void platform_destroy(void)
glDeleteLists(p.ground_list, 2);
}
+static void render(void)
+{
+ /* clear the window with current clearing color */
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ /* save the matrix state and do the rotations */
+ glPushMatrix();
+ /* apply camera transform, and draw the ground */
+ glframe_apply_camera_transform(&p.camera);
+ glColor3ub(255, 0, 255);
+ glCallList(p.ground_list);
+
+ glPushMatrix();
+ /* move object back and do in place rotation */
+ glTranslatef(0.0f, 0.2f, -3.5f);
+ glRotatef(p.xrot, 1.0f, 0.0f, 0.0f);
+ glRotatef(p.yrot, 0.0f, 1.0f, 0.0f);
+
+ /* draw the pyramid */
+ glColor3f(1.0f, 1.0f, 1.0f);
+ glCallList(p.triangle_list);
+ glPopMatrix();
+
+ /* draw a snowman */
+ glTranslatef(0.0f, 0.0f, -7.0f);
+ gltDrawSnowman();
+
+ /* restore the matrix state */
+ glPopMatrix();
+
+ /* buffer swap */
+ SDL_GL_SwapBuffers();
+}
+
int main(int argc, char **argv)
{
setup_sdl();
diff --git a/sdl/window.c b/sdl/window.c
new file mode 100644
index 0000000..3ecd99c
--- /dev/null
+++ b/sdl/window.c
@@ -0,0 +1,37 @@
+/* window.c
+ *
+ * Window
+ *
+ *
+ */
+
+#include <SDL/SDL.h>
+#include <SDL/SDL_image.h>
+#include <GL/glew.h>
+#include "window.h"
+
+extern const unsigned int bpp;
+
+void window_resize(int w, int h)
+{
+ printf("window: resizing to %dx%d\n", w, h);
+ GLfloat fAspect = (GLfloat) w / (GLfloat) h;
+ if (h == 0)
+ h = 1;
+ glViewport(0, 0, w, h);
+
+ /* reset coordinate system */
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+
+ /* produce the perspective projection */
+ /* void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar) */
+ gluPerspective(40.0f, fAspect, 1.0, 40.0);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ /* this needs to be ran again, glut does it for you I suppose */
+ SDL_SetVideoMode(w, h, bpp, SDL_OPENGL | SDL_RESIZABLE);
+}
+
diff --git a/sdl/window.h b/sdl/window.h
new file mode 100644
index 0000000..84969f8
--- /dev/null
+++ b/sdl/window.h
@@ -0,0 +1,8 @@
+#ifndef _WINDOW_H_
+#define _WINDOW_H_
+
+/* function prototypes */
+void window_resize(int, int);
+
+#endif
+