int main( int argc, char *argv[] ) { glutInit( &argc, argv ); glutInitWindowPosition( 200, 200 ); glutInitWindowSize( 800, 500 ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutCreateWindow("World of Awesome"); glutReshapeFunc( ReshapeGL ); glutDisplayFunc( Draw ); glutKeyboardFunc( keyboard ); glutMouseFunc( mouse ); glutMotionFunc( mouseMove ); glutPassiveMotionFunc( passiveMove ); glutTimerFunc(TIMER_DELAY, tock, 0); g_width = g_height = 200; #ifdef _WIN32 GLenum err = glewInit(); if (GLEW_OK != err) { std::cerr << "Error initializing glew! " << glewGetErrorString(err) << std::endl; return 1; } #endif #ifdef __APPLE__ glutSetCursor(GLUT_CURSOR_NONE); #endif backShade = glm::vec3(0.2,0.5,0.9); Initialize(); //test the openGL version getGLversion(); //install the shader if (!InstallShader(textFileRead((char *)"shaders/vert.glsl"), textFileRead((char *)"shaders/frag.glsl"))) { printf("Error installing shader!\n"); return 0; } InitGeom(); g_shadeType = PHONG; g_pitch = 0; g_yaw = M_PI / 2; float tx = cos(g_pitch)*cos(g_yaw); float ty = sin(g_pitch); float tz = cos(g_pitch)*cos(M_PI/2 - g_yaw); eye = glm::vec3(0, 2.5, 0); target = eye + glm::vec3(tx, ty, tz); sunDir = normalize(vec3(-0.2, -1.0, 0.0)); sunShade = glm::vec3(1.0, 1.0, 0.9); glutMainLoop(); return 0; }
int main(int argc,char* argv[]){ struct event_base *base; struct bufferevent *bev; int fd,res,i; struct sockaddr_in sin; char recbuf[100]; if(argc != 3){ printf("usage: %s <host> <0-1>\n", argv[0]); return 1; } user = strtol(argv[2], NULL, 10); printf("User %d\n", user); /*GL init*/ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE); glutInitWindowPosition(100, 100); glutInitWindowSize(600, 600); /*new event base*/ base = event_base_new(); if(!base){ printf("Get base failed!\n"); return 1; } /*new server address*/ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = htons(LISTEN_PORT); res = inet_pton(AF_INET, argv[1], &sin.sin_addr); if(res <= 0){ printf("Addr failed!\n"); return 1; } /*new buffer event*/ bev = bufferevent_socket_new(base, -1, BEV_OPT_CLOSE_ON_FREE|BEV_OPT_DEFER_CALLBACKS); if(bev == NULL){ printf("Create bufferevent failed!\n"); return 1; } /*A thread that listen keybord*/ pthread_create(&tid, NULL, SendingThread, bev); /*A thread that render with OpenGL*/ pthread_create(&disptid, NULL, RenderThread, bev); /*Connect to server*/ fd = bufferevent_socket_connect(bev, (struct sockaddr*)&sin, sizeof(sin)); if(fd < 0){ printf("Connect failed!\n"); bufferevent_free(bev); return 1; } bufferevent_setcb(bev, on_read, NULL, on_event, NULL); bufferevent_enable(bev, EV_READ|EV_WRITE); /*start polling*/ printf("Start polling\n"); event_base_dispatch(base); /*Wait until Xwindow is closed*/ pthread_join(disptid, NULL); return 0; }
void INIT(void) { printf("Morph 3D - Shows morphing platonic polyhedra\n"); printf("Author: Marcelo Fernandes Vianna ([email protected])\n\n"); printf(" [1] - Tetrahedron\n"); printf(" [2] - Hexahedron (Cube)\n"); printf(" [3] - Octahedron\n"); printf(" [4] - Dodecahedron\n"); printf(" [5] - Icosahedron\n"); printf(" [s] - Slow, more sleep time\n"); printf(" [f] - Faster,less sleep time\n"); printf("[SPACE] - Toggle colored faces\n"); printf("[RETURN] - Toggle smooth/flat shading\n"); printf(" [ESC] - Quit\n"); object=1; glutInitWindowPosition(0,0); glutInitWindowSize(640,480); glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGB ); if (glutCreateWindow("Morph 3D - Shows morphing platonic polyhedra") <= 0) { exit(0); } glClearDepth(1.0); glClearColor( 0.0, 0.0, 0.0, 1.0 ); glColor3f( 1.0, 1.0, 1.0 ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glFlush(); glutSwapBuffers(); glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT0, GL_POSITION, position0); glLightfv(GL_LIGHT1, GL_AMBIENT, ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse); glLightfv(GL_LIGHT1, GL_POSITION, position1); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient); glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular); glHint(GL_FOG_HINT, GL_FASTEST); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); pinit(); glutReshapeFunc( reshape ); glutKeyboardFunc( key ); glutIdleFunc( idle_ ); glutDisplayFunc( draw ); glutMainLoop(); }
int main(int argc, char *argv[]) { double pos; VideoState *is; if(argc < 2) { fprintf(stderr, "Usage: test <file>\n"); exit(1); } #ifdef __MINGW32__ ptw32_processInitialize(); //ptw32_processTerminate(); #endif //XInitThreads(); is = (VideoState *)av_mallocz(sizeof(VideoState)); avcodec_register_all(); //avdevice_register_all(); avfilter_register_all(); av_register_all(); avformat_network_init(); if (USE_EVENT_MULTI_THREAD) { if ( SDLMOD_StartEventLoop(SDLMOD_INIT_EVENTTHREAD) < 0 ) { fprintf(stderr, "Could not start SDLMOD event loop (multi thread)\n"); exit(1); } } else { if ( SDLMOD_StartEventLoop(0) < 0 ) { fprintf(stderr, "Could not start SDLMOD event loop (main thread)\n"); exit(1); } } if (SDLMOD_TimerInit() != 0) { fprintf(stderr, "SDLMOD_TimerInit failed\n"); exit(1); } g_video_width = 640; g_video_height = 480; g_video_resized = 0; //screen = SDL_SetVideoMode(g_video_width, g_video_height, SDL_VIDEO_MODE_BPP, SDL_VIDEO_MODE_FLAGS); screen = SDLMOD_CreateRGBSurface(0, g_video_width, g_video_height, SDL_VIDEO_MODE_BPP, Rmask, Gmask, Bmask, Amask ); if(!screen) { fprintf(stderr, "SDL: could not set video mode - exiting\n"); exit(1); } screen_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(screen_mutex, NULL); av_strlcpy(is->filename, argv[1], sizeof(is->filename)); is->pictq_mutex = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); pthread_mutex_init(is->pictq_mutex, NULL); is->pictq_cond = (pthread_cond_t *)malloc(sizeof(pthread_cond_t)); pthread_cond_init(is->pictq_cond, NULL); schedule_refresh(is, 40); is->av_sync_type = AV_SYNC_VIDEO_MASTER; { int err; is->parse_tid = (pthread_t *)malloc(sizeof(pthread_t)); err = pthread_create(is->parse_tid, NULL, decodeThread, is); if (err!=0) { free(is->parse_tid); printf("can't create thread: %s\n", strerror(err)); exit(0); } } if (!is->parse_tid) { av_free(is); return -1; } av_init_packet(&flush_pkt); flush_pkt.data = (uint8_t*)"FLUSH"; #if USE_EVENT_LOOP_MT { pthread_t pid; pthread_create(&pid, NULL, event_loop, is); if (0) { pthread_join(pid, NULL); } else { #if USE_GL glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH); glutInitWindowSize(g_video_width, g_video_height); glutInitWindowPosition(0, 0); win = glutCreateWindow(TITLE); createMenu(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutIdleFunc(idle); if (initEnvironment()) { glutMainLoop(); } #else printf(">>>>>>Please input command (exit, quit, save):<<<<<<\n"); char string[256]; char* ret; while(1) { ret = gets(string); if (strcmp(string, "exit") == 0 || strcmp(string, "quit") == 0 || strcmp(string, "e") == 0 || strcmp(string, "q") == 0 ) { break; } else if (strcmp(string, "save") == 0 || strcmp(string, "s") == 0 ) { save_bmp(); printf("save_bmp() finish.\n"); } else { printf("Please input command (exit, quit, save):\n"); } } #endif } } #else event_loop(is); #endif return 0; }
int main( int argc, char **argv) { std::string inpf, trif, outf, backf; adobe::dictionary_t params; bool use_lab = false; try { po::options_description desc("Allowed options"); po::variables_map vm; po::positional_options_description p; p.add( "input" , 1); p.add( "trimap", 1); desc.add_options() ("help", "produce help message") // files ("input", po::value<std::string>(), "input file") ("trimap",po::value<std::string>(), "trimap file") ("output,o", po::value<std::string>(), "output file") ("background,bg", po::value<std::string>(), "clean background") ("save_bg", "save estimated background") // colors ("rgb", "use rgb colorspace") // sampling ("kwin", po::value<int>()->default_value( 8), "known window radius") ("uwin", po::value<int>()->default_value( 8), "unknown window radius") ("mins", po::value<int>()->default_value( 16), "min samples") // clusters ("clusters", po::value<int>()->default_value( 5), "max number of clusters") ("ctheresh", po::value<double>()->default_value( 0.001), "cluster thereshold") // optimize ("cvar", po::value<double>()->default_value( 0.04), "camera variance") // gui ("window,w", "show results in a window") ; // end po::store( po::command_line_parser( argc, argv).options( desc).positional( p).run(), vm); po::notify( vm); if( vm.count( "help") || !vm.count("input") || !vm.count("trimap")) usage(); if( (!vm.count("output")) && (!vm.count("window"))) usage(); inpf = vm["input"].as<std::string>(); trif = vm["trimap"].as<std::string>(); if( vm.count("output")) outf = vm["output"].as<std::string>(); use_lab = !vm.count("rgb"); params[adobe::name_t("use_lab")] = adobe::any_regular_t( use_lab); // load images image.reference( read_image( inpf.c_str())); trimap.reference( read_trimap( trif.c_str())); if( (trimap.rows() != image.rows()) || (trimap.cols() != image.cols())) { std::cout << "Image & trimap dimensions don't match\n"; exit( boost::exit_failure); } if( use_lab) convert2lab( image); if( vm.count( "background")) { backf = vm["background"].as<std::string>(); params[adobe::name_t("use_back")] = adobe::any_regular_t( true); bg.reference( read_image( backf.c_str())); if( use_lab) convert2lab( bg); } else { bg.resize( image.rows(), image.cols()); params[adobe::name_t("use_back")] = adobe::any_regular_t( false); } // sampling params[ adobe::name_t( "kwin_size")] = adobe::any_regular_t( vm["kwin"].as<int>()); params[ adobe::name_t( "uwin_size")] = adobe::any_regular_t( vm["uwin"].as<int>()); params[ adobe::name_t( "min_samples")] = adobe::any_regular_t( vm["mins"].as<int>()); // cluster params[ adobe::name_t( "maxk")] = adobe::any_regular_t( vm["clusters"].as<int>()); params[ adobe::name_t( "ctheresh")] = adobe::any_regular_t( vm["ctheresh"].as<double>()); // optimize params[ adobe::name_t( "cvar")] = adobe::any_regular_t( vm["cvar"].as<double>()); fg.resize( image.rows(), image.cols()); alpha.resize( image.rows(), image.cols()); bmatte bm( image, trimap, fg, bg, alpha, params); bm(); if( use_lab) { convert2rgb( image); convert2rgb( fg); convert2rgb( bg); } if( vm.count( "output")) { save_image( outf.c_str(), fg, &alpha); if( vm.count( "save_bg")) { std::string bgf = "bg_" + outf; save_image( bgf.c_str(), bg); } } if( vm.count( "window")) { comp.resize( image.rows(), image.cols()); for( int j=0;j<image.rows();++j) { for( int i=0;i<image.cols();++i) { float t = alpha( j, i); comp( j, i) = (fg( j, i) * t) + ( Imath::Color3f( .5f, .5f, .5f) * (1.0f - t)); } } glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowPosition( 50, 50); glutInitWindowSize( image.cols(), image.rows()); glutCreateWindow( "BMatte"); glutKeyboardFunc( key); glutMouseFunc( mouse); glutDisplayFunc( display); gl_init(); glutMainLoop(); } } catch( std::exception& e) { std::cerr << "error: " << e.what() << "\n"; return boost::exit_failure; } catch( ...) { std::cerr << "Exception of unknown type!\n";} return boost::exit_success; }
int main(int ac, char **av) { fprintf(stderr, "Ray V1.0\nWritten by David Bucciarelli ([email protected])\n"); /* if(!SetPriorityClass(GetCurrentProcess(),REALTIME_PRIORITY_CLASS)) { fprintf(stderr,"Error setting the process class.\n"); return 0; } if(!SetThreadPriority(GetCurrentThread(),THREAD_PRIORITY_TIME_CRITICAL)) { fprintf(stderr,"Error setting the process priority.\n"); return 0; } */ glutInitWindowPosition(0, 0); glutInitWindowSize(WIDTH, HEIGHT); glutInit(&ac, av); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); if (!(win = glutCreateWindow("Ray"))) { fprintf(stderr, "Error, couldn't open window\n"); return -1; } reshape(WIDTH, HEIGHT); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_EXP2); glFogfv(GL_FOG_COLOR, fogcolor); glFogf(GL_FOG_DENSITY, 0.01); #ifdef FX glHint(GL_FOG_HINT, GL_NICEST); #endif calcposobs(); initspherepos(); inittextures(); initdlists(); glClearColor(fogcolor[0], fogcolor[1], fogcolor[2], fogcolor[3]); glutReshapeFunc(reshape); glutDisplayFunc(draw); glutKeyboardFunc(key); glutSpecialFunc(special); glutIdleFunc(draw); glutMainLoop(); return 0; }
// Setup function for GLUT parameters and loop //***************************************************************************** void InitGL(int* argc, char **argv) { // init GLUT glutInit(argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); glutInitWindowPosition (glutGet(GLUT_SCREEN_WIDTH)/2 - iGraphicsWinWidth/2, glutGet(GLUT_SCREEN_HEIGHT)/2 - iGraphicsWinHeight/2); glutInitWindowSize(iGraphicsWinWidth, iGraphicsWinHeight); iGLUTWindowHandle = glutCreateWindow("OpenCL for GPU Nbody Demo"); #if !(defined (__APPLE__) || defined(MACOSX)) glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); #endif // init GLEW glewInit(); GLboolean bGlew = glewIsSupported("GL_VERSION_2_0 " "GL_VERSION_1_5 " "GL_ARB_multitexture " "GL_ARB_vertex_buffer_object"); oclCheckErrorEX(bGlew, shrTRUE, pCleanup); glEnable(GL_DEPTH_TEST); glClearColor(0.0, 0.0, 0.0, 1.0); renderer = new ParticleRenderer; // check GL errors GLenum error; while ((error = glGetError()) != GL_NO_ERROR) { shrLog("InitGL: error - %s\n", (char *)gluErrorString(error)); } // Disable vertical sync, if supported #ifdef _WIN32 if (wglewIsSupported("WGL_EXT_swap_control")) { iVsyncState = wglGetSwapIntervalEXT(); wglSwapIntervalEXT(0); } #else #if defined (__APPLE__) || defined(MACOSX) GLint VBL = 0; CGLGetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &iVsyncState); CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); #else if(glxewIsSupported("GLX_SGI_swap_control")) { glXSwapIntervalSGI(0); } #endif #endif // create a new parameter list paramlist = new ParamListGL("sliders"); paramlist->bar_col_outer[0] = 0.8f; paramlist->bar_col_outer[1] = 0.8f; paramlist->bar_col_outer[2] = 0.0f; paramlist->bar_col_inner[0] = 0.8f; paramlist->bar_col_inner[1] = 0.8f; paramlist->bar_col_inner[2] = 0.0f; // add parameters to the list // Point Size paramlist->AddParam(new Param<float>("Point Size", activeParams.m_pointSize, 0.0f, 10.0f, 0.01f, &activeParams.m_pointSize)); // Velocity Damping paramlist->AddParam(new Param<float>("Velocity Damping", activeParams.m_damping, 0.5f, 1.0f, .0001f, &(activeParams.m_damping))); // Softening Factor paramlist->AddParam(new Param<float>("Softening Factor", activeParams.m_softening, 0.001f, 1.0f, .0001f, &(activeParams.m_softening))); // Time step size paramlist->AddParam(new Param<float>("Time Step", activeParams.m_timestep, 0.0f, 1.0f, .0001f, &(activeParams.m_timestep))); // Cluster scale (only affects starting configuration paramlist->AddParam(new Param<float>("Cluster Scale", activeParams.m_clusterScale, 0.0f, 10.0f, 0.01f, &(activeParams.m_clusterScale))); // Velocity scale (only affects starting configuration) paramlist->AddParam(new Param<float>("Velocity Scale", activeParams.m_velocityScale, 0.0f, 1000.0f, 0.1f, &activeParams.m_velocityScale)); }
int doMain(int argc,char **argv) { int i; char *opt; std::vector<std::string> filenames; std::vector<std::string> servers; std::string connectionType = "StreamSock"; std::string connectionParameters; int rows=1; int cols=-1; char type='M'; bool clientRendering=true; bool compose=false; std::string composerType=""; std::string autostart; for(i=1;i<argc;i++) { if(strlen(argv[i])>1 && argv[i][0]=='-') { switch(argv[i][1]) { case 'o': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionParameters = opt; printf("connectionParameters: '%s'\n", connectionParameters.c_str()); break; case 'A': opt = argv[i][2] ? argv[i]+2 : argv[++i]; autostart = opt; break; case 'D': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%f,%f,%f",&ca,&cb,&cc)!=3) { std::cout << "Copy opton -D x,y,z" << std::endl; return 1; } break; case 'b': opt = argv[i][2] ? argv[i]+2 : argv[++i]; serviceInterface.assign(opt); serviceInterfaceValid = true; break; case 'B': opt = argv[i][2] ? argv[i]+2 : argv[++i]; serviceAddress.assign(opt); serviceAddressValid = true; break; case 'f': opt = argv[i][2] ? argv[i]+2 : argv[++i]; filenames.push_back(opt); printf("<%s>\n",opt); break; case 'm': connectionType="Multicast"; break; case 'r': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d",&rows,&cols) != 2) sscanf(opt,"%d",&rows); break; case 't': opt = argv[i][2] ? argv[i]+2 : argv[++i]; subtilesize=atoi(opt); break; #ifdef FRAMEINTERLEAVE case 'i': opt = argv[i][2] ? argv[i]+2 : argv[++i]; interleave=atoi(opt); break; #endif case 'C': compose=true; break; case 'F': type='F'; break; case 'X': type='X'; break; case 'P': type='P'; break; case 'L': { type='L'; int lpos=2; while(argv[i][lpos]) { if(argv[i][lpos] == 'B') composerType = "BinarySwapComposer"; if(argv[i][lpos] == 'P') composerType = "PipelineComposer"; if(argv[i][lpos] == 'S') composerType = "SepiaComposer"; if(argv[i][lpos] == 'p') pipelinedBufferRead = true; ++lpos; } break; } case 'M': type='M'; break; case 'I': type='I'; break; case 's': stereoMode=1; break; case 'c': stereoMode=2; break; case 'S': info=true; break; case 'e': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%f",&eyedistance); break; case 'z': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%f",&zeroparallax); break; case 'd': clientRendering=false; break; case 'v': multiport=true; break; case 'x': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%d",&serverx); break; case 'y': opt = argv[i][2] ? argv[i]+2 : argv[++i]; sscanf(opt,"%d",&servery); break; case 'a': opt = argv[i][2] ? argv[i]+2 : argv[++i]; animName=opt; loadAnim(); animate=true; break; case 'l': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d",&animLoops,&animLength) != 2) { animLength = 30; if(sscanf(opt,"%d",&animLoops) != 1) { animLoops = -1; } } break; case 'g': opt = argv[i][2] ? argv[i]+2 : argv[++i]; if(sscanf(opt,"%d,%d,%d,%d", &winwidth,&winheight,&winx,&winy) != 4) sscanf(opt,"%d,%d",&winwidth,&winheight); break; case 'G': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionDestination = opt; break; case 'i': opt = argv[i][2] ? argv[i]+2 : argv[++i]; connectionInterface = opt; break; default: std::cout << argv[0] << "-ffile -m -rrows[,cols] -C -M" << std::endl; std::cout << "-m use multicast" << std::endl << "-G multicast group" << std::endl << "-i interface" << std::endl << "-b service interface" << std::endl << "-M multi display" << std::endl #ifdef FRAMEINTERLEAVE << "-I frame interleave" << std::endl #endif << "-r number of display rows" << std::endl << "-C compose" << std::endl << "-F sort-first" << std::endl << "-L sort-last" << std::endl << "-h this msg" << std::endl << "-s stereo" << std::endl << "-c red/cyan stereo" << std::endl << "-e eye distance" << std::endl << "-z zero parallax" << std::endl << "-d disable client rendering"<<std::endl << "-v use two viewports" << std::endl << "-x server x resolution" << std::endl << "-y server y resolution" << std::endl << "-t subtile size for img composition" << std::endl << "-D x,y,z duplicate geometry" << std::endl << "-A Autostart command" << std::endl << "-o connection parameter string e.g. \"TTL=8\"" << std::endl; return 0; } } else { servers.push_back(argv[i]); } } OSG::ChangeList::setReadWriteDefault(true); OSG::osgInit(argc, argv); glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE ); if(winx >=0 && winy >=0) glutInitWindowPosition(winx,winy); glutInitWindowSize(winwidth,winheight); winid = glutCreateWindow("OpenSG Cluster Client"); glutKeyboardFunc(key); glutReshapeFunc(reshape); glutDisplayFunc(display); if(animate) glutIdleFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); ract = OSG::RenderAction::create(); #ifdef OSG_OLD_RENDER_ACTION ract->setSortTrans(true); ract->setZWriteTrans(true); ract->setLocalLights(true); ract->setCorrectTwoSidedLighting(true); #endif // clear changelist from prototypes OSG::Thread::getCurrentChangeList()->clear(); // create cluster window switch(type) { case 'M': multidisplay=OSG::MultiDisplayWindow::create(); clusterWindow=multidisplay; break; case 'X': balancedmultidisplay=OSG::BalancedMultiWindow::create(); clusterWindow=balancedmultidisplay; break; case 'F': sortfirst=OSG::SortFirstWindow::create(); if(compose) sortfirst->setCompose(true); else sortfirst->setCompose(false); clusterWindow=sortfirst; break; case 'L': sortlast=OSG::SortLastWindow::create(); if(!composerType.empty()) { OSG::FieldContainerUnrecPtr fcPtr = OSG::FieldContainerFactory::the()-> createContainer(composerType.c_str()); OSG::ImageComposer *icPtr = dynamic_cast<OSG::ImageComposer *>(fcPtr.get()); if(icPtr != NULL) { if(dynamic_cast<OSG::PipelineComposer *>(icPtr) != NULL) { if(subtilesize>0) dynamic_cast<OSG::PipelineComposer *>(icPtr)->setTileSize(subtilesize); dynamic_cast<OSG::PipelineComposer *>(icPtr)->setPipelined(pipelinedBufferRead); } if(dynamic_cast<OSG::BinarySwapComposer *>(icPtr) != NULL) { if(subtilesize>0) dynamic_cast<OSG::BinarySwapComposer *>(icPtr)->setTileSize(subtilesize); } icPtr->setStatistics(info); // icPtr->setShort(false); sortlast->setComposer(icPtr); } } clusterWindow=sortlast; break; #ifdef FRAMEINTERLEAVE case 'I': frameinterleave=OSG::FrameInterleaveWindow::create(); clusterWindow=frameinterleave; if(compose) frameinterleave->setCompose(true); else frameinterleave->setCompose(false); break; #endif case 'P': sortfirst=OSG::SortFirstWindow::create(); sortfirst->setCompose(false); clusterWindow=sortfirst; break; } if(!autostart.empty()) clusterWindow->editMFAutostart()->push_back(autostart); for(i=0 ; i<int(servers.size()) ; ++i) clusterWindow->editMFServers()->push_back(servers[i]); if(cols < 0) cols = clusterWindow->getMFServers()->size32() / rows; switch(type) { case 'M': multidisplay->setHServers(cols); multidisplay->setVServers(rows); break; case 'X': balancedmultidisplay->setHServers(cols); balancedmultidisplay->setVServers(rows); // balancedmultidisplay->setShowBalancing(true); // balancedmultidisplay->setShowBalancing(info); break; } #ifdef FRAMEINTERLEAVE clusterWindow->setInterleave(interleave); #endif // create client window clientWindow=OSG::GLUTWindow::create(); // glutReshapeWindow(800,600); glutReshapeWindow(winwidth,winheight); clientWindow->setGlutId(winid); clientWindow->init(); // init scene graph init(filenames); // init client clusterWindow->setConnectionType(connectionType); // needs to be called before init()! clusterWindow->setConnectionParams(connectionParameters); if(clientRendering) { clusterWindow->setClientWindow(clientWindow); } clusterWindow->setConnectionDestination(connectionDestination); clusterWindow->setConnectionInterface(connectionInterface); clusterWindow->init(); if(serverx > 0) clusterWindow->resize(serverx,servery); else clusterWindow->resize(winwidth,winheight); clientWindow->resize(winwidth,winheight); // OSG::FieldContainerFactory::the()->dump(); OSG::commitChanges(); glutMainLoop(); return 0; }
int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STENCIL); if((argc > 1) && (strcmpi(argv[1], "--helmet") == 0)) { /*left eye*/ glutInitWindowPosition(0,0); glutInitWindowSize(640, 480); left_eye = glutCreateWindow("Escher World - Left Eye"); glutSetWindow(left_eye); set_window_size(640, 480); glutDisplayFunc(displayleft); glutKeyboardFunc(keyfunc); glutMouseFunc(mouse_button); glutPassiveMotionFunc(passive_mouse_motion); glutMotionFunc(passive_mouse_motion); glutReshapeFunc(set_window_size); /* glutTimerFunc(10,child,1);*/ /* right eye */ glutInitWindowPosition(641,0); glutInitWindowSize(640, 480); right_eye = glutCreateWindow("Escher World - Right Eye"); glutSetWindow(right_eye); set_window_size(640, 480); glutDisplayFunc(displayright); glutKeyboardFunc(keyfunc); glutMouseFunc(mouse_button); glutPassiveMotionFunc(passive_mouse_motion); glutMotionFunc(passive_mouse_motion); glutReshapeFunc(set_window_size); glutSetWindow(left_eye); create_menus(); init(); /* Initialize the scene */ init_scene(FILENAME); glutSetWindow(right_eye); create_menus(); create_menus(); init(); /* Initialize the scene */ init_scene(FILENAME); #ifdef USE_HELMET /* main_helmet(); signal(SIGUSR1, cleanup); */ birdinit(); /* glutTimerFunc(10,child,1);*/ #endif } else { glutInitWindowPosition(64,64); glutInitWindowSize(768, 832); glut_window = glutCreateWindow("Escher World"); glutSetWindow(glut_window); set_window_size(768, 832); helmet = !helmet; glutDisplayFunc(displaymid); glutKeyboardFunc(keyfunc); glutMouseFunc(mouse_button); glutPassiveMotionFunc(passive_mouse_motion); glutMotionFunc(passive_mouse_motion); glutReshapeFunc(set_window_size); create_menus(); init(); /* Initialize the scene */ init_scene(FILENAME); } glutMainLoop(); return 0; }
int main(int argc, char** argv) { if (argc != 7) { printf("%d", argc); for (int i = 0; i < argc; i++) { printf("%s\n", argv[i]); } usage(); } vertexShader = std::string(argv[1]); fragmentShader = std::string(argv[2]); meshOBJ = std::string(argv[3]); normalMap = std::string(argv[4]); displacementMap = std::string(argv[5]); colorMap =std::string(argv[6]); // // Initialize GLUT. // glutInit(&argc, argv); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowPosition(20, 20); glutInitWindowSize(640, 480); glutCreateWindow("CS148 Texturing"); // // Initialize GLEW. // #ifndef __APPLE__ glewInit(); if(!GLEW_VERSION_2_0) { printf("Your graphics card or graphics driver does\n" "\tnot support OpenGL 2.0, trying ARB extensions\n"); if(!GLEW_ARB_vertex_shader || !GLEW_ARB_fragment_shader) { printf("ARB extensions don't work either.\n"); printf("\tYou can try updating your graphics drivers.\n" "\tIf that does not work, you will have to find\n"); printf("\ta machine with a newer graphics card.\n"); exit(1); } } #endif // Be sure to initialize GLUT (and GLEW for this assignment) before // initializing your application. Setup(); glutDisplayFunc(DisplayCallback); glutReshapeFunc(ReshapeCallback); glutSpecialFunc(SpecialKeyCallback); glutKeyboardFunc(KeyCallback); glutMouseFunc(MouseCallback); glutMotionFunc(MouseMotionCallback); glutIdleFunc(DisplayCallback); glutMainLoop(); // Cleanup code should be called here. CleanUp(); return 0; }
int main(int argc, char *argv[]) { // Initialise OpenGL glutInit(&argc, argv); // Set window position, size & create window glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowPosition(50,50); glutInitWindowSize(width,height); windowId = glutCreateWindow("Ray Cast Volume Rendering"); glewInit(); // Set GLUT callback functions glutDisplayFunc(renderScene); //glutIdleFunc(updateScene); glutKeyboardFunc(keypress); // Setup OpenGL state & scene resources init(); //GLUI glui = GLUI_Master.create_glui( "Controls", 0, 865, 50); movement_panel = new GLUI_Panel( glui, "Movement Parameters" ); view_rot = new GLUI_Rotation( movement_panel, "Rotate", view_rotate ); view_rot->set_spin( 1.0 ); trans_z = new GLUI_Translation( movement_panel, "Zoom", GLUI_TRANSLATION_Z, &zoom ); trans_z->set_speed( .05 ); raycastPGM = new GLUI_Checkbox(glui, "Raycast /w XToon & Alpha Interpolation", &raycastEnable, RAYCAST, controlCB); xtoonPGM = new GLUI_Checkbox(glui, "Raycast XToon Shader", &xtoonEnable, XTOONPGM, controlCB); gradientPGM = new GLUI_Checkbox(glui, "Gradient", &gradientEnable, GRADIENT, controlCB); dvrPGM = new GLUI_Checkbox(glui, "DVR", &dvrEnable, DVR, controlCB); rin = new GLUI_Checkbox(glui, "Show Ray Start", &rayinToggle, RAYIN, controlCB); rout = new GLUI_Checkbox(glui, "Show Ray Stop", &rayoutToggle, RAYOUT, controlCB); column_01 = new GLUI_Column( glui ); GUIRayCastRoll = new GLUI_Rollout( glui, "Ray Cast Parameters", false); raycaster_panel = new GLUI_Panel( GUIRayCastRoll, "" ); jittering = new GLUI_Checkbox( raycaster_panel, "Stippling", &j, JITTER, controlCB ); jittering->set_alignment( GLUI_ALIGN_RIGHT ); GUIsamples = new GLUI_Spinner( raycaster_panel, "N Samples", &nSamples ); GUIsamples->set_int_limits( 0, 255 ); GUIsamples->set_alignment( GLUI_ALIGN_RIGHT ); GUInoise = new GLUI_Spinner( raycaster_panel, "Noise Delta", &noiseDelta ); GUInoise->set_float_limits( 1.0, 10.0 ); GUInoise->set_alignment( GLUI_ALIGN_RIGHT ); GUIstep = new GLUI_Spinner( raycaster_panel, "Step Length", &stepLength ); GUIstep->set_float_limits( 0.01f, 1.0f ); GUIstep->set_alignment( GLUI_ALIGN_RIGHT ); GUIt = new GLUI_Spinner( raycaster_panel, "Threshold", &threshold ); GUIt->set_float_limits( 0.01f, 1.0f ); GUIt->set_alignment( GLUI_ALIGN_RIGHT ); GUIgscale = new GLUI_Spinner( raycaster_panel, "Gradient Scale", &gradientScale ); GUIgscale->set_float_limits( 0.01f, 1.0f ); GUIgscale->set_alignment( GLUI_ALIGN_RIGHT ); GUIgdelta = new GLUI_Spinner( raycaster_panel, "Gradient Delta", &gradientDelta ); GUIgdelta->set_float_limits( 0.01f, 1.0f ); GUIgdelta->set_alignment( GLUI_ALIGN_RIGHT ); GUIfmax = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Max", &fMax ); GUIfmax->set_float_limits( 0.01f, 255.0f ); GUIfmax->set_alignment( GLUI_ALIGN_RIGHT ); GUIfmin = new GLUI_Spinner( raycaster_panel, "Histogram (Alpha) Min", &fMin ); GUIfmin->set_float_limits( 0.0f, 255.0f ); GUIfmin->set_alignment( GLUI_ALIGN_RIGHT ); GUIalpha = new GLUI_Spinner( raycaster_panel, "Alpha Value", &alpha ); GUIalpha->set_float_limits( 0.01f, 1.0f ); GUIalpha->set_alignment( GLUI_ALIGN_RIGHT ); GUItscale = new GLUI_Spinner( raycaster_panel, "Transfer Scale", &transferScale ); GUItscale->set_float_limits( 0.01f, 1.0f ); GUItscale->set_alignment( GLUI_ALIGN_RIGHT ); GUIthick = new GLUI_Spinner( raycaster_panel, "Thickness", &thickness ); GUIthick->set_float_limits( 0.01f, 1.0f ); GUIthick->set_alignment( GLUI_ALIGN_RIGHT ); GUIXToonRoll = new GLUI_Rollout( glui, "XTOON Parameters", false ); xtoon_panel = new GLUI_Panel( GUIXToonRoll, "" ); toneDetailBox = new GLUI_Checkbox(xtoon_panel, "Tone Detail", &toneDetail, XTOONTYPE, controlCB ); GUIr = new GLUI_Spinner( xtoon_panel, "Coarse Detail", &R ); GUIr->set_float_limits( 1.0f, 25.0f ); GUIr->set_alignment( GLUI_ALIGN_RIGHT ); backlightBOX = new GLUI_Checkbox(xtoon_panel, "Backlighting", &backlight, XTOONTYPE, controlCB ); GUIR = new GLUI_Spinner( xtoon_panel, "Backlight Detail", &backlight_detail ); GUIR->set_float_limits( 0.0f, 25.0f ); GUIR->set_alignment( GLUI_ALIGN_RIGHT ); specularBOX = new GLUI_Checkbox(xtoon_panel, "Specular Highlight", &specHighlight, XTOONTYPE, controlCB ); GUIs = new GLUI_Spinner( xtoon_panel, "Shine Factor", &S ); GUIs->set_float_limits( 1.0f, 25.0f ); GUIs->set_alignment( GLUI_ALIGN_RIGHT ); xtoonBOX = new GLUI_Checkbox(xtoon_panel, "Enable / Disable", &xToonFlag, XTOON, controlCB ); glui->set_main_gfx_window(windowId); glutInitWindowSize(300, 300); subWindowId = glutCreateWindow("Transfer Function 2D Texture"); glutPositionWindow(865, 350); // Set GLUT callback functions glutReshapeFunc(setViewport); glutDisplayFunc(renderSub); glutKeyboardFunc(keypressSub); // Setup OpenGL state & scene resources initSub(); GLUI_Master.set_glutIdleFunc(updateScene); // Show window & start update loop glutMainLoop(); return 0; }
/** * Method for create a window */ void Visualizer::createWindow(const char * title) { xnew=0; ynew=0; znew=0; /* actual position */ xold=0; yold=0; zold=0; /* old position */ xx1=0; yy1=0; zz1=0; /* mouse position*/ mouseState=0; /* mouse button state */ xshift=0; yshift=0; /* shifting in space*/ xnew=0; ynew=0; znew=0; /* actual position */ xold=0; yold=0; zold=0; /* old position */ xx1=0; yy1=0; zz1=0; /* mouse position*/ mouseState=0; /* mouse button state */ xshift=0; yshift=0; /* shifting in space*/ fov=45.0; /* field of view */ near_plane=1; /* trim plain */ far_plane=1000.0; /* farther trim plain */ line_width=1.0; /* width of line */ WindowWidth=1024; /* width and height of window */ WindowHeight=768; ObjectType=0; /* type of paint object */ Solid=1; /* fill or wireframe model */ char * dummy_argv[1]; dummy_argv[0] = const_cast<char *>("run"); int dummy_argc = 1; glutInit(&dummy_argc, dummy_argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE ); /* graphic mod of window */ glutInitWindowSize(WindowWidth,WindowHeight); /* original window size */ glutInitWindowPosition(10,10); /* original window position */ glutCreateWindow(title); /* create window */ glutDisplayFunc(onDisplay); /* set function for redisplay */ glutReshapeFunc(onReshape); /* set function for change of size window */ glutKeyboardFunc(onKeyboard); /* set function for press key */ glutSpecialFunc(onSpecial); glutMouseFunc(onMouseClick); /* set function for press mouse button */ glutMotionFunc(onMouseMotion); /* set function for mouse move */ glClearColor(0.0, 0.0, 0.0, 0.0); /* color for clearing of color-buffer */ glClearDepth(1.0f); /* color for clearing of z-buffer */ glEnable(GL_DEPTH_TEST); /* configure function for testing value in z-buffer */ glDepthFunc(GL_LESS); /* select function */ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); /* improvement display */ glEnable(GL_CULL_FACE); glPolygonMode(GL_FRONT, GL_FILL); /* configure draw of fill polygons */ //glCullFace(GL_FRONT); glLineWidth(line_width); /* line width */ glPointSize(line_width); //glEnable(GL_MULTISAMPLE); #ifdef FREEGLUT #ifdef GLUT_AUX int *sampleNumbers = NULL; int sampleNumbersSize = 0; sampleNumbers = glutGetModeValues(GLUT_MULTISAMPLE, &sampleNumbersSize); if(sampleNumbers != NULL) { glutSetOption(GLUT_MULTISAMPLE, sampleNumbers[sampleNumbersSize - 1]); printf("Multisampling with %i samples.\n", sampleNumbers[sampleNumbersSize - 1]); free(sampleNumbers); } else { printf("Multisampling is not available.\n"); } #endif #endif scene_ = glGenLists(1); /* get number of calllist */ createCallList(); /* initialization */ glutMainLoop(); }
int main(int argc, char* argv[]) { /****************************************/ /* Initialize GLUT and create window */ /****************************************/ glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowPosition( 50, 50 ); glutInitWindowSize( 300, 300 ); main_window = glutCreateWindow( "GLUI Example 2" ); glutDisplayFunc( myGlutDisplay ); glutReshapeFunc( myGlutReshape ); glutKeyboardFunc( myGlutKeyboard ); glutMotionFunc( myGlutMotion ); glutMouseFunc( myGlutMouse ); /****************************************/ /* Set up OpenGL lights */ /****************************************/ GLfloat light0_ambient[] = {0.1f, 0.1f, 0.3f, 1.0f}; GLfloat light0_diffuse[] = {.6f, .6f, 1.0f, 1.0f}; GLfloat light0_position[] = {1.0f, 1.0f, 1.0f, 0.0f}; glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse); glLightfv(GL_LIGHT0, GL_POSITION, light0_position); /****************************************/ /* Enable z-buferring */ /****************************************/ glEnable(GL_DEPTH_TEST); /****************************************/ /* Here's the GLUI code */ /****************************************/ GLUI *glui = GLUI_Master.create_glui( "GLUI", 0, 400, 50 ); /* name, flags, x, and y */ new GLUI_StaticText( glui, "GLUI Example 2" ); new GLUI_Separator( glui ); checkbox = new GLUI_Checkbox( glui, "Wireframe", &wireframe, 1, control_cb ); spinner = new GLUI_Spinner( glui, "Segments:", &segments, 2, control_cb ); spinner->set_int_limits( 3, 60 ); edittext = new GLUI_EditText( glui, "Text:", text, 3, control_cb ); GLUI_Panel *obj_panel = new GLUI_Panel( glui, "Object Type" ); radio = new GLUI_RadioGroup( obj_panel,&obj,4,control_cb ); new GLUI_RadioButton( radio, "Sphere" ); new GLUI_RadioButton( radio, "Torus" ); new GLUI_RadioButton( radio, "Teapot" ); new GLUI_Button( glui, "Quit", 0,(GLUI_Update_CB)exit ); glui->set_main_gfx_window( main_window ); /* We register the idle callback with GLUI, *not* with GLUT */ GLUI_Master.set_glutIdleFunc( myGlutIdle ); GLUI_Master.set_glutIdleFunc( NULL ); glutMainLoop(); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(800, 600); glutInitWindowPosition(100,100); glutCreateWindow("OGLplus+GLUT+GLEW"); if(glewInit() == GLEW_OK) try { glGetError(); namespace se = oglplus::smart_enums; oglplus::Context gl; oglplus::AMD_performance_monitor apm; const char* f1[2] = {" +--", " `--"}; const char* f2[2] = {" |", " "}; const char* f3[2] = {" +--", " `--"}; const char* f4[2] = {" |", ""}; auto groups = apm.GetGroups(); auto gi=groups.begin(), ge=groups.end(); std::cout << "--+-{Performance monitor groups}" << std::endl; if(gi != ge) std::cout << " |" << std::endl; while(gi != ge) { auto group = *gi; ++gi; const int fgi = (gi == ge)?1:0; std::cout << f1[fgi] << "+-["; std::cout << group.GetString(); std::cout << "]" << std::endl; std::cout << f2[fgi] << f4[0] << std::endl; GLint max; auto counters = group.GetCounters(max); auto ci=counters.begin(), ce=counters.end(); while(ci != ce) { auto counter = *ci; ++ci; const int fci = (ci == ce)?1:0; std::cout << f2[fgi] << f3[fci] << "("; std::cout << counter.GetString(); std::cout << ") ["; std::cout << EnumValueName(counter.Type()); std::cout << "]" << std::endl; std::cout << f2[fgi] << f4[fci] << std::endl; } if(fgi != 0) { oglplus::PerfMonitorAMD mon; mon.SelectCounters(true, counters); mon.Begin(); // Imagine some heavy duty rendering here gl.Clear().ColorBuffer(); mon.End(); if(mon.ResultAvailable()) { std::vector<oglplus::PerfMonitorAMDResult> values; mon.Result(values); auto ri=values.begin(), re=values.end(); while(ri != re) { auto counter = ri->Counter(); auto type = counter.Type(); std::cout << counter.GetString(); std::cout << " ["; std::cout << EnumValueName(type); std::cout << "] = "; if(type == se::UnsignedInt()) std::cout << ri->Low(); else if(type == se::Float()) std::cout << ri->Float(); else if(type == se::Percentage()) std::cout << ri->Float() << "%"; else if(type == se::UnsignedInt64()) std::cout << "too big"; std::cout << std::endl; ++ri; } } } } return 0; } catch(oglplus::Error& err) { std::cerr << "Error (in " << err.GLSymbol() << ", " << err.ClassName() << ": '" << err.ObjectDescription() << "'): " << err.what() << " [" << err.File() << ":" << err.Line() << "] "; std::cerr << std::endl; err.Cleanup(); } return 1; }
int main(int argc, char **argv) { // GLUT initialization glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH|GLUT_DOUBLE|GLUT_RGBA|GLUT_MULTISAMPLE); glutInitContextVersion (3, 3); glutInitContextFlags (GLUT_COMPATIBILITY_PROFILE ); glutInitWindowPosition(100,100); glutInitWindowSize(320,320); glutCreateWindow("Lighthouse3D - Assimp Demo"); // Callback Registration glutDisplayFunc(renderScene); glutReshapeFunc(changeSize); glutIdleFunc(renderScene); // Mouse and Keyboard Callbacks glutKeyboardFunc(processKeys); glutMouseFunc(processMouseButtons); glutMotionFunc(processMouseMotion); glutMouseWheelFunc ( mouseWheel ) ; // Init GLEW //glewExperimental = GL_TRUE; glewInit(); if (glewIsSupported("GL_VERSION_3_3")) printf("Ready for OpenGL 3.3\n"); else { printf("OpenGL 3.3 not supported\n"); return(1); } // Init the app (load model and textures) and OpenGL if (!init()) printf("Could not Load the Model\n"); printf ("Vendor: %s\n", glGetString (GL_VENDOR)); printf ("Renderer: %s\n", glGetString (GL_RENDERER)); printf ("Version: %s\n", glGetString (GL_VERSION)); printf ("GLSL: %s\n", glGetString (GL_SHADING_LANGUAGE_VERSION)); // return from main loop glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS); // GLUT main loop glutMainLoop(); // cleaning up textureIdMap.clear(); // clear myMeshes stuff for (unsigned int i = 0; i < myMeshes.size(); ++i) { glDeleteVertexArrays(1,&(myMeshes[i].vao)); glDeleteTextures(1,&(myMeshes[i].texIndex)); glDeleteBuffers(1,&(myMeshes[i].uniformBlockIndex)); } // delete buffers glDeleteBuffers(1,&matricesUniBuffer); return(0); }
int main(int argc, char **argv) { int i; glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); for (i=1; i<argc; i++) { if(!strcmp("-noms", argv[i])) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); printf("forcing no multisampling\n"); } else if(!strcmp("-nomipmaps", argv[i])) { useMipmaps = 0; } else if(!strcmp("-nearest", argv[i])) { linearFiltering = 0; } } glutInitWindowPosition(0, 0); glutInitWindowSize(600,300); glutCreateWindow("sprite blast"); glutReshapeFunc(reshape); glutDisplayFunc(redraw); glutMouseFunc(mouse); glutMotionFunc(mouseMotion); glutVisibilityFunc(visible); glutKeyboardFunc(key); glutCreateMenu(menu); glutAddMenuEntry("Reset time", 0); glutAddMenuEntry("Constant", 1); glutAddMenuEntry("Linear", 2); glutAddMenuEntry("Quadratic", 3); glutAddMenuEntry("Blend on", 4); glutAddMenuEntry("Blend off", 5); glutAddMenuEntry("Threshold 1", 6); glutAddMenuEntry("Threshold 10", 7); glutAddMenuEntry("Point smooth on", 8); glutAddMenuEntry("Point smooth off", 9); glutAddMenuEntry("Point size 4", 10); glutAddMenuEntry("Point size 8", 11); glutAddMenuEntry("Point size 16", 12); glutAddMenuEntry("Toggle spin", 13); glutAddMenuEntry("200 points ", 14); glutAddMenuEntry("500 points ", 15); glutAddMenuEntry("1000 points ", 16); glutAddMenuEntry("2000 points ", 17); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); glEnable(GL_POINT_SMOOTH); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glPointSize(16.0); #ifdef GL_ARB_point_parameters glPointParameterfvARB(GL_POINT_DISTANCE_ATTENUATION_ARB, theQuad); #endif makePointList(); makeSprite(); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main( int argc_, char **argv_ ) { meerkat::mk_argument_manager a("Force-directed edge bundling calculator", "Usage: fdeb [options]"); a.add_help(); a.add_argument_entry( "nodes", MK_VALUE, "--nodes", "-n", "File containing node positions", "", MK_REQUIRED); a.add_argument_entry( "edges", MK_VALUE, "--edges", "-e", "File containing edges", "", MK_REQUIRED); a.add_argument_entry( "json", MK_VALUE, "--json", "-json", "Prints result in a JSON file [unset]", "", MK_OPTIONAL); a.add_argument_entry( "K", MK_VALUE, "--K", "-K", "Edge stiffness [0.1]", "0.1", MK_OPTIONAL); a.add_argument_entry( "S", MK_VALUE, "--S", "-S", "Initial value of S [0.4]", "0.4", MK_OPTIONAL); a.add_argument_entry( "I", MK_VALUE, "--I", "-i", "Initial number of iterations [90]", "90", MK_OPTIONAL); a.add_argument_entry( "compat", MK_VALUE, "--compat", "-c", "Compatibility threshold [0.6]", "0.6", MK_OPTIONAL); a.add_argument_entry( "cycles", MK_VALUE, "--cycles", "-C", "Max number of cycles [5]", "5", MK_OPTIONAL); a.add_argument_entry( "sigma", MK_VALUE, "--sigma", "-s", "Smoothing width [3]", "3", MK_OPTIONAL); a.add_argument_entry( "edge weight", MK_VALUE, "--edge-weight", "-ew", "Edge weight threshold for edge filtering [unset]." "Edges with a weight below the given value are dropped", "-1.0", MK_OPTIONAL); a.add_argument_entry( "edge percentage", MK_VALUE, "--edge-percentage", "-ep", "Edge percentage for edge filtering [unset]." "The given fraction of edges among the strongest ones are kept", "-1.0", MK_OPTIONAL); a.add_argument_entry( "epsilon", MK_VALUE, "--epsilon", "-E", "Lowest interaction distance [1e-4]", "0.0001", MK_OPTIONAL); a.add_argument_entry( "gravitation center x", MK_VALUE, "--gravitation-center-x", "-gcx", "Gravitation center x coordinate [0.0]. If set, gravitation is turned on", "0.0", MK_OPTIONAL); a.add_argument_entry( "gravitation center y", MK_VALUE, "--gravitation-center-y", "-gcy", "Gravitation center y coordinate [0.0]. If set, gravitation is turned on", "0.0", MK_OPTIONAL); a.add_argument_entry( "gravitation exponent", MK_VALUE, "--gravitation-exponent", "-ge", "Gravitation exponent [-2.0]. If set, gravitation is turned on", "1.0", MK_OPTIONAL); a.add_argument_entry( "visualization", MK_FLAG, "--visualize", "-v", "Enables real-time visualization [off]", "0", MK_OPTIONAL); a.add_argument_entry( "transparency", MK_VALUE, "--transparency", "-t", "Transparency of edges", "0.3", MK_OPTIONAL); a.read_arguments(argc_, argv_); a.show_settings(); // set params and read graph gGraph.set_algorithm_params( a.get_double_argument("K"), a.get_int_argument("cycles"), a.get_int_argument("I"), a.get_double_argument("compat"), a.get_double_argument("sigma")); gGraph.set_network_params( a.get_double_argument("edge weight"), a.get_double_argument("edge percentage") ); gGraph.set_physics_params( a.get_double_argument("S"), a.get_double_argument("epsilon"), meerkat::mk_vector2(a.get_double_argument("gravitation center x"), a.get_double_argument("gravitation center y")), a.get_double_argument("gravitation exponent") ); if( a.is_set("gravitation center x") || a.is_set("gravitation center y") || a.is_set("gravitation exponent") ) gGraph.enable_gravitation(); // Read graph gGraph.read(a.get_string_argument("nodes"), a.get_string_argument("edges")); // Get output name if( a.is_set("json") ) gJson = a.get_string_argument("json"); // If visualization is enabled if( a.is_set("visualization") ) { // Set graphical parameters gGraph.set_graphics_params( a.get_double_argument("transparency") ); // Get bounding box meerkat::mk_vector2 bottomLeft, topRight; gGraph.get_bounding_box(bottomLeft, topRight, 20.0); double gWidth = topRight.x() - bottomLeft.x(); double gHeight = topRight.y() - bottomLeft.y(); // Init GLUT int wWidth = DEFAULT_SIZE, wHeight = DEFAULT_SIZE; if( gWidth > gHeight ) wHeight = int(wWidth * gHeight/gWidth); else wWidth = int(wHeight * gWidth/gHeight); glutInit( &argc_, argv_ ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); glutInitWindowSize( wWidth, wHeight ); glutInitWindowPosition( 10, 100 ); glutCreateWindow( "fdeb" ); init(bottomLeft, topRight); // Increase cycle index and enter main loop glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); glutTimerFunc( 10, timer, 1 ); glutMainLoop(); } // Otherwise, just perform edge bundling else { do { while( gGraph.iterate() > 0 ); gGraph.add_subvisions(); } while( gGraph.update_cycle() > 0 ); gGraph.smooth(); if( gJson != "" ) gGraph.print_json(gJson); } return 0; }
int main (int argc, char **argv) { /* **************************************************************************************************************************** */ /* Pointeurs vers l'application */ glutInit(&argc, argv); /* Activation des buffers : Double buffer RGBA color Depth buffer */ glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); /* Création de la fenêtre */ glutInitWindowSize(1024, 768); /* Positionnement de la fenêtre */ glutInitWindowPosition(100, 100); /* Ouverture de la fenêtre */ glutCreateWindow("TD_Animation_3D"); /* Spécification de la fontion de dessin */ glutDisplayFunc(display); /* Spécification de la fontion de redimensionnement */ glutReshapeFunc(reshape); /* Spécification des fontions de gestion du clavier */ glutKeyboardFunc(keyboardDown); glutKeyboardUpFunc(keyboardUp); glutSpecialFunc(keyboardSpecDown); glutSpecialUpFunc(keyboardSpecUp); /* Spécification des fontions de gestion de la souris */ glutMouseFunc(mouse); glutMotionFunc(motion); /* Spécification de la fonction de mise-à-jour */ glutIdleFunc(timeTick); /* **************************************************************************************************************************** */ /* Affichage des fonctions clavier */ HelpMessage(); /* **************************************************************************************************************************** */ /* Intitialisation des paramètres de l'affichage et de la fenêtre */ GLInit(); /* Intitialisation des paramètres du squelette */ SkeletInit(); /* Intitialisation de la scène cinématique */ IKInit(); /* **************************************************************************************************************************** */ /* Lancement de la boucle OpenGL */ glutMainLoop(); /* **************************************************************************************************************************** */ return 0; /* **************************************************************************************************************************** */ }
Window::Window(int x, int y, int w, int h, string title, int speed, double red, double green, double blue, bool read_keypresses_from_standard_input /* = false */ ) { m_x = x; m_y = y; m_w = w; m_h = h; m_title = title; m_read_keypresses_from_standard_input = read_keypresses_from_standard_input; if (speed > 100) speed = 100; if (speed < 1) speed = 1; // This formula sets up the meaning of the speed // Speed is very machine dependent, this may have to be changed // for very fast or very slow machine // special case, low speeds are really slow for debugging if (speed <= 10) clock_tick = (11 - speed) * 1000; else clock_tick = ((103 - speed) * (103 - speed))/10; // glut can be controlled by command line arguments pass to glutInit(). // In order to simplify argument parsing in gpl.cpp, command line // arguments are not passed to glutInit() int phony_argc = 1; char *phony_argv[2]; phony_argv[0] = strdup("gpl"); phony_argv[1] = 0; glutInit(&phony_argc,phony_argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(m_w,m_h); glutInitWindowPosition(m_x,m_y); glutCreateWindow(m_title.c_str()); // if we are suppose to read characters from the command line // (this is a testing/debugging tool) if (m_read_keypresses_from_standard_input) // use an idle function to read the commands glutIdleFunc(read_keypresses_from_standard_input_callback); // redraws all objects if window is changed by windowing system glutReshapeFunc(window_reshape_callback); glutVisibilityFunc(window_visibility_callback); glutDisplayFunc(draw_callback); glutTimerFunc(clock_tick, timer_callback, 0); glutKeyboardFunc(keyboard_callback); glutSpecialFunc(special_callback); glutMouseFunc(mouse_callback); glutMotionFunc(motion_callback); glutPassiveMotionFunc(passive_motion_callback); glViewport(0, 0, m_w, m_h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, m_w, 0, m_h); glClearColor (red, green, blue, 0.0); }
int main(int argc, char** argv) { //The order of initialisation may be wrong. TODO check. //For OGL3.2 glutInitContextVersion (3, 2); glutInitContextProfile(GLUT_CORE_PROFILE); //Usual glut code glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); #ifdef DEBUG //TODO: Check if freeglut is at least at version 2.60 (?) std::cout<< "Glut version:" << glutGet(GLUT_VERSION) << std::endl; #endif glutInitWindowSize(250, 250); glutInitWindowPosition(100, 100); glutCreateWindow("Hello"); init(); GLfloat square[] = {0.25, 0.25, 0.0, 0.75, 0.25, 0.0, 0.75, 0.75, 0.0,\ 0.25, 0.75, 0.0}; //Indices assume GL_TRIANGLES TODO-- check! GLuint square_indices[] = {0, 3, 2, 2, 1, 0}; //Using VBO's and VAO's //Generate the name for a Vertex Array GLuint vao_name; glGenVertexArrays(1, &vao_name); //Bind this vao as the currently used object glBindVertexArray(vao_name); //Create the names two vertex buffer object GLuint vbo_names[2]; glGenBuffers(2, vbo_names); //Bind the first vbo and indicate that it contains vertex data glBindBuffer(GL_ARRAY_BUFFER, vbo_names[0]); /* TODO: See if there is a better spec for vbo access * than GL_STATIC_DRAW */ //Copy the vertex data from the square array to this buffer glBufferData(GL_ARRAY_BUFFER, sizeof(GL_FLOAT) * 12, square,\ GL_STATIC_DRAW); /* Specify that the vertex data is going into vertex attribute zero. * in the vertex attribute array. Enable the corresponding attribute * in the array. */ glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); //Bind the second vbo as being an active buffer glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo_names[1]); //Copy the index data to the second vbo glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLuint) * 6, \ square_indices, GL_STATIC_DRAW); /* Specify that the index data is going into vertex attribute one * n the vertex attribute array. Enable the corresponding attribute * in the array. */ glVertexAttribPointer(1, 1, GL_INT, GL_FALSE, 0, 0); glEnableVertexAttribArray(1); //Shaders! GLchar *vertex_source, *fragment_source; GLuint vertex_shader, fragment_shader; GLuint shader_program; //Obtain the source for the shader programs. vertex_source = file_to_char_pointer("first_vertex_shader.glsl"); fragment_source = file_to_char_pointer("first_fragment_shader.glsl"); if((vertex_source != NULL) && (fragment_source != NULL)) { //Obtain the name for the shader program. shader_program = glCreateProgram(); //Obtain the names of the shaders vertex_shader = glCreateShader(GL_VERTEX_SHADER); fragment_shader = glCreateShader(GL_FRAGMENT_SHADER); //Set the source code of the shaders. //Fix this unsafe casting. glShaderSource(vertex_shader, 1, (const GLchar**)&vertex_source, NULL); //Strings \0 terminated glShaderSource(fragment_shader, 1, (const GLchar**) &fragment_source, NULL); //Compile the shaders glCompileShader(vertex_shader); glCompileShader(fragment_shader); //Attach the shaders to the program /* TODO: Figure out these lines carefully. Is the order of attaching * shaders important? */ glAttachShader(shader_program, vertex_shader); glAttachShader(shader_program, fragment_shader); //Link the program glLinkProgram(shader_program); //Bind parameters to the shader. glBindAttribLocation(shader_program, 0, "in_position"); //Set this program as the active shader program glUseProgram(shader_program); } glutDisplayFunc(display); glutMainLoop(); //Do cleanup. /* * CAUTION: Assumes that all the things that are cleaned up exist in the first place. This may not be true. */ glUseProgram(0); glDetachShader(shader_program, vertex_shader); glDetachShader(shader_program, fragment_shader); glDeleteProgram(shader_program); glDeleteShader(vertex_shader); glDeleteShader(fragment_shader); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glDeleteBuffers(2, vbo_names); glDeleteVertexArrays(1, &vao_name); delete vertex_source; delete fragment_source; return 0; }
int main(int argc, char *argv[]) { // Print a summary of the user-interface. printf("Welcome to the Adaptive Quadtree Meshing demo.\n"); printf("by Thatcher Ulrich <*****@*****.**> Copyright 2000\n\n"); printf("Use the mouse and keyboard to control the program. Here's a summary:\n"); printf(" * mouse-left plus mouse-move rotates the view orientation\n"); printf(" * mouse-right plus mouse-move moves the viewpoint\n"); printf(" * both mouse buttons plus mouse-move moves the viewpoint differently\n"); printf(" * 'w' toggles wireframe mode. Good for checking out the LOD\n"); printf(" * '0'-'9' controls the speed of viewpoint motion\n"); printf(" * 't' toggles texturing (off by default). Please try it\n"); printf(" * 'c' toggles backface culling\n"); printf(" * 'p' fixes the viewpoint at a certain altitude above the terrain\n"); printf(" * 'm' toggles motion mode\n"); printf(" * 'd' runs a 1-second benchmark and displays some performance data\n"); printf(" * '=' increases terrain detail\n"); printf(" * '-' decreases terrain detail\n"); printf("\n"); int i; root = new quadsquare(&RootCornerData); /* // Sample heightmap data. HeightMapInfo hm; hm.XOrigin = 30001; hm.ZOrigin = 30001; hm.XSize = 50; hm.ZSize = 50; hm.RowWidth = hm.XSize; hm.Scale = 0; hm.Data = new float[hm.XSize * hm.ZSize]; int i, j; for (j = 0; j < hm.ZSize; j++) { for (i = 0; i < hm.XSize; i++) { if (i == 0 || j == 0 || i == hm.XSize-1 || j == hm.ZSize - 1) hm.Data[i + j * hm.XSize] = 0; // Force boundary to 0. else hm.Data[i + j * hm.XSize] = sin(i * 0.1) * sin(j * 0.1) * 10; } } // Put some heightmap data in the quadtree. hm.Scale = 0; root->AddHeightMap(RootCornerData, hm); hm.Scale = 2; hm.XOrigin &= ~((1 << hm.Scale) - 1); hm.ZOrigin &= ~((1 << hm.Scale) - 1); root->AddHeightMap(RootCornerData, hm); hm.Scale = 6; hm.XOrigin &= ~((1 << hm.Scale) - 1); hm.ZOrigin &= ~((1 << hm.Scale) - 1); root->AddHeightMap(RootCornerData, hm); */ LoadData(); // Debug info. printf("nodes = %d\n", root->CountNodes()); printf("max error = %g\n", root->RecomputeErrorAndLighting(RootCornerData)); // Get rid of unnecessary nodes in flat-ish areas. printf("Culling unnecessary nodes (detail factor = 25)...\n"); root->StaticCullData(RootCornerData, 25); // Post-cull debug info. printf("nodes = %d\n", root->CountNodes()); printf("max error = %g\n", root->RecomputeErrorAndLighting(RootCornerData)); // Run the update function a few times before we start rendering // to disable unnecessary quadsquares, so the first frame won't // be overloaded with tons of triangles. for (i = 0; i < 10; i++) { root->Update(RootCornerData, (const float*) ViewerLoc, Detail); } // // Set up glut. // glutInit(&argc, argv); glutInitWindowSize(640, 480); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); int win_id = glutCreateWindow(argv[0]); if (win_id < 0) { printf("could not create window...exiting\n"); exit(1); } glutReshapeFunc(DisplayReshape); glutKeyboardFunc(KeyHandler); glutSpecialFunc(SpecialKeyHandler); glutMouseFunc(MouseHandler); glutMotionFunc(MotionHandler); glutIdleFunc(Idle); glutDisplayFunc(Display); glutMainLoop(); delete root; return 0; }
/* ---------------------------------------------------------------------------- */ int main(int argc, char **argv) { struct aiLogStream stream; glutInitWindowSize(900,600); glutInitWindowPosition(100,100); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInit(&argc, argv); glutCreateWindow("Assimp - Very simple OpenGL sample"); glutDisplayFunc(display); glutReshapeFunc(reshape); /* get a handle to the predefined STDOUT log stream and attach it to the logging system. It remains active for all further calls to aiImportFile(Ex) and aiApplyPostProcessing. */ stream = aiGetPredefinedLogStream(aiDefaultLogStream_STDOUT,NULL); aiAttachLogStream(&stream); /* ... same procedure, but this stream now writes the log messages to assimp_log.txt */ stream = aiGetPredefinedLogStream(aiDefaultLogStream_FILE,"assimp_log.txt"); aiAttachLogStream(&stream); /* the model name can be specified on the command line. If none is specified, we try to locate one of the more expressive test models from the repository (/models-nonbsd may be missing in some distributions so we need a fallback from /models!). */ if( 0 != loadasset( argc >= 2 ? argv[1] : "../../test/models-nonbsd/X/dwarf.x")) { if( argc != 1 || (0 != loadasset( "../../../../test/models-nonbsd/X/dwarf.x") && 0 != loadasset( "../../test/models/X/Testwuson.X"))) { return -1; } } glClearColor(0.1f,0.1f,0.1f,1.f); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* Uses default lighting parameters */ glEnable(GL_DEPTH_TEST); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); glEnable(GL_NORMALIZE); /* XXX docs say all polygons are emitted CCW, but tests show that some aren't. */ if(getenv("MODEL_IS_BROKEN")) glFrontFace(GL_CW); glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE); glutGet(GLUT_ELAPSED_TIME); glutMainLoop(); /* cleanup - calling 'aiReleaseImport' is important, as the library keeps internal resources until the scene is freed again. Not doing so can cause severe resource leaking. */ aiReleaseImport(scene); /* We added a log stream to the library, it's our job to disable it again. This will definitely release the last resources allocated by Assimp.*/ aiDetachAllLogStreams(); return 0; }
int main(int argc, char **argv) { int array_size_2d,totpoints,i; float rcol,gcol,bcol; FILE *fp_col; // The following parameters are usually read from a file, but // hard code them for the demo: ni=320; nj=112; vxin=0.04; roout=1.0; tau=0.51; // End of parameter list // Write parameters to screen printf ("ni = %d\n", ni); printf ("nj = %d\n", nj); printf ("vxin = %f\n", vxin); printf ("roout = %f\n", roout); printf ("tau = %f\n", tau); totpoints=ni*nj; array_size_2d=ni*nj*sizeof(float); // Allocate memory for arrays f0 = malloc(array_size_2d); f1 = malloc(array_size_2d); f2 = malloc(array_size_2d); f3 = malloc(array_size_2d); f4 = malloc(array_size_2d); f5 = malloc(array_size_2d); f6 = malloc(array_size_2d); f7 = malloc(array_size_2d); f8 = malloc(array_size_2d); tmpf0 = malloc(array_size_2d); tmpf1 = malloc(array_size_2d); tmpf2 = malloc(array_size_2d); tmpf3 = malloc(array_size_2d); tmpf4 = malloc(array_size_2d); tmpf5 = malloc(array_size_2d); tmpf6 = malloc(array_size_2d); tmpf7 = malloc(array_size_2d); tmpf8 = malloc(array_size_2d); plotvar = malloc(array_size_2d); plot_rgba = malloc(ni*nj*sizeof(unsigned int)); solid = malloc(ni*nj*sizeof(int)); // // Some factors used to calculate the f_equilibrium values // faceq1 = 4.f/9.f; faceq2 = 1.f/9.f; faceq3 = 1.f/36.f; // // Initialise f's by setting them to the f_equilibirum values assuming // that the whole domain is at velocity vx=vxin vy=0 and density ro=roout // for (i=0; i<totpoints; i++) { f0[i] = faceq1 * roout * (1.f - 1.5f*vxin*vxin); f1[i] = faceq2 * roout * (1.f + 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); f2[i] = faceq2 * roout * (1.f - 1.5f*vxin*vxin); f3[i] = faceq2 * roout * (1.f - 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); f4[i] = faceq2 * roout * (1.f - 1.5f*vxin*vxin); f5[i] = faceq3 * roout * (1.f + 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); f6[i] = faceq3 * roout * (1.f - 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); f7[i] = faceq3 * roout * (1.f - 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); f8[i] = faceq3 * roout * (1.f + 3.f*vxin + 4.5f*vxin*vxin - 1.5f*vxin*vxin); plotvar[i] = vxin; solid[i] = 1; } // // Read in colourmap data for OpenGL display // fp_col = fopen("cmap.dat","r"); if (fp_col==NULL) { printf("Error: can't open cmap.dat \n"); return 1; } // allocate memory for colourmap (stored as a linear array of int's) fscanf (fp_col, "%d", &ncol); cmap_rgba = (unsigned int *)malloc(ncol*sizeof(unsigned int)); // read colourmap and store as int's for (i=0;i<ncol;i++){ fscanf(fp_col, "%f%f%f", &rcol, &gcol, &bcol); cmap_rgba[i]=((int)(255.0f) << 24) | // convert colourmap to int ((int)(bcol * 255.0f) << 16) | ((int)(gcol * 255.0f) << 8) | ((int)(rcol * 255.0f) << 0); } fclose(fp_col); // // Iinitialise OpenGL display - use glut // glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(ni, nj); // Window of ni x nj pixels glutInitWindowPosition(50, 50); // position glutCreateWindow("2D LB"); // title // Check for OpenGL extension support printf("Loading extensions: %s\n", glewGetErrorString(glewInit())); if(!glewIsSupported( "GL_VERSION_2_0 " "GL_ARB_pixel_buffer_object " "GL_EXT_framebuffer_object " )){ fprintf(stderr, "ERROR: Support for necessary OpenGL extensions missing."); fflush(stderr); return; } // Set up view glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,ni,0.,nj, -200.0, 200.0); // Create texture which we use to display the result and bind to gl_Tex glEnable(GL_TEXTURE_2D); glGenTextures(1, &gl_Tex); // Generate 2D texture glBindTexture(GL_TEXTURE_2D, gl_Tex); // bind to gl_Tex // texture properties: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ni, nj, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); // Create pixel buffer object and bind to gl_PBO. We store the data we want to // plot in memory on the graphics card - in a "pixel buffer". We can then // copy this to the texture defined above and send it to the screen glGenBuffers(1, &gl_PBO); glBindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB, gl_PBO); printf("Buffer created.\n"); // Set the call-back functions and start the glut loop printf("Starting GLUT main loop...\n"); glutDisplayFunc(display); glutReshapeFunc(resize); glutIdleFunc(display); glutMouseFunc(mouse); glutMotionFunc(mouse_motion); glutMainLoop(); return 0; }
void Application::init() { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(500, 500); glutInitWindowPosition(100, 100); }