void shut_down(int return_code){ kernelCleanup(); cudaDeviceReset(); #ifdef __APPLE__ glfwTerminate(); #endif exit(return_code); }
int main(int argc, char **argv) { // Initialize the GLUT framework. if (!glueInit(550, 800, argc, argv, kernelRun)) { return 1; } std::string path( argv[ 0 ] ); int lastSlash = path.find_last_of( "\\" ); path.resize( lastSlash + 1 ); path.append( "../../content/" ); // Load an asvo from file. Object3d imrod = obj3dInit(BFSOctreeImport ( ( path + "imrod.asvo" ).c_str(), ( path + "diffuse.raw" ).c_str(), ( path + "illum.raw" ).c_str(), ( path + "spec.raw" ).c_str(), ( path + "normal.raw" ).c_str() ), true); Vector3 rotAxis = { 1.f, 0.f, 0.f }; obj3dAssignTransform(&imrod, h_createRotation(rotAxis, -1.5707f)); // Copy the model to device memory. BFSOctreeCopyToDevice(&imrod.data); // Set up the camera. Vector3 pos = { 0.f, 25.f, -100.f }; Vector3 lookAt = { 0.f, 0.f, 0.f }; camInit(pos, lookAt, 1.f, glueGetWindowRatio(), 10.f, 200.f); // Set up the light. Vector3 light = { -1.f, -0.5f, 0.5f }; lightSet(light, 0.8f); // Set which model to render (only one supported at the moment). kernelSetParams(imrod); // Start the main render-and-update loop glutMainLoop(); // Do cleanup work. BFSOctreeCleanup(&imrod.data); kernelCleanup(); glueCleanup(); return 0; }
int main(int argc, char** argv){ bool loadedScene = false; for(int i=1; i<argc; i++){ string header; string data; istringstream liness(argv[i]); getline(liness, header, '='); getline(liness, data, '='); if(strcmp(header.c_str(), "mesh")==0){ //renderScene = new scene(data); mesh = new obj(); objLoader* loader = new objLoader(data, mesh); mesh->buildVBOs(); delete loader; loadedScene = true; } } if(!loadedScene){ cout << "Usage: mesh=[obj file]" << endl; return 0; } frame = 0; seconds = time (NULL); fpstracker = 0; // Launch CUDA/GL #ifdef __APPLE__ // Needed in OSX to force use of OpenGL3.2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); init(); #else init(argc, argv); #endif // Initialize camera position cam = glm::translate( cam, glm::vec3( 0.0, 0.0, 2.0f ) ); initCuda(); initVAO(); initTextures(); GLuint passthroughProgram; passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl"); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); #ifdef __APPLE__ // send into GLFW main loop while(1){ display(); if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){ kernelCleanup(); cudaDeviceReset(); exit(0); } } glfwTerminate(); #else glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(mouse_motion); glutMainLoop(); #endif kernelCleanup(); return 0; }
int main(int argc, char** argv){ bool loadedScene = false; for(int i=1; i<argc; i++){ string header; string data; istringstream liness(argv[i]); getline(liness, header, '='); getline(liness, data, '='); if(strcmp(header.c_str(), "mesh")==0){ //renderScene = new scene(data); mesh = new obj(); objLoader* loader = new objLoader(data, mesh); mesh->buildVBOs(); delete loader; loadedScene = true; } } if(!loadedScene){ cout << "Usage: mesh=[obj file]" << endl; return 0; } // Initialization of camera parameters cam.position = glm::vec3(0.0f, 1.0f, 1.0f); cam.up = glm::vec3(0.0f, 1.0f, 0.0f); cam.view = glm::normalize(-cam.position); cam.right = glm::normalize(glm::cross(cam.view, cam.up)); cam.fovy = 45.0f; // Initialize transformation model = new glm::mat4(utilityCore::buildTransformationMatrix(glm::vec3(0.0f, -0.2f, 0.0f), glm::vec3(0.0f), glm::vec3(0.7f))); view = new glm::mat4(glm::lookAt(cam.position, glm::vec3(0.0f), cam.up)); projection = new glm::mat4(glm::perspective(cam.fovy, (float)width / height, zNear, zFar)); transformModel2Projection = new cudaMat4(utilityCore::glmMat4ToCudaMat4(*projection * *view * *model)); // Initialize viewport in the model space viewPort = glm::normalize(utilityCore::multiplyMat(utilityCore::glmMat4ToCudaMat4(*projection * *view), glm::vec4(cam.view, 1.0f))); frame = 0; seconds = time (NULL); fpstracker = 0; // Launch CUDA/GL #ifdef __APPLE__ // Needed in OSX to force use of OpenGL3.2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); init(); #else init(argc, argv); #endif initCuda(); initVAO(); initTextures(); GLuint passthroughProgram; passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl"); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); #ifdef __APPLE__ // send into GLFW main loop while(1){ display(); if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){ kernelCleanup(); cudaDeviceReset(); exit(0); } } glfwTerminate(); #else glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutSpecialFunc(specialFunction); glutMouseFunc(mouseClick); glutMotionFunc(mouseMotion); glutMainLoop(); #endif kernelCleanup(); delete model; delete view; delete projection; delete transformModel2Projection; return 0; }
int main(int argc, char** argv){ bool loadedScene = false; //for(int i=1; i<argc; i++){ string header; string data; //istringstream liness(argv[i]); //getline(liness, header, '='); getline(liness, data, '='); //if(strcmp(header.c_str(), "mesh")==0){ //renderScene = new scene(data); //laoding file for obj data = "../../objs/plane.obj"; mesh = new obj(); objLoader* loader = new objLoader(data, mesh); mesh->buildVBOs(); meshVector.push_back(mesh); data = "../../objs/bunny.obj"; mesh = new obj(); loader = new objLoader(data, mesh); mesh->buildVBOs(); meshVector.push_back(mesh); delete loader; loadedScene = true; //} //} stencilBuffer = new int[width*height]; #if STENCIL == 1 isStencil = true; #else isStencil = false; #endif firstObj = 0; secondObj = FIRST; if(!loadedScene){ cout << "Usage: mesh=[obj file]" << endl; return 0; } frame = 0; seconds = time (NULL); fpstracker = 0; // Launch CUDA/GL #ifdef __APPLE__ // Needed in OSX to force use of OpenGL3.2 glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 2); glfwOpenWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); init(); #else init(argc, argv); #endif initCuda(); initVAO(); initTextures(); GLuint passthroughProgram; passthroughProgram = initShader("shaders/passthroughVS.glsl", "shaders/passthroughFS.glsl"); glUseProgram(passthroughProgram); glActiveTexture(GL_TEXTURE0); #ifdef __APPLE__ // send into GLFW main loop while(1){ display(); if (glfwGetKey(GLFW_KEY_ESC) == GLFW_PRESS || !glfwGetWindowParam( GLFW_OPENED )){ kernelCleanup(); cudaDeviceReset(); exit(0); } } glfwTerminate(); #else glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMainLoop(); #endif kernelCleanup(); return 0; }