summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyle K <kylek389@gmail.com>2010-11-08 01:09:58 -0600
committerKamil Kaminski <kamilkss@gmail.com>2010-11-08 01:09:58 -0600
commit1d934cbf31923c0116123b7e04783c307f1149ff (patch)
tree6ee08f2c3d940eceb72fbf27dc945b6b14191287
parentb4fabf95efc0d858f449df6ffe5ca57141a56151 (diff)
downloadGLPyramid-1d934cbf31923c0116123b7e04783c307f1149ff.tar.gz
GLPyramid-1d934cbf31923c0116123b7e04783c307f1149ff.tar.bz2
GLPyramid-1d934cbf31923c0116123b7e04783c307f1149ff.zip
Meh
-rw-r--r--sdl/GL_notes.txt9
-rw-r--r--sdl/Makefile9
-rw-r--r--sdl/glframe.c7
-rw-r--r--sdl/gltools.c105
-rw-r--r--sdl/gltools.h4
-rw-r--r--sdl/pyramid.c27
6 files changed, 143 insertions, 18 deletions
diff --git a/sdl/GL_notes.txt b/sdl/GL_notes.txt
index c22d743..b155d88 100644
--- a/sdl/GL_notes.txt
+++ b/sdl/GL_notes.txt
@@ -65,6 +65,13 @@ Shadow Mapping
lots of magic is done to project the texture/shadow map back into the final scene
Shaders
-- VP: to mimick fixed functionality, multiply incoming vertex my MVP (modelview/projection matrices)
+- VP: to mimick fixed functionality, multiply incoming vertex by MVP (modelview/projection matrices)
if no transfomration took place, just transfer the vertex data into next stage, clipping AFAIK
+Vertex Shader--you can write code for tasks such as:
+- Vertex position transformation using the modelview and projection matrices
+- Normal transformation, and if required its normalization
+- Texture coordinate generation and transformation
+- Lighting per vertex or computing values for lighting per pixel
+- Color computation
+
diff --git a/sdl/Makefile b/sdl/Makefile
index 51a013f..1f9134c 100644
--- a/sdl/Makefile
+++ b/sdl/Makefile
@@ -1,5 +1,5 @@
PROG = pyramid
-OBJS = $(PROG).o math3d.o gltools.o glframe.o
+OBJS = $(PROG).o math3d.o gltools.o glframe.o shader.o
CC = gcc
DBGFLAGS = -g -O0
ifdef DEBUG
@@ -16,7 +16,7 @@ SDL_image_LDFLAGS := $(shell pkg-config --libs SDL_image)
$(PROG): $(OBJS)
$(CC) $(LDFLAGS) $(SDL_LDFLAGS) $(SDL_image_LDFLAGS) $(OBJS) -o $(PROG)
-$(PROG).o: $(PROG).c math3d.h gltools.h
+$(PROG).o: $(PROG).c math3d.h gltools.h glframe.h
$(CC) -c $(CFLAGS) $(SDL_CFLAGS) $(SDL_image_CFLAGS) $(PROG).c
math3d.o: math3d.c math3d.h
@@ -25,9 +25,12 @@ math3d.o: math3d.c math3d.h
gltools.o: gltools.c gltools.h math3d.h
$(CC) -c $(CFLAGS) gltools.c
-glframe.o: glframe.c math3d.h
+glframe.o: glframe.c glframe.h math3d.h
$(CC) -c $(CFLAGS) glframe.c
+shader.o: shader.c shader.h math3d.h
+ $(CC) -c $(CFLAGS) shader.c
+
.PHONY: clean
clean:
diff --git a/sdl/glframe.c b/sdl/glframe.c
index b8b45d9..c61f651 100644
--- a/sdl/glframe.c
+++ b/sdl/glframe.c
@@ -8,7 +8,6 @@
*/
#include "glframe.h"
-#include "math3d.h"
void glframe_reset(GLFrame *frame)
{
@@ -25,7 +24,7 @@ void glframe_reset(GLFrame *frame)
frame->v_up[2] = 0.0f;
}
-/* get a 4x4 transformation matrix that describes the ccamera orientation */
+/* get a 4x4 transformation matrix that describes the camera orientation */
void glframe_get_camera_orientation(GLFrame *frame, M3DMatrix44f m)
{
M3DVector3f x, z;
@@ -63,7 +62,7 @@ void glframe_get_camera_orientation(GLFrame *frame, M3DMatrix44f m)
/* some of the code is unimplemented */
void glframe_apply_camera_transform(GLFrame *frame)
{
- /* XXX: rotation only, should passed in as a parameter */
+ /* XXX: rotation only, should be passed in as a parameter */
int rot_only = 0;
M3DMatrix44f m;
@@ -95,7 +94,7 @@ void glframe_rotate_local_y(GLFrame *frame, float angle)
{
M3DMatrix44f rotMat;
- /* just Rotate around the up vector */
+ /* just rotate around the up vector */
/* create a rotation matrix around my Up (Y) vector */
m3dRotationMatrix44f(rotMat, angle, frame->v_up[0], frame->v_up[1], frame->v_up[2]);
diff --git a/sdl/gltools.c b/sdl/gltools.c
index 756112b..7244f4b 100644
--- a/sdl/gltools.c
+++ b/sdl/gltools.c
@@ -6,7 +6,6 @@
*
*/
-#include "math3d.h"
#include "gltools.h"
GLint gltWriteTGA(const char *szFileName)
@@ -166,6 +165,110 @@ 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;
diff --git a/sdl/gltools.h b/sdl/gltools.h
index 61001d2..121c285 100644
--- a/sdl/gltools.h
+++ b/sdl/gltools.h
@@ -1,6 +1,8 @@
#ifndef _GLTOOLS_H_
#define _GLTOOLS_H_
+#include "math3d.h"
+
/* this is the targa header, pragmas are needed to do the voodoo magic */
/* http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/ */
#pragma pack(1)
@@ -24,6 +26,8 @@ typedef struct
/* function prototypes */
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);
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index 91d03f1..e08b426 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -12,6 +12,8 @@
* so far we have been using immediate mode rendering, we should begin using
* display lists / batch processing to reduce overhead, aka compiling commands
*
+ * it might be time to split the code, and make a shader version...
+ *
*/
#include <SDL/SDL.h>
@@ -74,13 +76,13 @@ static void setup_opengl(void)
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 };
-
+
/* 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 */
+ glFogi(GL_FOG_MODE, GL_LINEAR); /* fog equation */
glEnable(GL_DEPTH_TEST); /* hidden surface removal */
glFrontFace(GL_CCW); /* counter clock-wise polygons face out */
@@ -105,7 +107,7 @@ static void setup_opengl(void)
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);
@@ -113,8 +115,9 @@ static void setup_opengl(void)
glHint(GL_POINT_SMOOTH_HINT, GL_NICEST);
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
- glEnable(GL_POLYGON_SMOOTH);
- glHint(GL_POLYGON_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);
@@ -163,7 +166,7 @@ static void setup_opengl(void)
glNewList(triangle_list, GL_COMPILE);
gltDrawTriangle();
- glEndList();
+ glEndList();
}
static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag)
@@ -202,7 +205,7 @@ static void keys(SDL_keysym *keysym, unsigned int *keys_held, int flag)
if (keys_held[SDLK_LEFT])
glframe_rotate_local_y(&camera, 0.02f);
if (keys_held[SDLK_RIGHT])
- glframe_rotate_local_y(&camera, -0.02f);
+ glframe_rotate_local_y(&camera, -0.02f);
}
xRot = (GLfloat) ((const int) xRot % 360);
@@ -264,15 +267,21 @@ static void render(void)
glframe_apply_camera_transform(&camera);
glColor3ub(255, 0, 255);
glCallList(ground_list);
-
+
+ glPushMatrix();
/* move object back and do in place rotation */
glTranslatef(0.0f, 0.2f, -3.5f);
glRotatef(xRot, 1.0f, 0.0f, 0.0f);
glRotatef(yRot, 0.0f, 1.0f, 0.0f);
/* draw the pyramid */
- glColor3f(1.0f, 1.0f, 1.0f);
+ glColor3f(1.0f, 1.0f, 1.0f);
glCallList(triangle_list);
+ glPopMatrix();
+
+ /* draw a snowman */
+ glTranslatef(0.0f, 0.0f, -7.0f);
+ gltDrawSnowman();
/* restore the matrix state */
glPopMatrix();