// // Initialize OpenGL to establish lighting and colors // and initialize viewing and model parameter // void initialize(){ // initialize modelview matrix to identity glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // specify window clear (background) color to be black glClearColor(0, 0, 0, 0); // position light and turn it on glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_LIGHT2); // initialize viewing and model parameters setInitialState(); updateProjection(); //read in OBJFile objfile.read(); psurf = objfile.getscene(); // This is texture map sent to texture memory without mipmapping: //glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TEXTUREWIDTH, TEXTUREHEIGHT, // 0, GL_RGBA, GL_UNSIGNED_BYTE, TextureImage); }
// // Load the scene and get the centroid and bounding box // void load_scene(PolySurf **scene, OBJFile &objfile){ int err = objfile.read(); *scene = objfile.getscene(); if(err || scene == NULL){ char *filename = objfile.getfilename(); cerr << "OBJ file " << filename << " has errors" << endl; exit(2); } }
// // Main program to create window, setup callbacks, and initiate GLUT // int main(int argc, char* argv[]){ int suffix; //parse command line arguments switch(argc){ case 4: image = new ImageFile(); saveName = argv[3]; wFileExists = true; case 3: Nrays = atoi(argv[2]); case 2: suffix = strlen(argv[1]) - 4; if(strcmp(&(argv[1][suffix]), ".obj") != 0){ std::cerr<< "Invalid file suffix: " << suffix << std::endl; exit(1); } objfile.setfilename(argv[1]); break; case 1: default: std::cerr<< "invalid number of arguments "<< std::endl; exit(-1); break; } args = argv; //add to the lights vector gl_lightspos.push_back(Vector3d(100,100,100)); gl_lightspos.push_back(Vector3d(-100,100,40)); cam = new Camera(Vector3d(0., 0., 0.), Vector3d(0., 0., -1.), Vector3d(0., 1., 0.), 1.0); // start up the glut utilities glutInit(&argc, argv); // create the graphics window, giving width, height, and title text // and establish double buffering, RGBA color // Depth buffering must be available for drawing the shaded model glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(WIDTH, HEIGHT); glutCreateWindow("3D Texture Viewer with Mipmaps"); // register callback to draw graphics when window needs updating glutDisplayFunc(doDisplay); glutReshapeFunc(doReshape); glutKeyboardFunc(handleKey); glutMouseFunc(handleButtons); glutMotionFunc(handleMotion); initialize(); glutMainLoop(); }
// // Validate command line, and initialize viewport width, and output filename // void get_commandline(int argc, char *argv[], OBJFile &objfile){ int suffix; if(argc < 2 || argc > 3) goto abort; suffix = strlen(argv[1]) - 4; if(strcmp(&(argv[1][suffix]), ".obj") != 0) goto abort; objfile.setfilename(argv[1]); return; abort: cerr << "usage: objview filename.obj [nrays]" << endl; exit(1); }