/* Displays an OBJ using the glm library call from Nate Robbins's library. The object is unitized and displayed in the unit cube with the origin at the center. Scott D. Anderson Fall 2006 */ #include #include #include #include #include char* filename; // the filename for the OBJ file GLMmodel* pmodel = NULL; // the model object void initmodel(void) { GLfloat BoundingBox[6]; // [minx,maxx,miny,maxy,minz,maxz] pmodel = glmReadOBJ(filename); if (!pmodel) exit(0); glmUnitize(pmodel); glmBoundingBox(pmodel,BoundingBox); printf("Bounding Box is (%f,%f,%f,%f,%f,%f)\n", BoundingBox[0], BoundingBox[1], BoundingBox[2], BoundingBox[3], BoundingBox[4], BoundingBox[5]); glmFacetNormals(pmodel); glmVertexNormals(pmodel, 90.0); } void display(void) { twDisplayInit(); twCamera(); glPushAttrib(GL_ALL_ATTRIB_BITS); GLfloat pos[] = { 0.0, 0.0, 1.0, 0.0 }; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, pos); glmDraw(pmodel, GLM_SMOOTH | GLM_MATERIAL); glPopAttrib(); glFlush(); glutSwapBuffers(); } int main(int argc, char* argv[]) { char buf[256]; if( argc <= 1 ) { printf("What OBJ file to load? "); scanf(buf,sizeof(buf),stdin); filename = buf; } else { filename = argv[1]; } initmodel(); /* Ready to start doing OpenGL */ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(500,500); glutCreateWindow(argv[0]); glutDisplayFunc(display); twBoundingBox(-1,1,-1,1,-1,1); // unit cube twMainInit(); glutMainLoop(); return (0); }