diff --git a/stl-viewer.c b/stl-viewer.c index f4f0462..2bc7b51 100644 --- a/stl-viewer.c +++ b/stl-viewer.c @@ -8,7 +8,7 @@ #define HEIGHT 500 stl_t * stl = NULL; -GLuint stldl; +GLuint stldl = 0; GLfloat default_color[] = {1, 1, 1, 1}; GLuint buildDL(void); @@ -28,12 +28,8 @@ void init(void) void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBegin(GL_QUADS); - glVertex3f(-2.0, -1.0, 0.0); - glVertex3f(-2.0, 1.0, 0.0); - glVertex3f(0.0, 1.0, 0.0); - glVertex3f(0.0, -1.0, 0.0); - glEnd(); + if (stldl) + glCallList(stldl); SDL_GL_SwapBuffers(); } @@ -42,10 +38,10 @@ void reshape(GLsizei w, GLsizei h) glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30.0); + gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 10000.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glTranslatef(0.0, 0.0, -3.6); + glTranslatef(0.0, 0.0, -30); } int main(int argc, char *argv[]) @@ -63,7 +59,7 @@ int main(int argc, char *argv[]) return -2; } stldl = buildDL(); - + if (SDL_Init(SDL_INIT_VIDEO)) { fprintf(stderr, "Failed to initialize SDL!\n"); @@ -123,6 +119,7 @@ GLuint buildDL(void) else if (!dfltClrAct) glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, default_color); + glNormal3fv(stl_face(stl, i).normal); int j; for (j = 0; j < 3; j++) glVertex3fv(stl_face(stl, i).vertices[j]);