//------------------------------------------------------------------------------ int main(int argc, char ** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA |GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(1024, 1024); glutCreateWindow("OpenSubdiv test"); std::string str; if (argc > 1) { std::ifstream ifs(argv[1]); if (ifs) { std::stringstream ss; ss << ifs.rdbuf(); ifs.close(); str = ss.str(); g_defaultShapes.push_back(SimpleShape(str.c_str(), argv[1], kCatmark)); } } initializeShapes(); int smenu = glutCreateMenu(modelMenu); for(int i = 0; i < (int)g_defaultShapes.size(); ++i){ glutAddMenuEntry( g_defaultShapes[i].name.c_str(), i); } int lmenu = glutCreateMenu(levelMenu); for(int i = 1; i < 8; ++i){ char level[16]; sprintf(level, "Level %d\n", i); glutAddMenuEntry(level, i); } // Register Osd compute kernels OpenSubdiv::OsdCpuKernelDispatcher::Register(); OpenSubdiv::OsdGlslKernelDispatcher::Register(); #if OPENSUBDIV_HAS_OPENCL OpenSubdiv::OsdClKernelDispatcher::Register(); #endif #if OPENSUBDIV_HAS_CUDA OpenSubdiv::OsdCudaKernelDispatcher::Register(); // Note: This function randomly crashes with linux 5.0-dev driver. // cudaGetDeviceProperties overrun stack..? cudaGLSetGLDevice( cutGetMaxGflopsDeviceId() ); #endif int kmenu = glutCreateMenu(kernelMenu); int nKernels = OpenSubdiv::OsdKernelDispatcher::kMAX; for(int i = 0; i < nKernels; ++i) if(OpenSubdiv::OsdKernelDispatcher::HasKernelType( OpenSubdiv::OsdKernelDispatcher::KernelType(i))) glutAddMenuEntry(getKernelName(i), i); glutCreateMenu(menu); glutAddSubMenu("Level", lmenu); glutAddSubMenu("Model", smenu); glutAddSubMenu("Kernel", kmenu); glutAttachMenu(GLUT_RIGHT_BUTTON); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutKeyboardFunc(keyboard); glutMotionFunc(motion); glewInit(); initGL(); const char *filename = NULL; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-d")) g_level = atoi(argv[++i]); else if (!strcmp(argv[i], "-c")) g_repeatCount = atoi(argv[++i]); else filename = argv[i]; } modelMenu(0); glutIdleFunc(idle); glutMainLoop(); quit(); }
//------------------------------------------------------------------------------ int main(int argc, char ** argv) { bool fullscreen = false; std::string str; for (int i = 1; i < argc; ++i) { if (!strcmp(argv[i], "-d")) g_level = atoi(argv[++i]); else if (!strcmp(argv[i], "-c")) g_repeatCount = atoi(argv[++i]); else if (!strcmp(argv[i], "-f")) fullscreen = true; else { std::ifstream ifs(argv[1]); if (ifs) { std::stringstream ss; ss << ifs.rdbuf(); ifs.close(); str = ss.str(); g_defaultShapes.push_back(SimpleShape(str.c_str(), argv[1], kCatmark)); } } } initializeShapes(); OsdSetErrorCallback(callbackError); if (not glfwInit()) { printf("Failed to initialize GLFW\n"); return 1; } static const char windowTitle[] = "OpenSubdiv glBatchViewer"; #define CORE_PROFILE #ifdef CORE_PROFILE setGLCoreProfile(); #endif #if GLFW_VERSION_MAJOR>=3 if (fullscreen) { g_primary = glfwGetPrimaryMonitor(); // apparently glfwGetPrimaryMonitor fails under linux : if no primary, // settle for the first one in the list if (not g_primary) { int count=0; GLFWmonitor ** monitors = glfwGetMonitors(&count); if (count) g_primary = monitors[0]; } if (g_primary) { GLFWvidmode const * vidmode = glfwGetVideoMode(g_primary); g_width = vidmode->width; g_height = vidmode->height; } } if (not (g_window=glfwCreateWindow(g_width, g_height, windowTitle, fullscreen and g_primary ? g_primary : NULL, NULL))) { printf("Failed to open window.\n"); glfwTerminate(); return 1; } glfwMakeContextCurrent(g_window); glfwSetKeyCallback(g_window, keyboard); glfwSetCursorPosCallback(g_window, motion); glfwSetMouseButtonCallback(g_window, mouse); glfwSetWindowSizeCallback(g_window, reshape); #else if (glfwOpenWindow(g_width, g_height, 8, 8, 8, 8, 24, 8, fullscreen ? GLFW_FULLSCREEN : GLFW_WINDOW) == GL_FALSE) { printf("Failed to open window.\n"); glfwTerminate(); return 1; } glfwSetWindowTitle(windowTitle); glfwSetKeyCallback(keyboard); glfwSetMousePosCallback(motion); glfwSetMouseButtonCallback(mouse); glfwSetWindowSizeCallback(reshape); #endif #if defined(OSD_USES_GLEW) #ifdef CORE_PROFILE // this is the only way to initialize glew correctly under core profile context. glewExperimental = true; #endif if (GLenum r = glewInit() != GLEW_OK) { printf("Failed to initialize glew. Error = %s\n", glewGetErrorString(r)); exit(1); } #ifdef CORE_PROFILE // clear GL errors which was generated during glewInit() glGetError(); #endif #endif // activate feature adaptive tessellation if OSD supports it g_adaptive = OpenSubdiv::OsdGLDrawContext::SupportsAdaptiveTessellation(); initGL(); glfwSwapInterval(0); initHUD(); callbackModel(g_currentShape); g_fpsTimer.Start(); while (g_running) { idle(); display(); #if GLFW_VERSION_MAJOR>=3 glfwPollEvents(); glfwSwapBuffers(g_window); #else glfwSwapBuffers(); #endif } uninitGL(); glfwTerminate(); }
void initializeShapes( ) { #include <shapes/bilinear_cube.h> g_defaultShapes.push_back(SimpleShape(bilinear_cube, "bilinear_cube", kBilinear)); #include <shapes/catmark_cube_corner0.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_corner0, "catmark_cube_corner0", kCatmark)); #include <shapes/catmark_cube_corner1.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_corner1, "catmark_cube_corner1", kCatmark)); #include <shapes/catmark_cube_corner2.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_corner2, "catmark_cube_corner2", kCatmark)); #include <shapes/catmark_cube_corner3.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_corner3, "catmark_cube_corner3", kCatmark)); #include <shapes/catmark_cube_corner4.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_corner4, "catmark_cube_corner4", kCatmark)); #include <shapes/catmark_cube_creases0.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_creases0, "catmark_cube_creases0", kCatmark)); #include <shapes/catmark_cube_creases1.h> g_defaultShapes.push_back(SimpleShape(catmark_cube_creases1, "catmark_cube_creases1", kCatmark)); #include <shapes/catmark_cube.h> g_defaultShapes.push_back(SimpleShape(catmark_cube, "catmark_cube", kCatmark)); #include <shapes/catmark_dart_edgecorner.h> g_defaultShapes.push_back(SimpleShape(catmark_dart_edgecorner, "catmark_dart_edgecorner", kCatmark)); #include <shapes/catmark_dart_edgeonly.h> g_defaultShapes.push_back(SimpleShape(catmark_dart_edgeonly, "catmark_dart_edgeonly", kCatmark)); #include <shapes/catmark_edgecorner.h> g_defaultShapes.push_back(SimpleShape(catmark_edgecorner ,"catmark_edgecorner", kCatmark)); #include <shapes/catmark_edgeonly.h> g_defaultShapes.push_back(SimpleShape(catmark_edgeonly, "catmark_edgeonly", kCatmark)); #include <shapes/catmark_pyramid_creases0.h> g_defaultShapes.push_back(SimpleShape(catmark_pyramid_creases0, "catmark_pyramid_creases0", kCatmark)); #include <shapes/catmark_pyramid_creases1.h> g_defaultShapes.push_back(SimpleShape(catmark_pyramid_creases1, "catmark_pyramid_creases1", kCatmark)); #include <shapes/catmark_pyramid.h> g_defaultShapes.push_back(SimpleShape(catmark_pyramid, "catmark_pyramid", kCatmark)); #include <shapes/catmark_tent_creases0.h> g_defaultShapes.push_back(SimpleShape(catmark_tent_creases0, "catmark_tent_creases0", kCatmark)); #include <shapes/catmark_tent_creases1.h> g_defaultShapes.push_back(SimpleShape(catmark_tent_creases1, "catmark_tent_creases1", kCatmark)); #include <shapes/catmark_tent.h> g_defaultShapes.push_back(SimpleShape(catmark_tent, "catmark_tent", kCatmark)); #include <shapes/catmark_square_hedit0.h> g_defaultShapes.push_back(SimpleShape(catmark_square_hedit0, "catmark_square_hedit0", kCatmark)); #include <shapes/catmark_square_hedit1.h> g_defaultShapes.push_back(SimpleShape(catmark_square_hedit1, "catmark_square_hedit1", kCatmark)); #include <shapes/catmark_square_hedit2.h> g_defaultShapes.push_back(SimpleShape(catmark_square_hedit2, "catmark_square_hedit2", kCatmark)); #include <shapes/catmark_square_hedit3.h> g_defaultShapes.push_back(SimpleShape(catmark_square_hedit3, "catmark_square_hedit3", kCatmark)); #include <shapes/loop_cube_creases0.h> g_defaultShapes.push_back(SimpleShape(loop_cube_creases0, "loop_cube_creases0", kLoop)); #include <shapes/loop_cube_creases1.h> g_defaultShapes.push_back(SimpleShape(loop_cube_creases1, "loop_cube_creases1", kLoop)); #include <shapes/loop_cube.h> g_defaultShapes.push_back(SimpleShape(loop_cube, "loop_cube", kLoop)); #include <shapes/loop_icosahedron.h> g_defaultShapes.push_back(SimpleShape(loop_icosahedron, "loop_icosahedron", kLoop)); #include <shapes/loop_saddle_edgecorner.h> g_defaultShapes.push_back(SimpleShape(loop_saddle_edgecorner, "loop_saddle_edgecorner", kLoop)); #include <shapes/loop_saddle_edgeonly.h> g_defaultShapes.push_back(SimpleShape(loop_saddle_edgeonly, "loop_saddle_edgeonly", kLoop)); #include <shapes/loop_triangle_edgecorner.h> g_defaultShapes.push_back(SimpleShape(loop_triangle_edgecorner, "loop_triangle_edgecorner", kLoop)); #include <shapes/loop_triangle_edgeonly.h> g_defaultShapes.push_back(SimpleShape(loop_triangle_edgeonly, "loop_triangle_edgeonly", kLoop)); }