summaryrefslogtreecommitdiffstats
path: root/sdl/pyramid.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdl/pyramid.c')
-rw-r--r--sdl/pyramid.c66
1 files changed, 41 insertions, 25 deletions
diff --git a/sdl/pyramid.c b/sdl/pyramid.c
index ff8a03f..316abe5 100644
--- a/sdl/pyramid.c
+++ b/sdl/pyramid.c
@@ -1,18 +1,11 @@
/* pyramid.c
*
- * @2011 Kamil Kaminski
+ * Kamil Kaminski
+ * kkaminsk.com
*
- * notes: since lighting is enabled, we need to specify normals for
- * each polygon face so the OpenGL can calculate e.g. how light reflects
+ * Textured Pyramid,
+ * running on a homebrew framework
*
- * drawing a shadow for the pyramid would require drawing things twice, so on 2nd
- * 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
- *
- * it might be time to split the code, and make a shader version...
*
*/
@@ -54,8 +47,9 @@ static int client_init(struct client *p)
p->textures[1] = gltLoadTGATexture("grass.tga");
/* display list, precompile commands */
- p->ground_list = glGenLists(2);
+ p->ground_list = glGenLists(3);
p->triangle_list = p->ground_list + 1;
+ p->figures_list = p->ground_list + 2;
/* a triangle with a texture */
glNewList(p->triangle_list, GL_COMPILE);
@@ -71,13 +65,22 @@ static int client_init(struct client *p)
glDrawGround();
glEndList();
+ /* figures */
+ glNewList(p->figures_list, GL_COMPILE);
+ glDisable(GL_LIGHTING);
+ glDisable(GL_TEXTURE_2D);
+ glDrawFigures();
+ glEnable(GL_LIGHTING);
+ glEnable(GL_TEXTURE_2D);
+ glEndList();
+
return 0;
}
static int client_destroy(struct client *p)
{
glDeleteTextures(2, p->textures);
- glDeleteLists(p->ground_list, 2);
+ glDeleteLists(p->ground_list, 3);
return 0;
}
@@ -95,25 +98,36 @@ static void render(struct platform *p)
/* save the matrix state and do the rotations */
glPushMatrix();
/* apply camera transform, and draw the ground */
- glframe_apply_camera_transform(&p->camera, 1);
+ glframe_apply_camera_transform(&p->camera, 0);
glCallList(p->c->ground_list);
glPushMatrix();
- /* move object back and do in place rotation */
- glTranslatef(0.0f, 0.2f, -3.5f);
- glRotatef(p->c->xrot, 1.0f, 0.0f, 0.0f);
- glRotatef(p->c->yrot, 0.0f, 1.0f, 0.0f);
+ /* move object back and do in place rotation */
+ glTranslatef(0.0f, 0.2f, -3.5f);
+ glRotatef(p->c->xrot, 1.0f, 0.0f, 0.0f);
+ glRotatef(p->c->yrot, 0.0f, 1.0f, 0.0f);
- /* draw the pyramid */
- glCallList(p->c->triangle_list);
+ /* draw the pyramid */
+ glCallList(p->c->triangle_list);
glPopMatrix();
- /* draw a snowman */
- glTranslatef(0.0f, 0.0f, -7.0f);
+ glPushMatrix();
+ /* draw a snowman */
+ glDisable(GL_TEXTURE_2D);
+ int i;
+ for (i = 0; i < 3; i++)
+ {
+ glTranslatef(0.0f, 0.0f, -6.0f);
+ glDrawSnowman();
+ }
+ glEnable(GL_TEXTURE_2D);
+ glPopMatrix();
- glDisable(GL_TEXTURE_2D);
- glDrawSnowman();
- glEnable(GL_TEXTURE_2D);
+ glPushMatrix();
+ /* draw figures */
+ glTranslatef(0.0f, 4.0f, 0.0f);
+ glCallList(p->c->figures_list);
+ glPopMatrix();
/* restore the matrix state */
glPopMatrix();
@@ -124,6 +138,8 @@ static void render(struct platform *p)
int main(int argc, char **argv)
{
+ glutInit(&argc, argv);
+
struct platform p;
memset(&p, 0, sizeof(p));