vrheights
diff src/teapot.c @ 5:053a52f0cb64
console
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 26 Sep 2014 18:40:15 +0300 |
parents | 316ec8250af2 |
children |
line diff
1.1 --- a/src/teapot.c Fri Sep 26 13:19:22 2014 +0300 1.2 +++ b/src/teapot.c Fri Sep 26 18:40:15 2014 +0300 1.3 @@ -1,9 +1,4 @@ 1.4 -#ifndef __APPLE__ 1.5 -#include <GL/gl.h> 1.6 -#else 1.7 -#include <OpenGL/gl.h> 1.8 -#endif 1.9 - 1.10 +#include "opengl.h" 1.11 #include "teapot.h" 1.12 #include "teapot_data.h" 1.13 1.14 @@ -11,27 +6,41 @@ 1.15 1.16 int patch_subdivision = 6; 1.17 1.18 +static int dlist_sub[32]; 1.19 + 1.20 void bezier_teapot(float scale) 1.21 { 1.22 int i; 1.23 1.24 + glMatrixMode(GL_MODELVIEW); 1.25 + 1.26 + if(!dlist_sub[patch_subdivision]) { 1.27 + dlist_sub[patch_subdivision] = glGenLists(1); 1.28 + glNewList(dlist_sub[patch_subdivision], GL_COMPILE); 1.29 + 1.30 + for(i=0; i<NUM_TEAPOT_PATCHES; i++) { 1.31 + float flip = teapot_part_flip[i]; 1.32 + float rot = teapot_part_rot[i]; 1.33 + 1.34 + glPushMatrix(); 1.35 + glTranslatef(0, -3.15 * 0.5, 0); 1.36 + glRotatef(rot, 0, 1, 0); 1.37 + glScalef(1, 1, flip); 1.38 + glRotatef(-90, 1, 0, 0); 1.39 + 1.40 + draw_patch(teapot_verts, teapot_index + i * 16, flip < 0.0 ? 1 : 0, patch_subdivision, patch_subdivision, 1.0); 1.41 + 1.42 + glPopMatrix(); 1.43 + } 1.44 + 1.45 + glEndList(); 1.46 + } 1.47 + 1.48 scale /= 2.0; 1.49 - 1.50 - for(i=0; i<NUM_TEAPOT_PATCHES; i++) { 1.51 - float flip = teapot_part_flip[i]; 1.52 - float rot = teapot_part_rot[i]; 1.53 - 1.54 - glMatrixMode(GL_MODELVIEW); 1.55 - glPushMatrix(); 1.56 - glTranslatef(0, -3.15 * scale * 0.5, 0); 1.57 - glRotatef(rot, 0, 1, 0); 1.58 - glScalef(1, 1, flip); 1.59 - glRotatef(-90, 1, 0, 0); 1.60 - 1.61 - draw_patch(teapot_verts, teapot_index + i * 16, flip < 0.0 ? 1 : 0, patch_subdivision, patch_subdivision, scale); 1.62 - 1.63 - glPopMatrix(); 1.64 - } 1.65 + glPushMatrix(); 1.66 + glScalef(scale, scale, scale); 1.67 + glCallList(dlist_sub[patch_subdivision]); 1.68 + glPopMatrix(); 1.69 } 1.70 1.71 static void draw_patch(struct vec3 *bez_cp, int *index, int flip, int useg, int vseg, float scale)