int main(int narg, char** argc) { const char *strVertexPath = "vertex.shader", *strFragmentPath = "fragment.shader"; /* read program parameters from command line */ char *program = argc[0]; while ((narg>1) && (argc[1][0]=='-')) { switch(argc[1][1]) { case 'f': strFragmentPath=&argc[1][3]; break; case 'v': strVertexPath=&argc[1][3]; break; default: std::cout << "Usage: " << program << " <options>" << std::endl << "\t-v <file_name>\tVertex shader path" << std::endl << "\t-f <file_name>\tFragment shader path" << std::endl; exit(EXIT_SUCCESS); break; } narg--; argc++; } /* initialize GL context and window */ window = GL_init(); /* load shaders */ dout << "Fragment shader: " << strFragmentPath << std::endl; dout << "Vertex shader: " << strVertexPath << std::endl; GLuint shaderProgram = InitializeProgram(strVertexPath, strFragmentPath); glUseProgram(shaderProgram); dout << "Loading shader program complete" << std::endl; // Get a handle for our "MVP" uniform GLuint MatrixID = glGetUniformLocation(shaderProgram, "MVP"); // Get a handle for our buffers GLuint vertexPosition_modelspaceID = glGetAttribLocation(shaderProgram, "vertex"); GLuint vertexNormalID = glGetAttribLocation(shaderProgram, "normal"); // Read our .obj file std::vector<glm::vec3> vertices; std::vector<glm::vec3> normals; loadOBJ("monkey.obj", vertices, normals); // Load it into a VBO GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), &vertices[0], GL_STATIC_DRAW); GLuint normalbuffer; glGenBuffers(1, &normalbuffer); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), &normals[0], GL_STATIC_DRAW); // Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 1.0f, 1000.0f); // Camera matrix glm::mat4 View = glm::lookAt( glm::vec3(0, 1, 3), // Camera is at (4,3,3), in World Space glm::vec3(0,0,0), // and looks at the origin glm::vec3(0,1,0) // Head is up (set to 0,-1,0 to look upside-down) ); // Model matrix : an identity matrix (model will be at the origin) glm::mat4 Model = glm::mat4(1.0f); // Our ModelViewProjection : multiplication of our 3 matrices glm::mat4 MVP = Projection * View * Model; // Remember, matrix multiplication is the other way around /* loop until window closed */ dout << "Entering main loop" << std::endl; while (!glfwWindowShouldClose(window)) { // Clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Send our transformation to the currently bound shader, // in the "MVP" uniform glUniformMatrix4fv(MatrixID, 1, GL_FALSE, &MVP[0][0]); // 1rst attribute buffer : vertices glEnableVertexAttribArray(vertexPosition_modelspaceID); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glVertexAttribPointer( vertexPosition_modelspaceID, // The attribute we want to configure 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); glEnableVertexAttribArray(vertexNormalID); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glVertexAttribPointer( vertexNormalID, // The attribute we want to configure 3, // size GL_FLOAT, // type GL_FALSE, // normalized? 0, // stride (void*)0 // array buffer offset ); // Draw the triangles ! glDrawArrays(GL_TRIANGLES, 0, vertices.size() ); glDisableVertexAttribArray(vertexPosition_modelspaceID); glDisableVertexAttribArray(vertexNormalID); /* swap buffers */ glfwSwapBuffers(window); /* poll events */ glfwPollEvents(); } /* terminate application */ dout << "Loop ended, closing" << std::endl; // Cleanup VBO and shader glDeleteBuffers(1, &vertexbuffer); glDeleteBuffers(1, &normalbuffer); glDeleteProgram(shaderProgram); glfwDestroyWindow(window); glfwTerminate(); exit(EXIT_SUCCESS); }
bool initialize() { //cout << "Makes it to initalize!" << endl; bool loadedSuccess = true; char defualtOBJName[] = "iceRink.obj"; //Change to change the default loaded object. btCollisionShape *tempShape = NULL; btDefaultMotionState *tempMotionState = NULL; btScalar tempMass; btVector3 tempInertia; btRigidBody *tempRigidBody = NULL; //Collision Masks int shapeColidesWith = COL_WALL | COL_SHAPE; int wallColidesWith = COL_SHAPE; //TABLE globalObjCount++; Vertex *geometry; btVector3 tempVect = btVector3(0.0f, 1.0f, 0.0f); btScalar planeScaler = 3; objTriMesh = new btTriangleMesh(); loadedSuccess = loadOBJ(defualtOBJName, &geometry); if ( !loadedSuccess ) { cout << "OBJ file not found or invalid format" << endl; return false; } glGenBuffers(1, &vbo_geometry); glBindBuffer(GL_ARRAY_BUFFER, vbo_geometry); glBufferData(GL_ARRAY_BUFFER, sizeof(geometry)*numberTriangles*3, geometry, GL_STATIC_DRAW); //Create collision Objects //Initalize the Hockey Table. tempShape = new btBvhTriangleMeshShape(objTriMesh, true); //Hockey Table //tempShape = new btStaticPlaneShape(tempVect, planeScaler); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0,-15,0))); tempMass = 0; tempInertia = btVector3(0.0f, 0.0f, 0.0f); tempShape->calculateLocalInertia(tempMass, tempInertia); btRigidBody::btRigidBodyConstructionInfo shapeRigidBodyCI(tempMass, tempMotionState, tempShape, tempInertia); tempRigidBody = new btRigidBody(shapeRigidBodyCI); objectsDataList.addObject(0, tempShape, tempMotionState, tempMass, tempInertia, vbo_geometry, numberTriangles, 1, tempRigidBody); dynamicsWorld->addRigidBody(tempRigidBody, COL_WALL, wallColidesWith); tempRigidBody = NULL; delete geometry; numberTriangles = 0; delete objTriMesh; objTriMesh = new btTriangleMesh(); //cout << "Makes it past loading the table!" << endl; /* //CUBE globalObjCount++; Vertex *Cube; objTriMesh = new btTriangleMesh(); btVector3 squareVect = btVector3(0.6f, 0.6f, 0.6f); loadedSuccess = loadOBJ("Cube.obj", &Cube); if ( !loadedSuccess ) { cout << "OBJ file not found or invalid format" << endl; return false; } // Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_cube); glBindBuffer(GL_ARRAY_BUFFER, vbo_cube); glBufferData(GL_ARRAY_BUFFER, sizeof(Cube)*numberTriangles*3, Cube, GL_STATIC_DRAW); //Initalize the Cube. //tempShape = new btBvhTriangleMeshShape(objTriMesh, true);//Cube tempShape = new btBoxShape(squareVect); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0.5f,4.0f,0.0f))); tempMass = 1; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(1, tempShape, tempMotionState, tempMass, tempInertia, vbo_cube, numberTriangles, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(1), COL_SHAPE, shapeColidesWith); delete Cube; numberTriangles = 0; delete objTriMesh; objTriMesh = new btTriangleMesh(); */ //CYLINDER //Paddle 1 globalObjCount++; Vertex *cylinder; btVector3 cylinderVect = btVector3(0.6f, 0.6f, 0.6f); objTriMesh = new btTriangleMesh(); loadedSuccess = loadOBJ("Paddle.obj", &cylinder); if ( !loadedSuccess ) { cout << "OBJ file not found or invalid format" << endl; return false; } // Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_cylinder); glBindBuffer(GL_ARRAY_BUFFER, vbo_cylinder); glBufferData(GL_ARRAY_BUFFER, sizeof(cylinder)*numberTriangles*3, cylinder, GL_STATIC_DRAW); //Initalize the Cylinder //tempShape = new btBvhTriangleMeshShape(objTriMesh, true); //cylinder tempShape = new btCylinderShape(cylinderVect); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(-2.0f,1.0f,2.0f))); tempMass = 1; tempInertia = btVector3(0.0f, 0.0f, 0.0f); tempShape->calculateLocalInertia(tempMass, tempInertia); btRigidBody::btRigidBodyConstructionInfo paddleOneRigidBodyCI(tempMass, tempMotionState, tempShape, tempInertia); tempRigidBody = new btRigidBody(paddleOneRigidBodyCI); objectsDataList.addObject(1, tempShape, tempMotionState, tempMass, tempInertia, vbo_cylinder, numberTriangles, .5f, tempRigidBody); dynamicsWorld->addRigidBody(tempRigidBody, COL_SHAPE, shapeColidesWith); //delete cylinder; tempRigidBody = NULL; numberTriangles = 0; delete objTriMesh; objTriMesh = new btTriangleMesh(); cout << "Loaded Paddle 1" << endl; /* //Paddle 2 globalObjCount++; Vertex *cylinder; objTriMesh = new btTriangleMesh(); loadedSuccess = loadOBJ("Paddle.obj", &cylinder); if ( !loadedSuccess ) { cout << "OBJ file not found or invalid format" << endl; return false; } Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_cylinder); glBindBuffer(GL_ARRAY_BUFFER, vbo_cylinder); glBufferData(GL_ARRAY_BUFFER, sizeof(cylinder)*numberTriangles*3, cylinder, GL_STATIC_DRAW); Initalize the Cylinder tempShape = new btBvhTriangleMeshShape(objTriMesh, true); //cylinder tempShape = new btCylinderShape(cylinderVect); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(2.0f,1.0f,2.0f))); tempMass = 1; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(2, tempShape, tempMotionState, tempMass, tempInertia, vbo_cylinder, numberTriangles, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(2), COL_SHAPE, shapeColidesWith); delete cylinder; numberTriangles = 0; delete objTriMesh; objTriMesh = new btTriangleMesh(); //SPHERE globalObjCount++; Vertex *sphere; objTriMesh = new btTriangleMesh(); btScalar sphereScaler = 1; loadedSuccess = loadOBJ("Earth.obj", &sphere); if ( !loadedSuccess ) { cout << "OBJ file not found or invalid format" << endl; return false; } // Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_sphere); glBindBuffer(GL_ARRAY_BUFFER, vbo_sphere); glBufferData(GL_ARRAY_BUFFER, sizeof(sphere)*numberTriangles*3, sphere, GL_STATIC_DRAW); //Initalize the Sphere //tempShape = new btBvhTriangleMeshShape(objTriMesh, true); //Sphere tempShape = new btSphereShape(sphereScaler); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(4.0f,1.0f,1.0f))); tempMass = 1; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(1, tempShape, tempMotionState, tempMass, tempInertia, vbo_sphere, numberTriangles, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(1), COL_SHAPE, shapeColidesWith); delete sphere; numberTriangles = 0; */ ///Walls /* globalObjCount++; btVector3 left_wall = btVector3(4.f, 4.f, 4.f); tempShape = new btBoxShape( left_wall); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(11, 0, 0.0f))); tempMass = 100; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(4, tempShape, tempMotionState, tempMass, tempInertia, 0, 1, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(4), COL_SHAPE, shapeColidesWith); globalObjCount++; btVector3 top_wall = btVector3(6.f, 6.f, 6.f); tempShape = new btBoxShape( top_wall); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0, 0, 9.5f))); tempMass = 100; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(5, tempShape, tempMotionState, tempMass, tempInertia, 0, 1, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(5), COL_SHAPE, shapeColidesWith); globalObjCount++; btVector3 bottom_wall = btVector3(6.f, 6.f, 6.f); tempShape = new btBoxShape( bottom_wall); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(0, 0, -9.f))); tempMass = 100; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(6, tempShape, tempMotionState, tempMass, tempInertia, 0, 1, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(6), COL_SHAPE, shapeColidesWith); globalObjCount++; btVector3 right_wall = btVector3(4.f, 4.f, 4.f); tempShape = new btBoxShape( right_wall); tempMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), btVector3(-7, 0, 0.0f))); tempMass = 100; tempInertia = btVector3(0.0f, 0.0f, 0.0f); objectsDataList.addObject(7, tempShape, tempMotionState, tempMass, tempInertia, 0, 1, .5f); dynamicsWorld->addRigidBody(objectsDataList.getRigidBody(7), COL_SHAPE, shapeColidesWith); */ //Clean Up //tempShape = NULL; //delete objTriMesh; //objTriMesh = NULL; tempShape = NULL; tempMotionState = NULL; //--Load vertex shader and fragment shader from 2 text files ShaderLoader loader("vertexShader.txt", "fragmentShader.txt"); program = loader.LoadShader(); //Now we set the locations of the attributes and uniforms //this allows us to access them easily while rendering loc_position = glGetAttribLocation(program, const_cast<const char*>("v_position")); if(loc_position == -1) { std::cerr << "[F] POSITION NOT FOUND" << std::endl; return false; } loc_uv = glGetAttribLocation(program, const_cast<const char*>("v_uv")); if(loc_uv == -1) { std::cerr << "[F] V_UV NOT FOUND" << std::endl; return false; } loc_mvpmat = glGetUniformLocation(program, const_cast<const char*>("mvpMatrix")); if(loc_mvpmat == -1) { std::cerr << "[F] MVPMATRIX NOT FOUND" << std::endl; return false; } //--Init the view and projection matrices // if you will be having a moving camera the view matrix will need to more dynamic // ...Like you should update it before you render more dynamic // for this project having them static will be fine view = glm::lookAt( glm::vec3(.5, 7.0, 0), //Eye Position glm::vec3(.5, 0.0, 0.0), //Focus point glm::vec3(0.0, 0.0, 1.0)); //Positive Y is up projection = glm::perspective( 45.0f, //the FoV typically 90 degrees is good which is what this is set to float(w)/float(h), //Aspect Ratio, so Circles stay Circular 0.01f, //Distance to the near plane, normally a small value like this 100.0f); //Distance to the far plane, // load texture image Magick::InitializeMagick(""); Magick::Image image; Magick::Blob m_blob; try { // Read a file into image object if ( textureFileName != "") { image.read( textureFileName ); image.flip(); image.write(&m_blob, "RGBA"); } else { throw std::invalid_argument("No texture file found"); } } catch(exception& tmp) { cout << "Error while reading in texture image, texture file not found" << endl; } int imageWidth = image.columns(); int imageHeight = image.rows(); // setup texture glGenTextures(1, &aTexture); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, aTexture); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, m_blob.data()); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); //and its done return true; }
Mesh::Mesh(const char* filePath){ loadOBJ(filePath); }
bool initialize(char* fileName) { // Initialize basic geometry and shaders for this example //this defines a cube, this is why a model loader is nice //you can also do this with a draw elements and indices, try to get that working bool geometryLoadedCorrectly = loadOBJ (fileName, geometry); if (!geometryLoadedCorrectly) { std::cerr << "[F] The Geometry Was Not Loaded Correctly!"<<std::endl; return false; } // Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_geometry); glBindBuffer(GL_ARRAY_BUFFER, vbo_geometry); glBufferData(GL_ARRAY_BUFFER, geometry.size()*sizeof(Vertex), &geometry[0], GL_STATIC_DRAW); //--Geometry done GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); // check if shaders are created if(!vertex_shader) { std::cerr << "Error creating shader vertex!" << std::endl; return false; } if(!fragment_shader) { std::cerr << "Error creating shader fragment!" << std::endl; return false; } //Shader Sources // Put these into files and write a loader in the future // Note the added uniform! shaderLoaderClass loadVertex; shaderLoaderClass loadFragment; std::string vsString = loadVertex.loadShader (vsFile); std::string fsString = loadFragment.loadShader (fsFile); const char *vs = vsString.c_str (); const char *fs = fsString.c_str (); //compile the shaders GLint shader_status; // Vertex shader first glShaderSource(vertex_shader, 1, &vs, NULL); glCompileShader(vertex_shader); //check the compile status glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &shader_status); if(!shader_status) { std::cerr << "[F] FAILED TO COMPILE VERTEX SHADER!" << std::endl; return false; } // Now the Fragment shader glShaderSource(fragment_shader, 1, &fs, NULL); glCompileShader(fragment_shader); //check the compile status glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &shader_status); if(!shader_status) { std::cerr << "[F] FAILED TO COMPILE FRAGMENT SHADER!" << std::endl; return false; } //Now we link the 2 shader objects into a program //This program is what is run on the GPU program = glCreateProgram(); glAttachShader(program, vertex_shader); glAttachShader(program, fragment_shader); glLinkProgram(program); //check if everything linked ok glGetProgramiv(program, GL_LINK_STATUS, &shader_status); if(!shader_status) { std::cerr << "[F] THE SHADER PROGRAM FAILED TO LINK" << std::endl; return false; } //Now we set the locations of the attributes and uniforms //this allows us to access them easily while rendering loc_position = glGetAttribLocation(program, const_cast<const char*>("v_position")); if(loc_position == -1) { std::cerr << "[F] POSITION NOT FOUND" << std::endl; return false; } loc_color = glGetAttribLocation(program, const_cast<const char*>("v_color")); if(loc_color == -1) { std::cerr << "[F] V_COLOR NOT FOUND" << std::endl; return false; } loc_mvpmat = glGetUniformLocation(program, const_cast<const char*>("mvpMatrix")); if(loc_mvpmat == -1) { std::cerr << "[F] MVPMATRIX NOT FOUND" << std::endl; return false; } //--Init the view and projection matrices // if you will be having a moving camera the view matrix will need to more dynamic // ...Like you should update it before you render more dynamic // for this project having them static will be fine view = glm::lookAt( glm::vec3(0.0, 8.0, -16.0), //Eye Position glm::vec3(0.0, 0.0, 0.0), //Focus point glm::vec3(0.0, 1.0, 0.0)); //Positive Y is up projection = glm::perspective( 45.0f, //the FoV typically 90 degrees is good which is what this is set to float(w)/float(h), //Aspect Ratio, so Circles stay Circular 0.01f, //Distance to the near plane, normally a small value like this 100.0f); //Distance to the far plane, //enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); //and its done return true; }
bool loadOBJ(const char *path, Object &obj) { return loadOBJ(path, obj.vertices, obj.uvs, obj.vertices); }
/* construct sphere-tree for the model */ bool constructTree(const boost::filesystem::path& input_file, bool toYAML) { boost::filesystem::path output_file = input_file.parent_path () / boost::filesystem::basename (input_file); if (toYAML) output_file += "-spawn.yml"; else output_file += "-spawn.sph"; printf("Input file: %s\n", input_file.c_str ()); printf("Output file: %s\n\n", output_file.c_str ()); /* load the surface model */ Surface sur; bool loaded = false; std::string extension = boost::algorithm::to_lower_copy (input_file.extension ().string ()); if (extension == ".obj") loaded = loadOBJ(&sur, input_file.c_str ()); else loaded = sur.loadSurface(input_file.c_str ()); if (!loaded){ printf("ERROR : Unable to load input file (%s)\n\n", input_file.c_str ()); return false; } /* scale box */ // FIXME: Disable scaling for now (wrong result if a transformation is applied after) //float boxScale = sur.fitIntoBox(1000); float boxScale = 1.; /* make medial tester */ MedialTester mt; mt.setSurface(sur); mt.useLargeCover = true; /* setup evaluator */ SEConvex convEval; convEval.setTester(mt); SEBase *eval = &convEval; Array<Point3D> sphPts; SESphPt sphEval; if (testerLevels > 0){ // <= 0 will use convex tester SSIsohedron::generateSamples(&sphPts, testerLevels-1); sphEval.setup(mt, sphPts); eval = &sphEval; printf("Using concave tester (%d)\n\n", sphPts.getSize()); } /* verify model */ if (verify){ bool ok = verifyModel(sur); if (!ok){ printf("ERROR : model is not usable\n\n"); return false; } } /* setup for the set of cover points */ Array<Surface::Point> coverPts; MSGrid::generateSamples(&coverPts, numCoverPts, sur, TRUE, minCoverPts); printf("%d cover points\n", coverPts.getSize()); /* setup SPAWN algorithm */ SRSpawn spawn; spawn.setup(mt); spawn.useIterativeSelect = false; spawn.eval = eval; /* setup SphereTree constructor - using dynamic construction */ STGGeneric treegen; treegen.eval = eval; treegen.useRefit = true; treegen.setSamples(coverPts); treegen.reducer = &spawn; /* make sphere-tree */ SphereTree tree; tree.setupTree(branch, depth+1); waitForKey(); treegen.constructTree(&tree); /* save sphere-tree */ if (tree.saveSphereTree(output_file, 1.0f/boxScale)){ Array<LevelEval> evals; if (eval){ evaluateTree(&evals, tree, eval); writeEvaluation(stdout, evals); } if (!yaml) { FILE *f = fopen(output_file.c_str (), "a"); if (f){ fprintf(f, "\n\n"); fprintf(f, "Options : \n"); writeParam(stdout, intParams); writeParam(stdout, boolParams); fprintf(f, "\n\n"); writeEvaluation(f, evals); fclose(f); } } return true; } else{ return false; } }
int main( void ) { crap::audiodevice audio_device; /* openalcode */ //setup window crap::window_setup win_setup; win_setup.title = "Funny Window"; win_setup.width = 1024; win_setup.height = 768; win_setup.multisampling_count = 8; win_setup.opengl_version = 3.3f; win_setup.opengl_profile = crap::compat; //create window crap::window window( win_setup ); window.open(); //get keyboard and mouse crap::keyboard keyboard; crap::mouse mouse; // temporary crap::opengl::enable(crap::opengl::depth_test); crap::opengl::setDepthComparison(crap::opengl::less); crap::opengl::enable(crap::opengl::cull_face); //camera setup camera cam; cam.setPosition( glm::vec3( 0.0f, 0.0f, 5.0f ) ); mouse_pos = mouse.position(); //create contentmanager content_manager cm; cm.init( "spg.ini" ); //create vertex array crap::vertex_array vert_array; vert_array.bind(); //test: load vbo onto GPU vbo cube_vbo( "cube", &cm, vbo::static_draw ); vbo ape_vbo("ape", &cm, vbo::static_draw ); vbo cube_big_vbo( "cube", &cm, vbo::static_draw ); //vbo people_vbo("people", &cm, vbo::static_draw ); ////////////////////////// // Read our .obj file std::vector<glm::vec3> vertices; std::vector<glm::vec2> uvs; std::vector<glm::vec3> normals; bool res = loadOBJ("../../../data/geometry/dupercube.obj", vertices, uvs, normals); std::vector<glm::vec3> tangents; std::vector<glm::vec3> bitangents; computeTangentBasis( vertices, uvs, normals, // input tangents, bitangents // output ); std::vector<unsigned short> indices; std::vector<glm::vec3> indexed_vertices; std::vector<glm::vec2> indexed_uvs; std::vector<glm::vec3> indexed_normals; std::vector<glm::vec3> indexed_tangents; std::vector<glm::vec3> indexed_bitangents; indexVBO_TBN( vertices, uvs, normals, tangents, bitangents, indices, indexed_vertices, indexed_uvs, indexed_normals, indexed_tangents, indexed_bitangents ); GLuint vertexbuffer; glGenBuffers(1, &vertexbuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); glBufferData(GL_ARRAY_BUFFER, indexed_vertices.size() * sizeof(glm::vec3), &indexed_vertices[0], GL_STATIC_DRAW); GLuint uvbuffer; glGenBuffers(1, &uvbuffer); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); glBufferData(GL_ARRAY_BUFFER, indexed_uvs.size() * sizeof(glm::vec2), &indexed_uvs[0], GL_STATIC_DRAW); GLuint normalbuffer; glGenBuffers(1, &normalbuffer); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); glBufferData(GL_ARRAY_BUFFER, indexed_normals.size() * sizeof(glm::vec3), &indexed_normals[0], GL_STATIC_DRAW); GLuint tangentbuffer; glGenBuffers(1, &tangentbuffer); glBindBuffer(GL_ARRAY_BUFFER, tangentbuffer); glBufferData(GL_ARRAY_BUFFER, indexed_tangents.size() * sizeof(glm::vec3), &indexed_tangents[0], GL_STATIC_DRAW); GLuint bitangentbuffer; glGenBuffers(1, &bitangentbuffer); glBindBuffer(GL_ARRAY_BUFFER, bitangentbuffer); glBufferData(GL_ARRAY_BUFFER, indexed_bitangents.size() * sizeof(glm::vec3), &indexed_bitangents[0], GL_STATIC_DRAW); // Generate a buffer for the indices as well GLuint elementbuffer; glGenBuffers(1, &elementbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, elementbuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned short), &indices[0], GL_STATIC_DRAW); ///////////////////////// geometry_content ig; cm.create_content( "cube" , &ig, type_name::geometry ); //test: load texture onto GPU tbo diffuse_tbo( "stone_diff", &cm, tbo::tga ); tbo normal_tbo( "stone_norm", &cm, tbo::tga ); tbo height_tbo( "stone_height", &cm, tbo::tga ); //shadow stuff crap::frame_buffer frame_buffer; frame_buffer.bind(); tbo depthmap( "", &cm, tbo::depth ); frame_buffer.unbind(); //shadow stuff crap::quad_buffer quad_buffer; //test: load linked shader progam onto GPU shader_manager sm(&cm); sm.add("epr_vert", "epr_frag"); sm.add("shadow_vert", "shadow_frag"); //get stuff from shader program //shadow shader sm.set_current("shadow_vert", "shadow_frag"); crap::uniform DepthBiasMVPID = sm.current()->uniform_location("depthMVP"); //vertex shader sm.set_current("epr_vert", "epr_frag"); crap::uniform WorldMatrixID = sm.current()->uniform_location("world_matrix4x4"); crap::uniform ViewMatrixID = sm.current()->uniform_location("view_matrix4x4"); crap::uniform ModelMatrixID = sm.current()->uniform_location("model_matrix4x4"); crap::uniform ModelView3x3MatrixID = sm.current()->uniform_location("model_view_matrix3x3"); //fragment shader crap::uniform DiffuseTextureID = sm.current()->uniform_location("diffuse_texture"); crap::uniform NormalTextureID = sm.current()->uniform_location("normal_texture"); crap::uniform HeightTextureID = sm.current()->uniform_location("height_texture"); crap::uniform LightAmbientPowerID = sm.current()->uniform_location("ambient_power"); crap::uniform LightPowerArrayID = sm.current()->uniform_location("light_power"); crap::uniform LightSpecularTypeArrayID = sm.current()->uniform_location("light_specular_type"); crap::uniform LightSpecularLobeArrayID = sm.current()->uniform_location("light_specular_lobe"); crap::uniform LightColorArrayID = sm.current()->uniform_location("light_color"); crap::uniform LightSelfShadowingOnID = sm.current()->uniform_location("selfshadowing_on"); crap::uniform DisplacementOnID = sm.current()->uniform_location("displacement_on"); crap::uniform DisplacementStepsID = sm.current()->uniform_location("displacement_steps"); crap::uniform DisplacementRefinementStepsID = sm.current()->uniform_location("displacement_refinement_steps"); crap::uniform DisplacementUVFactorID = sm.current()->uniform_location("displacement_uv_factor"); //both shaders crap::uniform LightPositionArrayID = sm.current()->uniform_location("light_position"); crap::uniform LightDirectionArrayID = sm.current()->uniform_location("light_direction"); crap::uniform LightTypeArrayID = sm.current()->uniform_location("light_type"); crap::uniform LightStateArrayID = sm.current()->uniform_location("light_state"); crap::uniform LightNormalMappingOnID = sm.current()->uniform_location("normal_mapping_on"); //shadow stuff crap::uniform ShadowMapID = sm.current()->uniform_location("shadow_map"); crap::uniform ShadowMappingOnID = sm.current()->uniform_location("shadow_mapping_on"); crap::uniform ShadowDepthBiasMVPID = sm.current()->uniform_location("depth_bias_mvp"); //SHADER DATA // Projection matrix : 60° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units float display_field_of_view = 60.f; //60° float display_ratio_horizontal = 4.f; float display_ratio_vertical = 3.f; float display_range_near = 0.1f; float display_range_far = 100.f; glm::mat4 projection_matrix = glm::perspective( display_field_of_view, display_ratio_horizontal / display_ratio_vertical, display_range_near, display_range_far); glm::mat4 model_matrix(1.0f); glm::mat4 model_view_matrix(1.0f); glm::mat4 view_matrix = cam.view(); glm::mat4 world_matrix(1.0f); glm::mat3 model_view_matrix3x3(1.0f); //light stuff float light_ambient_power = 0.5f; float light_power_array[MAX_LIGHTS] = { 1.f, 1.f, 1.f }; int light_specular_type_array[MAX_LIGHTS] = { 1, 1, 1 }; float light_specular_lobe_array[MAX_LIGHTS] = { 100.f, 100.f, 100.f }; glm::vec3 light_color_array[MAX_LIGHTS] = { glm::vec3(1.f), glm::vec3(1.f), glm::vec3(1.f) }; int light_self_shadowing_on = 1; glm::vec3 light_position_array[MAX_LIGHTS] = { glm::vec3(4,0,0), glm::vec3(0,0,-4), glm::vec3(4,4,4) }; glm::vec3 light_direction_array[MAX_LIGHTS] = { glm::vec3(-4,0,0), glm::vec3(0,0,4), glm::vec3(-4,-4,-4) }; int light_type_array[MAX_LIGHTS] = { 0, 0, 0 }; int light_state_array[MAX_LIGHTS] = { 1, 0, 0 }; int light_normal_mapping_on = 1; //shadowstuff int shadow_mapping_on = 1; //displacement stuff int displacement_on = 1; float displacement_steps = 20; float displacement_refinement_steps = 20; float displacmenet_uv_factor = 20; //GUI TwInit(TW_OPENGL, NULL); TwWindowSize(1024, 768); TwBar * GeneralGUI = TwNewBar("General settings"); TwBar * LightGUI = TwNewBar("Light Settings"); TwBar * DisplacementGUI = TwNewBar("Displacement Settings"); TwSetParam(GeneralGUI, NULL, "refresh", TW_PARAM_CSTRING, 1, "0.1"); TwSetParam(LightGUI, NULL, "refresh", TW_PARAM_CSTRING, 1, "0.1"); TwSetParam(DisplacementGUI, NULL, "refresh", TW_PARAM_CSTRING, 1, "0.1"); //general gui TwAddSeparator(GeneralGUI, "Funny seperator", NULL); TwAddVarRW(GeneralGUI, "Field of View", TW_TYPE_FLOAT , &display_field_of_view, "help='Field of View value'"); TwAddVarRW(GeneralGUI, "Ratio Horizontal", TW_TYPE_FLOAT , &display_ratio_horizontal, "help='Ratio Horizontal'"); TwAddVarRW(GeneralGUI, "Ratio Vertical", TW_TYPE_FLOAT , &display_ratio_vertical, "help='Ratio Vertical'"); TwAddVarRW(GeneralGUI, "Range Near", TW_TYPE_FLOAT , &display_range_near, "help='Range near'"); TwAddVarRW(GeneralGUI, "Range far", TW_TYPE_FLOAT , &display_range_far, "help='Range far'"); //light gui TwAddVarRW(LightGUI, "Ambient light", TW_TYPE_FLOAT , &light_ambient_power, "help='Ambient power'"); TwAddVarRW(LightGUI, "Self Shadowing", TW_TYPE_BOOL32, &light_self_shadowing_on, NULL); TwAddVarRW(LightGUI, "Normal Mapping", TW_TYPE_BOOL32, &light_normal_mapping_on, NULL); TwType gui_light_type = TwDefineEnumFromString("LightType", "Directionallight,Pointlight"); TwType gui_light_specular_type = TwDefineEnumFromString("LightSpecularType", "Blinn,Phong"); //shadow TwAddVarRW(LightGUI, "Cast Shadows", TW_TYPE_BOOL32, &shadow_mapping_on, NULL); //light1 TwAddVarRW(LightGUI, "Light 1", TW_TYPE_BOOL32, light_state_array, NULL); TwAddVarRW(LightGUI, "Light Type 1", gui_light_type, light_type_array, NULL); TwAddVarRW(LightGUI, "Light Specular Type 1", gui_light_specular_type, light_specular_type_array, NULL); TwAddVarRW(LightGUI, "Light Power 1", TW_TYPE_FLOAT , light_power_array, NULL); TwAddVarRW(LightGUI, "Light Specular Lobe 1", TW_TYPE_FLOAT , light_specular_lobe_array, NULL); TwAddVarRW(LightGUI, "Light Color 1", TW_TYPE_COLOR3F , light_color_array, NULL); TwAddVarRW(LightGUI, "Light Position 1", TW_TYPE_DIR3F , light_position_array, NULL); TwAddVarRW(LightGUI, "Light Direction 1", TW_TYPE_DIR3F , light_direction_array, NULL); //light2 TwAddVarRW(LightGUI, "Light 2", TW_TYPE_BOOL32, light_state_array+1, NULL); TwAddVarRW(LightGUI, "Light Type 2", gui_light_type, light_type_array+1, NULL); TwAddVarRW(LightGUI, "Light Specular Type 2", gui_light_specular_type, light_specular_type_array+1, NULL); TwAddVarRW(LightGUI, "Light Power 2", TW_TYPE_FLOAT , light_power_array+1, NULL); TwAddVarRW(LightGUI, "Light Specular Lobe 2", TW_TYPE_FLOAT , light_specular_lobe_array+1, NULL); TwAddVarRW(LightGUI, "Light Color 2", TW_TYPE_COLOR3F , light_color_array+1, NULL); TwAddVarRW(LightGUI, "Light Position 2", TW_TYPE_DIR3F , light_position_array+1, NULL); TwAddVarRW(LightGUI, "Light Direction 2", TW_TYPE_DIR3F , light_direction_array+1, NULL); //light3 TwAddVarRW(LightGUI, "Light 3", TW_TYPE_BOOL32, light_state_array+2, NULL); TwAddVarRW(LightGUI, "Light Type 3", gui_light_type, light_type_array+2, NULL); TwAddVarRW(LightGUI, "Light Specular Type 3", gui_light_specular_type, light_specular_type_array+2, NULL); TwAddVarRW(LightGUI, "Light Power 3", TW_TYPE_FLOAT , light_power_array+2, NULL); TwAddVarRW(LightGUI, "Light Specular Lobe 3", TW_TYPE_FLOAT , light_specular_lobe_array+2, NULL); TwAddVarRW(LightGUI, "Light Color 3", TW_TYPE_COLOR3F , light_color_array+2, NULL); TwAddVarRW(LightGUI, "Light Position 3", TW_TYPE_DIR3F , light_position_array+2, NULL); TwAddVarRW(LightGUI, "Light Direction 3", TW_TYPE_DIR3F , light_direction_array+2, NULL); //displacement gui TwAddVarRW(DisplacementGUI, "Displacement ON/OFF", TW_TYPE_BOOL32, &displacement_on, NULL); TwAddVarRW(DisplacementGUI, "Displacment steps", TW_TYPE_FLOAT , &displacement_steps, NULL); TwAddVarRW(DisplacementGUI, "Displacement refinement", TW_TYPE_FLOAT , &displacement_refinement_steps, NULL); TwAddVarRW(DisplacementGUI, "Displacement UV factor", TW_TYPE_FLOAT , &displacmenet_uv_factor, NULL); //gui mouse setup mouse.set_on_pressed_function( (crap::mouse::user_button_callback_function)gui_mouse_down ); mouse.set_on_release_function( (crap::mouse::user_button_callback_function)gui_mouse_up ); mouse.set_on_move_function( (crap::mouse::user_move_callback_function)TwEventMousePosGLFW ); mouse.set_on_wheel_function( (crap::mouse::user_wheel_callback_function)TwEventMouseWheelGLFW ); keyboard.set_on_pressed_function( (crap::keyboard::user_callback_function)TwEventKeyGLFW ); //todo set char input // temporary crap::opengl::clearColor(1.0f, 1.0f, 1.0f, 0.0f); while( !keyboard.is_pressed( crap::keyboard::key_escape ) && window.is_open() ) { // update positions handleInput(keyboard, mouse, cam); crap::opengl::clear(crap::opengl::color_depth_buffer); frame_buffer.bind(); glViewport(0,0,1024,1024); // Render on the whole framebuffer, complete from the lower left corner to the upper right sm.set_current("shadow_vert", "shadow_frag"); sm.activate(); glm::vec3 lightInvDir = light_direction_array[0]; //glm::vec3(0.5f,2,2); // Compute the MVP matrix from the light's point of view glm::mat4 depthProjectionMatrix = glm::ortho<float>(-10,10,-10,10,-10,20); glm::mat4 depthViewMatrix = glm::lookAt(lightInvDir, glm::vec3(0,0,0), glm::vec3(0,1,0)); glm::mat4 depthModelMatrix = glm::mat4(1.0); glm::mat4 depthMVP = depthProjectionMatrix * depthViewMatrix * depthModelMatrix; sm.current()->uniform_matrix4f_value( DepthBiasMVPID, 1, &depthMVP[0][0]); sm.current()->vertex_attribute_array.enable(0); cube_vbo.bind_buffer( vbo::verticies ); sm.current()->vertex_attribute_array.pointer( 0, 3, crap::gl_float, false, 0, (void*)0); cube_vbo.bind_buffer( vbo::indicies ); crap::opengl::draw_elements( crap::opengl::triangles, // mode cube_vbo.indicies_size, // count crap::opengl::unsigned_short // type ); sm.current()->vertex_attribute_array.disable(0); frame_buffer.unbind(); glViewport(0,0,1024,768); // Render on the whole framebuffer, complete from the lower left corner to the upper right crap::opengl::clear(crap::opengl::color_depth_buffer); sm.set_current("epr_vert", "epr_frag"); sm.activate(); /////////////////////////////////////// ////////////////////////////////////// projection_matrix = glm::perspective( display_field_of_view, display_ratio_horizontal / display_ratio_vertical, display_range_near, display_range_far); view_matrix = cam.view(); model_view_matrix = view_matrix * world_matrix; model_view_matrix3x3 = glm::mat3(model_view_matrix); world_matrix = projection_matrix * view_matrix * model_matrix; glm::mat4 biasMatrix( 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.0, 0.5, 0.0, 0.5, 0.5, 0.5, 1.0 ); glm::mat4 depthBiasMVP = biasMatrix*depthMVP; sm.current()->uniform_matrix4f_value( ShadowDepthBiasMVPID, 1, &depthBiasMVP[0][0]); sm.current()->uniform_1i(ShadowMappingOnID, shadow_mapping_on); //activate shader porgram and connect data //sm.activate(); //default stuff sm.current()->uniform_matrix4f_value( WorldMatrixID, 1, &world_matrix[0][0]); sm.current()->uniform_matrix4f_value( ModelMatrixID, 1, &model_matrix[0][0]); sm.current()->uniform_matrix4f_value( ViewMatrixID, 1, &view_matrix[0][0]); sm.current()->uniform_matrix3f_value( ModelView3x3MatrixID, 1, &model_view_matrix3x3[0][0]); //light sm.activate(); sm.current()->uniform_1f(LightAmbientPowerID, light_ambient_power); sm.current()->uniform_1i(LightSelfShadowingOnID, light_self_shadowing_on); sm.current()->uniform_1i(LightNormalMappingOnID, light_normal_mapping_on); sm.current()->uniform_1f_value( LightPowerArrayID, 3, light_power_array ); sm.current()->uniform_1i_value( LightSpecularTypeArrayID, 3, light_specular_type_array ); sm.current()->uniform_1f_value( LightSpecularLobeArrayID, 3, light_specular_lobe_array ); sm.current()->uniform_3f_value( LightColorArrayID, 3, (f32*)light_color_array ); sm.current()->uniform_3f_value( LightPositionArrayID, 3, (f32*)light_position_array ); sm.current()->uniform_3f_value( LightDirectionArrayID, 3, (f32*)light_direction_array ); sm.current()->uniform_1i_value( LightTypeArrayID, 3, light_type_array ); sm.current()->uniform_1i_value( LightStateArrayID, 3, light_state_array ); //displacement sm.current()->uniform_1i( DisplacementOnID, displacement_on ); sm.current()->uniform_1f( DisplacementStepsID, displacement_steps); sm.current()->uniform_1f( DisplacementRefinementStepsID, displacement_refinement_steps); sm.current()->uniform_1f( DisplacementUVFactorID, displacmenet_uv_factor); //activate texture buffer and connect data diffuse_tbo.activate(); diffuse_tbo.bind_buffer(); sm.current()->uniform_1i( DiffuseTextureID, 0); normal_tbo.activate(); normal_tbo.bind_buffer(); sm.current()->uniform_1i( NormalTextureID, 1); height_tbo.activate(); height_tbo.bind_buffer(); sm.current()->uniform_1i( HeightTextureID, 2 ); depthmap.activate(); depthmap.bind_buffer(); sm.current()->uniform_1i( ShadowMapID, 4); //define data of buffers sm.current()->vertex_attribute_array.enable(0); //cube_vbo.bind_buffer( vbo::verticies ); glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer); sm.current()->vertex_attribute_array.pointer( 0, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(1); glBindBuffer(GL_ARRAY_BUFFER, uvbuffer); //cube_vbo.bind_buffer( vbo::uvs ); sm.current()->vertex_attribute_array.pointer( 1, 2, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(2); glBindBuffer(GL_ARRAY_BUFFER, normalbuffer); //cube_vbo.bind_buffer( vbo::normals ); sm.current()->vertex_attribute_array.pointer( 2, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(3); glBindBuffer(GL_ARRAY_BUFFER, tangentbuffer); //cube_vbo.bind_buffer( vbo::tangents ); sm.current()->vertex_attribute_array.pointer( 3, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(4); glBindBuffer(GL_ARRAY_BUFFER, bitangentbuffer); //cube_vbo.bind_buffer( vbo::binormals ); sm.current()->vertex_attribute_array.pointer( 4, 3, crap::gl_float, false, 0, (void*)0); ////draw the f**k cube_vbo.bind_buffer( vbo::indicies ); crap::opengl::draw_elements( crap::opengl::triangles, // mode cube_vbo.indicies_size, // count crap::opengl::unsigned_short // type ); sm.current()->vertex_attribute_array.disable(0); sm.current()->vertex_attribute_array.disable(1); sm.current()->vertex_attribute_array.disable(2); sm.current()->vertex_attribute_array.disable(3); sm.current()->vertex_attribute_array.disable(4); //next object glm::mat4 model_matrix_2 = model_matrix * glm::translate(3.f,0.f,0.f); model_view_matrix = view_matrix * model_matrix_2; model_view_matrix3x3 = glm::mat3(model_view_matrix); world_matrix = projection_matrix * view_matrix * model_matrix_2; //activate shader porgram and connect data //sm.activate(); sm.current()->uniform_matrix4f_value( WorldMatrixID, 1, &world_matrix[0][0]); sm.current()->uniform_matrix4f_value( ModelMatrixID, 1, &model_matrix_2[0][0]); sm.current()->uniform_matrix3f_value( ModelView3x3MatrixID, 1, &model_view_matrix3x3[0][0]); //attempt //define data of buffers sm.current()->vertex_attribute_array.enable(0); ape_vbo.bind_buffer( vbo::verticies ); sm.current()->vertex_attribute_array.pointer( 0, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(1); ape_vbo.bind_buffer( vbo::uvs ); sm.current()->vertex_attribute_array.pointer( 1, 2, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(2); ape_vbo.bind_buffer( vbo::normals ); sm.current()->vertex_attribute_array.pointer( 2, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(3); ape_vbo.bind_buffer( vbo::tangents ); sm.current()->vertex_attribute_array.pointer(3, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(4); ape_vbo.bind_buffer( vbo::binormals ); sm.current()->vertex_attribute_array.pointer( 4, 3, crap::gl_float, false, 0, (void*)0); //draw the f**k ape_vbo.bind_buffer( vbo::indicies ); crap::opengl::draw_elements( crap::opengl::triangles, // mode ape_vbo.indicies_size, // count crap::opengl::unsigned_short // type ); //disable data define stuff sm.current()->vertex_attribute_array.disable(0); sm.current()->vertex_attribute_array.disable(1); sm.current()->vertex_attribute_array.disable(2); sm.current()->vertex_attribute_array.disable(3); sm.current()->vertex_attribute_array.disable(4); //next object glm::mat4 model_matrix_3 = model_matrix * glm::translate(0.f,-2.f,0.f); model_view_matrix = view_matrix * model_matrix_2; model_view_matrix3x3 = glm::mat3(model_view_matrix); world_matrix = projection_matrix * view_matrix * model_matrix_3; //activate shader porgram and connect data //sm.activate(); sm.current()->uniform_matrix4f_value( WorldMatrixID, 1, &world_matrix[0][0]); sm.current()->uniform_matrix4f_value( ModelMatrixID, 1, &model_matrix_3[0][0]); sm.current()->uniform_matrix3f_value( ModelView3x3MatrixID, 1, &model_view_matrix3x3[0][0]); //attempt //define data of buffers sm.current()->vertex_attribute_array.enable(0); cube_big_vbo.bind_buffer( vbo::verticies ); sm.current()->vertex_attribute_array.pointer( 0, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(1); cube_big_vbo.bind_buffer( vbo::uvs ); sm.current()->vertex_attribute_array.pointer( 1, 2, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(2); cube_big_vbo.bind_buffer( vbo::normals ); sm.current()->vertex_attribute_array.pointer( 2, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(3); cube_big_vbo.bind_buffer( vbo::tangents ); sm.current()->vertex_attribute_array.pointer(3, 3, crap::gl_float, false, 0, (void*)0); sm.current()->vertex_attribute_array.enable(4); cube_big_vbo.bind_buffer( vbo::binormals ); sm.current()->vertex_attribute_array.pointer( 4, 3, crap::gl_float, false, 0, (void*)0); //draw the f**k cube_big_vbo.bind_buffer( vbo::indicies ); crap::opengl::draw_elements( crap::opengl::triangles, // mode cube_big_vbo.indicies_size, // count crap::opengl::unsigned_short // type ); //disable data define stuff sm.current()->vertex_attribute_array.disable(0); sm.current()->vertex_attribute_array.disable(1); sm.current()->vertex_attribute_array.disable(2); sm.current()->vertex_attribute_array.disable(3); sm.current()->vertex_attribute_array.disable(4); glMatrixMode(GL_PROJECTION); glLoadMatrixf((const GLfloat*)&projection_matrix[0]); glMatrixMode(GL_MODELVIEW); glm::mat4 MV = view_matrix * model_matrix; glLoadMatrixf((const GLfloat*)&MV[0]); sm.activate(); // normals glColor3f(0,0,1); glBegin(GL_LINES); for (unsigned int i=0; i<ig.indices_size; i++){ glm::vec3 p = glm::vec3(ig.positions[ig.indices[i]].x, ig.positions[ig.indices[i]].y, ig.positions[ig.indices[i]].z ); glVertex3fv(&p.x); glm::vec3 o = glm::normalize( glm::vec3(ig.normals[ig.indices[i]].x, ig.normals[ig.indices[i]].y, ig.normals[ig.indices[i]].z) ); p+=o*0.1f; glVertex3fv(&p.x); } glEnd(); // tangents glColor3f(1,0,0); glBegin(GL_LINES); for (unsigned int i=0; i<ig.indices_size; i++){ glm::vec3 p = glm::vec3(ig.positions[ig.indices[i]].x, ig.positions[ig.indices[i]].y, ig.positions[ig.indices[i]].z ); glVertex3fv(&p.x); glm::vec3 o = glm::normalize( glm::vec3(ig.tangents[ig.indices[i]].x, ig.tangents[ig.indices[i]].y, ig.tangents[ig.indices[i]].z) ); p+=o*0.1f; glVertex3fv(&p.x); } glEnd(); // bitangents glColor3f(0,1,0); glBegin(GL_LINES); for (unsigned int i=0; i<ig.indices_size; i++){ glm::vec3 p = glm::vec3(ig.positions[ig.indices[i]].x, ig.positions[ig.indices[i]].y, ig.positions[ig.indices[i]].z ); glVertex3fv(&p.x); glm::vec3 o = glm::normalize( glm::vec3(ig.binormals[ig.indices[i]].x, ig.binormals[ig.indices[i]].y, ig.binormals[ig.indices[i]].z) ); p+=o*0.1f; glVertex3fv(&p.x); } glEnd(); glm::vec3 debug_light; // light pos 1 glColor3f(1,1,1); glBegin(GL_LINES); debug_light = light_position_array[0]; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light-=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(0,1,0)*0.1f; glVertex3fv(&debug_light.x); glEnd(); // light pos 2 glColor3f(1,1,1); glBegin(GL_LINES); debug_light = light_position_array[1]; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light-=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(0,1,0)*0.1f; glVertex3fv(&debug_light.x); glEnd(); // light pos3 glColor3f(1,1,1); glBegin(GL_LINES); debug_light = light_position_array[2]; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light-=glm::vec3(1,0,0)*0.1f; glVertex3fv(&debug_light.x); debug_light+=glm::vec3(0,1,0)*0.1f; glVertex3fv(&debug_light.x); glEnd(); // Draw GUI TwDraw(); //poll and swap window.swap(); window.poll_events(); } TwTerminate(); //geometry_content ig; //cm.create_content( "ape" , &ig, type_name::geometry ); //texture_content tc; //cm.create_content( "color", &tc, type_name::texture ); //shader_content sc; //cm.create_content( "fragment_texture_only", &sc, type_name::shader ); //cm.save_content( "fragment_texture_only", &sc, type_name::shader ); return 0; }
bool initialize(){ //loading texture GLuint tex; GLint uniform_text; glGenTextures(1, &tex); float color[] = { 0.0f, 0.0f, 0.0f, 0.0f}; glBindTexture(GL_TEXTURE_2D, tex); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, res_text.width, res_text.height, 0, GL_RGB, GL_UNSIGNED_BYTE, res_texture.pixel_data); // Initialize basic geometry and shaders for this example Vertex* geometry = loadOBJ(fname); // Create a Vertex Buffer object to store this vertex info on the GPU glGenBuffers(1, &vbo_geometry); glBindBuffer(GL_ARRAY_BUFFER, vbo_geometry); glBufferData(GL_ARRAY_BUFFER, numOfVert * sizeof(Vertex), geometry, GL_STATIC_DRAW); //--Geometry done GLuint vertex_shader = glCreateShader(GL_VERTEX_SHADER); GLuint fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); //Shader Sources // Put these into files and write a loader in the future // Note the added uniform! const char *vs; vs = shaderLoader("vertexShader"); const char *fs; fs = shaderLoader("fragmentShader"); //compile the shaders GLint shader_status; // Vertex shader first glShaderSource(vertex_shader, 1, &vs, NULL); glCompileShader(vertex_shader); //check the compile status glGetShaderiv(vertex_shader, GL_COMPILE_STATUS, &shader_status); if(!shader_status){ std::cerr << "[F] FAILED TO COMPILE VERTEX SHADER!" << std::endl; return false; } // Now the Fragment shader glShaderSource(fragment_shader, 1, &fs, NULL); glCompileShader(fragment_shader); //check the compile status glGetShaderiv(fragment_shader, GL_COMPILE_STATUS, &shader_status); if(!shader_status){ std::cerr << "[F] FAILED TO COMPILE FRAGMENT SHADER!" << std::endl; return false; } //Now we link the 2 shader objects into a program //This program is what is run on the GPU program = glCreateProgram(); glAttachShader(program, vertex_shader); glAttachShader(program, fragment_shader); glLinkProgram(program); //check if everything linked ok glGetProgramiv(program, GL_LINK_STATUS, &shader_status); if(!shader_status){ std::cerr << "[F] THE SHADER PROGRAM FAILED TO LINK" << std::endl; return false; } //Now we set the locations of the attributes and uniforms //this allows us to access them easily while rendering loc_position = glGetAttribLocation(program, const_cast<const char*>("v_position")); if(loc_position == -1){ std::cerr << "[F] POSITION NOT FOUND" << std::endl; return false; } loc_color = glGetAttribLocation(program, const_cast<const char*>("v_color")); if(loc_color == -1){ std::cerr << "[F] V_COLOR NOT FOUND" << std::endl; return false; } loc_mvpmat = glGetUniformLocation(program, const_cast<const char*>("mvpMatrix")); if(loc_mvpmat == -1){ std::cerr << "[F] MVPMATRIX NOT FOUND" << std::endl; return false; } //--Init the view and projection matrices // if you will be having a moving camera the view matrix will need to more dynamic // ...Like you should update it before you render more dynamic // for this project having them static will be fine view = glm::lookAt( glm::vec3(0.0, 8.0, -16.0), //Eye Position glm::vec3(0.0, 0.0, 0.0), //Focus point glm::vec3(0.0, 1.0, 0.0)); //Positive Y is up projection = glm::perspective( 45.0f, //the FoV typically 90 degrees is good which is what this is set to float(w)/float(h), //Aspect Ratio, so Circles stay Circular 0.01f, //Distance to the near plane, normally a small value like this 100.0f); //Distance to the far plane, //enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); //and its done return true; }
/* main function in embree namespace */ int main(int argc, char** argv) { /* for best performance set FTZ and DAZ flags in MXCSR control and status register */ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); /* create stream for parsing */ Ref<ParseStream> stream = new ParseStream(new CommandLineStream(argc, argv)); /* parse command line */ parseCommandLine(stream, FileName()); /* load default scene if none specified */ if (filename.ext() == "") { FileName file = FileName::executableFolder() + FileName("models/cornell_box.ecs"); parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path()); } /* configure number of threads */ if (g_numThreads) g_rtcore += ",threads=" + std::to_string((long long)g_numThreads); if (g_numBenchmarkFrames) g_rtcore += ",benchmark=1"; g_rtcore += g_subdiv_mode; /* load scene */ if (strlwr(filename.ext()) == std::string("obj")) { if (g_subdiv_mode != "") { std::cout << "enabling subdiv mode" << std::endl; loadOBJ(filename,one,g_obj_scene,true); } else loadOBJ(filename,one,g_obj_scene); } else if (strlwr(filename.ext()) == std::string("xml")) loadXML(filename,one,g_obj_scene); else if (filename.ext() != "") THROW_RUNTIME_ERROR("invalid scene type: "+strlwr(filename.ext())); /* initialize ray tracing core */ init(g_rtcore.c_str()); /* send model */ set_scene(&g_obj_scene); /* benchmark mode */ if (g_numBenchmarkFrames) renderBenchmark(outFilename); /* render to disk */ if (outFilename.str() != "") renderToFile(outFilename); /* interactive mode */ if (g_interactive) { initWindowState(argc,argv,tutorialName, g_width, g_height, g_fullscreen); enterWindowRunLoop(); } return 0; }
void Renderer::build() { _vp.s = 0.0625; _vp.width = 640; _vp.height = 480; _vp.numSamples = 4; auto sphere1 = std::make_shared<Sphere>(P3d(1e5 + 1.0, 40.8, 81.6), 1e5); auto sphere2 = std::make_shared<Sphere>(P3d(-1e5 + 99.0, 40.8, 81.6), 1e5); auto sphere3 = std::make_shared<Sphere>(P3d(50.0, 40.8, 1e5), 1e5); auto sphere4 = std::make_shared<Sphere>(P3d(50.0, 40.8, -1e5 + 250.0), 1e5); auto sphere5 = std::make_shared<Sphere>(P3d(50.0, 1e5, 81.6), 1e5); auto sphere6 = std::make_shared<Sphere>(P3d(50.0, -1e5 + 81.6, 81.6), 1e5); //auto sphere7 = std::make_shared<Sphere>(P3d(65.0, 20.0, 20.), 20.0); //auto sphere8 = std::make_shared<Sphere>(P3d(27.0, 16.5, 47.), 16.5); //auto sphere9 = std::make_shared<Sphere>(P3d(77.0, 16.5, 78.), 16.5); auto sphere10 = std::make_shared<Sphere>(P3d(50.0f, 90.0, 81.6), 15.0); auto polygon = std::make_shared<TriangleMesh>(); polygon->loadOBJ("teapod.obj"); auto mat1 = std::make_shared<Matte>(C3f(0.75f, 0.25f, 0.25f)); auto mat2 = std::make_shared<Matte>(C3f(0.25f, 0.25f, 0.75f)); auto mat3 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f)); auto mat4 = std::make_shared<Matte>(C3f(0.00f, 0.00f, 0.00f)); auto mat5 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f)); auto mat6 = std::make_shared<Matte>(C3f(0.75f, 0.75f, 0.75f)); //auto mat7 = std::make_shared<Matte>(C3f(0.25f, 0.75f, 0.25f)); //auto mat8 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f)); //auto mat9 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f)); auto mat10 = std::make_shared<Matte>(C3f(0.0f, 0.00f, 0.00f)); auto mat11 = std::make_shared<Matte>(C3f(0.99f, 0.99f, 0.99f)); mat1->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat2->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat3->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat4->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat5->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat6->setEmission(C3f(0.0f, 0.0f, 0.0f)); //mat7->setEmission(C3f(0.0f, 0.0f, 0.0f)); //mat8->setEmission(C3f(0.0f, 0.0f, 0.0f)); //mat9->setEmission(C3f(0.0f, 0.0f, 0.0f)); mat10->setEmission(C3f(36.0f, 36.0f, 36.0f)); mat11->setEmission(C3f(0.0f, 0.0f, 0.0f)); sphere1->setMaterial(mat1); sphere2->setMaterial(mat2); sphere3->setMaterial(mat3); sphere4->setMaterial(mat4); sphere5->setMaterial(mat5); sphere6->setMaterial(mat6); //sphere7->setMaterial(mat7); //sphere8->setMaterial(mat8); //sphere9->setMaterial(mat9); sphere10->setMaterial(mat10); polygon->setMaterial(mat11); _scene.addObject(sphere1); _scene.addObject(sphere2); _scene.addObject(sphere3); _scene.addObject(sphere4); _scene.addObject(sphere5); _scene.addObject(sphere6); //_scene.addObject(sphere7); //_scene.addObject(sphere8); //_scene.addObject(sphere9); _scene.addObject(sphere10); _scene.addObject(polygon); auto camera = std::make_shared<PinholeCamera>(); //auto camera = std::make_shared<ThinLens>(); //camera->setLensRadius(10.0); //camera->setFocalDistance(142.0); camera->setDistance(40.0); _camera = camera; _camera->eye = P3d(50.f, 52.f, 220.f); _camera->lookat = P3d(50.0f, 51.9f, 219.0f); _camera->up = V3d(0.0f, 1.0f, 0.0f); _camera->computeUVW(); }
void OBJRenderer::loadObject(const char *filename) { loadOBJ(filename, obj); }
void InitLivin(int width, int height){ int i; char letterpath[] = "data/x.obj"; /* character mesh mask */ char letterlist[LETTERNUM] = "bceginrsty"; /* Cybernetic genetics characters */ char greetingspath[21]; /* OpenGL related initialization */ glClearColor(0.0, 0.0, 0.0, 0.0); glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); perspectiveMatrix(pmatrix, 35.0, (float)width/(float)height, 0.1, 1500.0); /* Demo related initialization */ head = openDepthVideo("data/head.dv"); matat = openDepthVideo("data/matat.dv"); face = initFace("shaders/face.vs", "shaders/face.fs"); armface = initFace("shaders/face.vs", "shaders/face.fs"); knock = openOutline("data/knock.pyd", "shaders/knock.vs", "shaders/knock.fs"); jump = openOutline("data/jump.pyd", "shaders/jump.vs", "shaders/outline.fs"); hang = openOutline("data/hanging.pyd", "shaders/hang.vs", "shaders/outline.fs"); run = openOutline("data/run.pyd", "shaders/run.vs", "shaders/outline.fs"); falling = openOutline("data/falling_letters.pyd", "shaders/run.vs", "shaders/outline.fs"); door = openOutline("data/door.pyd", "shaders/door.vs", "shaders/door.fs"); trap = openOutline("data/trap.pyd", "shaders/trap.vs", "shaders/outline.fs"); fractalme = openOutline("data/fractalme.pyd", "shaders/frme.vs", "shaders/frme.fs"); /* Acrobatic outlines */ tiger = openOutline("data/tiger.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); hop = openOutline("data/hop.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); katf = openOutline("data/kezenatfordulas.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); flip = openOutline("data/flip.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); run2 = openOutline("data/run2.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); catwheel = openOutline("data/catwheel.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); tbill = openOutline("data/tarkobillenes.pyd", "shaders/acrobat.vs", "shaders/outline.fs"); createBox(); createBackground(); initGreetings(); createDistBack(); bigcube = createBigCube(600); titletex = loadPNGTexture("data/title.png"); greentex = loadPNGTexture("data/green.png"); creditstex = loadPNGTexture("data/credits.png"); bgalphatex = loadPNGTexture("data/bg_alpha.png"); whitetex = loadPNGTexture("data/white.png"); icubetex = loadPNGTexture("data/innercube.png"); headouttex = loadPNGTexture("data/headout.png"); chesstex = loadPNGTexture("data/chessboard.png"); atpartytex = loadPNGTexture("data/at_party.png"); for(i = 0; i < 12; i++){ sprintf(greetingspath, "data/greetings%d.png", i+1); greetingstex[i] = loadPNGTexture(greetingspath); } for(i = 0; i < MAXKNOCKINGMAN; i++){ knockingmans[i * 3 + 0] = drand48() * 4.0 + 8.0; knockingmans[i * 3 + 1] = drand48() * 6.0 + 1.0; knockingmans[i * 3 + 2] = drand48(); } /* Shaders */ background_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/background.vs"); background_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/background.fs"); background_src[2] = loadShader(GL_TESS_EVALUATION_SHADER, "shaders/background.te"); background_src[3] = loadShader(GL_TESS_CONTROL_SHADER, "shaders/background.tc"); background_src[4] = loadShader(GL_GEOMETRY_SHADER, "shaders/background.gs"); background_shader = createProgram(5, background_src); title_src[0] = background_src[0]; title_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/title.fs"); title_src[2] = background_src[2]; title_src[3] = background_src[3]; title_src[4] = background_src[4]; title_shader = createProgram(5, title_src); scroll_src[0] = background_src[0]; scroll_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/scroll.fs"); scroll_src[2] = background_src[2]; scroll_src[3] = background_src[3]; scroll_src[4] = background_src[4]; scroll_shader = createProgram(5, scroll_src); credits_src[0] = background_src[0]; credits_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/credits.fs"); credits_src[2] = background_src[2]; credits_src[3] = background_src[3]; credits_src[4] = loadShader(GL_GEOMETRY_SHADER, "shaders/credits.gs"); credits_shader = createProgram(5, credits_src); letter_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/letter.vs"); letter_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/letter.fs"); letter_shader = createProgram(2, letter_src); cube_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/cube.vs"); cube_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/cube.fs"); cube_src[2] = loadShader(GL_GEOMETRY_SHADER, "shaders/cube.gs"); cube_shader = createProgram(3, cube_src); gr_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/greetings.vs"); gr_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/greetings.fs"); gr_shader = createProgram(2, gr_src); dbgr_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/dbgr.vs"); dbgr_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/dbgr.fs"); dbgr_shader = createProgram(2, dbgr_src); bigcube_src[0] = loadShader(GL_VERTEX_SHADER, "shaders/bigcube.vs"); bigcube_src[1] = loadShader(GL_FRAGMENT_SHADER, "shaders/bigcube.fs"); bigcube_shader = createProgram(2, bigcube_src); /* Letters */ for(i = 0; i < LETTERNUM; i++){ letterpath[5] = letterlist[i]; letters[i] = loadOBJ(letterpath); glBindVertexArray(letters[i]->vao); bindVarToBuff(letter_shader, "vertex", letters[i]->vbo[MESHVERTEXINDEX], 3); bindVarToBuff(letter_shader, "normal", letters[i]->vbo[MESHNORMALINDEX], 3); bindVarToBuff(letter_shader, "tcoord", letters[i]->vbo[MESHTEXINDEX], 2); } cube = loadOBJ("data/cube.obj"); glBindVertexArray(cube->vao); bindVarToBuff(cube_shader, "vertex", cube->vbo[MESHVERTEXINDEX], 3); bindVarToBuff(cube_shader, "normal", cube->vbo[MESHNORMALINDEX], 3); bindVarToBuff(cube_shader, "tcoord", cube->vbo[MESHTEXINDEX], 2); initExplosion(); startTime(); }
/* main function in embree namespace */ int main(int argc, char** argv) { /* for best performance set FTZ and DAZ flags in MXCSR control and status register */ _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); /* create stream for parsing */ Ref<ParseStream> stream = new ParseStream(new CommandLineStream(argc, argv)); /* parse command line */ parseCommandLine(stream, FileName()); /* load default scene if none specified */ if (filename.ext() == "") { FileName file = FileName::executableFolder() + FileName("models/cornell_box.ecs"); parseCommandLine(new ParseStream(new LineCommentFilter(file, "#")), file.path()); } /* configure number of threads */ if (g_numThreads) g_rtcore += ",threads=" + std::to_string((long long)g_numThreads); if (g_numBenchmarkFrames) g_rtcore += ",benchmark=1"; g_rtcore += g_subdiv_mode; /* load scene */ if (strlwr(filename.ext()) == std::string("obj")) { if (g_subdiv_mode != "") { std::cout << "enabling subdiv mode" << std::endl; loadOBJ(filename,one,g_obj_scene,true); } else loadOBJ(filename,one,g_obj_scene); } else if (strlwr(filename.ext()) == std::string("xml")) loadXML(filename,one,g_obj_scene); else if (filename.ext() != "") THROW_RUNTIME_ERROR("invalid scene type: "+strlwr(filename.ext())); /* load keyframes */ if (keyframeList.str() != "") loadKeyFrameAnimation(keyframeList); /* initialize ray tracing core */ init(g_rtcore.c_str()); /* set shader mode */ switch (g_shader) { case SHADER_EYELIGHT: key_pressed(GLUT_KEY_F2); break; case SHADER_UV : key_pressed(GLUT_KEY_F4); break; case SHADER_NG : key_pressed(GLUT_KEY_F5); break; case SHADER_GEOMID : key_pressed(GLUT_KEY_F6); break; case SHADER_GEOMID_PRIMID: key_pressed(GLUT_KEY_F7); break; }; /* convert triangle meshes to subdiv meshes */ if (g_only_subdivs) g_obj_scene.convert_to_subdiv(); /* send model */ set_scene(&g_obj_scene); /* send keyframes */ if (g_keyframes.size()) set_scene_keyframes(&*g_keyframes.begin(),g_keyframes.size()); /* benchmark mode */ if (g_numBenchmarkFrames) renderBenchmark(outFilename); /* render to disk */ if (outFilename.str() != "") renderToFile(outFilename); /* interactive mode */ if (g_interactive) { initWindowState(argc,argv,tutorialName, g_width, g_height, g_fullscreen); enterWindowRunLoop(g_anim_mode); } return 0; }