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) { 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) { int i; glutInitWindowSize(400, 200); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); glutInit(&argc, argv); for (i = 1; i < argc; i++) { if (!strcmp("-sb", argv[i])) { glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_MULTISAMPLE); singleBuffer = 1; } } glutCreateWindow("multilight"); glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); gluPerspective(50.0, 2.0, 0.1, 100.0); glMatrixMode(GL_MODELVIEW); gluLookAt( 0.0, 1.0, -16.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.); numActiveLights = MIN_VALUE(MAX_LIGHTS, 8); for (i = 0; i < numActiveLights; i++) { initLight(i); } glLightModelfv(GL_LIGHT_MODEL_AMBIENT, modelAmb); glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, GL_TRUE); glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); glEnable(GL_CULL_FACE); glEnable(GL_DEPTH_TEST); glMaterialfv(GL_FRONT, GL_AMBIENT, matAmb); glMaterialfv(GL_FRONT, GL_DIFFUSE, matDiff); glMaterialfv(GL_FRONT, GL_SPECULAR, matSpec); glMaterialfv(GL_FRONT, GL_EMISSION, matEmission); glMaterialf(GL_FRONT, GL_SHININESS, 10.0); glNewList(DL_LIGHT_SPHERE, GL_COMPILE); glutSolidSphere(0.2, 4, 4); glEndList(); glNewList(DL_BIG_SPHERE, GL_COMPILE); glutSolidSphere(1.5, 20, 20); glEndList(); glNewList(DL_ICO, GL_COMPILE); glutSolidIcosahedron(); glEndList(); glutDisplayFunc(display); glutVisibilityFunc(visible); glutKeyboardFunc(key); glutMouseFunc(mouse); glutMotionFunc(motion); glutCreateMenu(menu); glutAddMenuEntry("Sphere", M_SPHERE); glutAddMenuEntry("Icosahedron", M_ICO); glutAddMenuEntry("Linear attenuation", M_LINEAR); glutAddMenuEntry("Quadratic attenuation", M_QUAD); glutAddMenuEntry("Toggle Light Number Labels", M_LABELS); glutAddMenuEntry("Report Light Significance", M_REPORT_SIG); glutAddMenuEntry("Lambertian-based Significance", M_LAMBERTIAN); glutAddMenuEntry("Distance-based Significance", M_DISTANCE); glutAddMenuEntry("Time Frames", M_TIME); glutAddMenuEntry("Quit", 666); glutAttachMenu(GLUT_RIGHT_BUTTON); glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
/* Parse arguments, and set up interface between OpenGL and window system */ int main(int argc, char *argv[]) { GLUquadricObj *sphere, *cone, *base; GLfloat v0[3], v1[3], v2[3]; unsigned *floortex; int texcomps, texwid, texht; glutInit(&argc, argv); glutInitWindowSize(512, 512); if(argc > 1) { char *args = argv[1]; int done = GL_FALSE; while(!done) { switch(*args) { case 's': /* single buffer */ printf("Single Buffered\n"); dblbuf = GL_FALSE; break; case '-': /* do nothing */ break; case 0: done = GL_TRUE; break; } args++; } } if(dblbuf) glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL|GLUT_DOUBLE); else glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); (void)glutCreateWindow("projection shadows"); glutDisplayFunc(redraw); glutKeyboardFunc(key); glutMouseFunc(mouse); glutMotionFunc(motion); glutReshapeFunc(reshape); glutCreateMenu(menu); glutAddMenuEntry("No Shadows", NONE); glutAddMenuEntry("Black Shadows", SHADOW_BLACK); glutAddMenuEntry("Shadows on Texture", SHADOW); glutAttachMenu(GLUT_RIGHT_BUTTON); /* draw a perspective scene */ glMatrixMode(GL_PROJECTION); glFrustum(-100., 100., -100., 100., 320., 640.); glMatrixMode(GL_MODELVIEW); /* turn on features */ glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* make shadow matricies */ /* 3 points on floor */ v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f; v1[X] = 100.f; v1[Y] = -100.f; v1[Z] = -320.f; v2[X] = 100.f; v2[Y] = -100.f; v2[Z] = -520.f; findplane(floorplane, v0, v1, v2); shadowmatrix(floorshadow, floorplane, lightpos); /* 3 points on left wall */ v0[X] = -100.f; v0[Y] = -100.f; v0[Z] = -320.f; v1[X] = -100.f; v1[Y] = -100.f; v1[Z] = -520.f; v2[X] = -100.f; v2[Y] = 100.f; v2[Z] = -520.f; findplane(lwallplane, v0, v1, v2); shadowmatrix(leftwallshadow, lwallplane, lightpos); /* place light 0 in the right place */ glLightfv(GL_LIGHT0, GL_POSITION, lightpos); /* remove back faces to speed things up */ glCullFace(GL_BACK); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); /* make display lists for sphere and cone; for efficiency */ glNewList(WALLS, GL_COMPILE); glColor3f(1.f, 1.f, 1.f); glBegin(GL_QUADS); /* right wall */ glNormal3f(-1.f, 0.f, 0.f); glVertex3f( 100.f, -100.f, -320.f); glVertex3f( 100.f, 100.f, -320.f); glVertex3f( 100.f, 100.f, -520.f); glVertex3f( 100.f, -100.f, -520.f); /* ceiling */ glNormal3f(0.f, -1.f, 0.f); glVertex3f(-100.f, 100.f, -320.f); glVertex3f(-100.f, 100.f, -520.f); glVertex3f( 100.f, 100.f, -520.f); glVertex3f( 100.f, 100.f, -320.f); /* back wall */ glNormal3f(0.f, 0.f, 1.f); glVertex3f(-100.f, -100.f, -520.f); glVertex3f( 100.f, -100.f, -520.f); glVertex3f( 100.f, 100.f, -520.f); glVertex3f(-100.f, 100.f, -520.f); glEnd(); glEndList(); glNewList(SPHERE, GL_COMPILE); sphere = gluNewQuadric(); glPushMatrix(); glTranslatef(60.f, -50.f, -360.f); gluSphere(sphere, 20.f, 20, 20); gluDeleteQuadric(sphere); glPopMatrix(); glEndList(); glNewList(LIGHT, GL_COMPILE); sphere = gluNewQuadric(); gluSphere(sphere, 5.f, 20, 20); gluDeleteQuadric(sphere); glEndList(); glNewList(CONE, GL_COMPILE); cone = gluNewQuadric(); base = gluNewQuadric(); glPushMatrix(); glTranslatef(-40.f, -40.f, -400.f); glRotatef(-90.f, 1.f, 0.f, 0.f); gluDisk(base, 0., 20., 20, 1); gluCylinder(cone, 20., 0., 60., 20, 20); gluDeleteQuadric(cone); gluDeleteQuadric(base); glPopMatrix(); glEndList(); glNewList(SHADOWERS, GL_COMPILE); glCallList(CONE); glCallList(SPHERE); glEndList(); glNewList(FLOOR, GL_COMPILE); /* make the floor textured */ glEnable(GL_TEXTURE_2D); glBegin(GL_QUADS); glNormal3f(0.f, 1.f, 0.f); glTexCoord2i(0, 0); glVertex3f(-100.f, -100.f, -320.f); glTexCoord2i(1, 0); glVertex3f( 100.f, -100.f, -320.f); glTexCoord2i(1, 1); glVertex3f( 100.f, -100.f, -520.f); glTexCoord2i(0, 1); glVertex3f(-100.f, -100.f, -520.f); glEnd(); glDisable(GL_TEXTURE_2D); glEndList(); glNewList(LEFTWALL, GL_COMPILE); glBegin(GL_QUADS); /* left wall */ glNormal3f(1.f, 0.f, 0.f); glVertex3f(-100.f, -100.f, -320.f); glVertex3f(-100.f, -100.f, -520.f); glVertex3f(-100.f, 100.f, -520.f); glVertex3f(-100.f, 100.f, -320.f); glEnd(); glEndList(); floortex = read_texture("../../data/wood0.rgb", &texwid, &texht, &texcomps); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA, GL_UNSIGNED_BYTE, floortex); free(floortex); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glutMainLoop(); return 0; }
int main(int argc, char **argv) { int width = 320, height = 240; int i; char *name; glutInitWindowSize(width, height); glutInit(&argc, argv); /* process commmand line args */ for (i = 1; i < argc; ++i) { if (!strcmp("-db", argv[i])) { useDB = !useDB; } else { usage(); } } /* choose visual */ glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); name = "MOTH - by Bob Doyle"; glutCreateWindow(name); glutKeyboardFunc(keyboard); myInit(); /* initialize objects in scene */ glutDisplayFunc(display); glutVisibilityFunc(visible); glutCreateMenu(menu_select); glutAddMenuEntry("Start motion", 1); glutAddMenuEntry("Stop motion", 2); glutAddMenuEntry("Quit", 5); glutAddMenuEntry("Drink Ed's beer", 5); glutAttachMenu(GLUT_RIGHT_BUTTON); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-.9, .9, -.9, .9, 1.0, 35.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); #if 0 glTranslatef(0.0, 0.0, mvt_zi); #endif glEnable(GL_NORMALIZE); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); /* double your fun */ glShadeModel(GL_SMOOTH); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); myInit(); /* initialize objects in scene */ glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int argc, char *argv[]) { // inicjalizacja biblioteki GLUT glutInit(&argc, argv); // inicjalizacja bufora ramki glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); // rozmiary głównego okna programu glutInitWindowSize(500, 500); // utworzenie głównego okna programu glutCreateWindow("Zadanie 2"); // dołączenie funkcji generującej scenę 3D glutDisplayFunc(DisplayScene); // dołączenie funkcji wywoływanej przy zmianie rozmiaru okna glutReshapeFunc(Reshape); // dołączenie funkcji obsługi klawiatury glutKeyboardFunc(Keyboard); // utworzenie podmenu - Filtr pomniejszający int MenuMinFilter = glutCreateMenu(Menu); glutAddMenuEntry("GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST); glutAddMenuEntry("GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR); glutAddMenuEntry("GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST); glutAddMenuEntry("GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR); // utworzenie podmenu - Aspekt obrazu int MenuAspect = glutCreateMenu(Menu); #ifdef WIN32 glutAddMenuEntry("Aspekt obrazu - całe okno", FULL_WINDOW); #else glutAddMenuEntry("Aspekt obrazu - cale okno", FULL_WINDOW); #endif glutAddMenuEntry("Aspekt obrazu 1:1", ASPECT_1_1); // menu główne glutCreateMenu(Menu); #ifdef WIN32 glutAddSubMenu("Filtr pomniejszający", MenuMinFilter); glutAddSubMenu("Aspekt obrazu", MenuAspect); glutAddMenuEntry("Wyjście", EXIT); #else glutAddSubMenu("Filtr pomniejszajacy", MenuMinFilter); glutAddSubMenu("Aspekt obrazu", MenuAspect); glutAddMenuEntry("Wyjscie", EXIT); #endif // określenie przycisku myszki obsługującego menu podręczne glutAttachMenu(GLUT_RIGHT_BUTTON); // sprawdzenie i przygotowanie obsługi wybranych rozszerzeñ ExtensionSetup(); // utworzenie list wyświetlania GenerateDisplayLists(); // wprowadzenie programu do obsługi pętli komunikatów glutMainLoop(); return 0; }
int main( int argc, char **argv ) { // Parse the arguments if (argc < 2) { printf("Missing arguments ... use:\n"); printf("./raycast step_max <options>\n"); return -1; } /* if (strcmp(argv[1], "-u") == 0) { // user defined scene set_up_user_scene(); } else { // default scene set_up_default_scene(); } */ step_max = atoi(argv[1]); // maximum level of recursions // Optional arguments for(int i = 2; i < argc; i++) { if (strcmp(argv[i], "+s") == 0) shadow_on = 1; if (strcmp(argv[i], "+l") == 0) reflect_on = 1; //if (strcmp(argv[i], "+c") == 0) chessboard_on = 1; if (strcmp(argv[i], "+r") == 0) refract_on = 1; if (strcmp(argv[i], "+f") == 0) difref_on = 1; if (strcmp(argv[i], "+p") == 0) antiAlias_on = 1; if (strcmp(argv[i], "+t") == 0) triangle_on = 1; } set_up_global_variable(); if(chessboard_on = 1) set_up_chessboard(); if(triangle_on) set_up_triangles(); //printf("object Count : %d\n",objectCount); set_up_chessPiece(); //printObjects(); // ray trace the scene now // we have used so many global variables and this function is // happy to carry no parameters printf("Rendering scene using my fantastic ray tracer ...\n"); ray_trace(); printf("After ray trace\n"); // we want to make sure that intensity values are normalized histogram_normalization(); // Show the result in glut via texture mapping glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); glutInitWindowSize( WIN_WIDTH, WIN_HEIGHT ); glutCreateWindow( "Ray tracing" ); glewInit(); #ifndef __NO_DISPLAY__ init(); #endif printf("After init\n"); glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }
// Initialize GLUT & OpenSG and set up the scene int main (int argc, char **argv) { int i; float ca=-1,cb=-1,cc=-1; // OSG init osgInit(argc,argv); char *filename=NULL; // GLUT init glutInit(&argc, argv); glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE); int winid = glutCreateWindow("OpenSG"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(key); // the connection between GLUT and OpenSG GLUTWindowPtr gwin= GLUTWindow::create(); gwin->setId(winid); gwin->init(); // create the scene float x,y,z; scene = Node::create(); beginEditCP(scene); scene->setCore(Group::create()); endEditCP(scene); NodePtr file; for(i=1;i<argc;++i) { if(argv[i][0] =='-') { switch(argv[i][1]) { case 'd': useFaceDistribution=true; break; case 'v': viewVolume=true; break; case 's': serverCount=atoi(&argv[i][2]); break; case 'l': loop=atoi(&argv[i][2]); break; case 'S': simulateRendering=true; break; } } else { if(argv[i][0] >='0' && argv[i][0] <='9') { if(ca==-1) ca=atoi(argv[i]); else if(cb==-1) cb=atoi(argv[i]); else if(cc==-1) cc=atoi(argv[i]); } else { filename=argv[1]; } } } if(ca == -1 && filename) { file = OSG::SceneFileHandler::the().read(filename); beginEditCP(scene); scene->addChild(file); endEditCP(scene); } else { if(ca==-1) ca=4; if(cb==-1) cb=ca; if(cc==-1) cc=cb; if(file == NullFC) { GeometryPtr geo=makeBoxGeo(.6,.6,.6,20,20,20); beginEditCP(geo); SimpleMaterialPtr mat=SimpleMaterial::create(); beginEditCP(mat); mat->setAmbient(Color3f(.4,.4,.4)); mat->setSpecular(Color3f(0,0,0)); mat->setDiffuse(Color3f(1,1,1)); endEditCP(mat); geo->setMaterial(mat); endEditCP(geo); NodePtr node; NodePtr geoNode; TransformPtr trans; for(x=-ca/2 ; x<ca/2 ; x++) for(y=-cb/2 ; y<cb/2 ; y++) for(z=-cc/2 ; z<cc/2 ; z++) { trans=Transform::create(); node=Node::create(); geoNode=Node::create(); beginEditCP(geoNode); beginEditCP(trans); beginEditCP(node); node->setCore(trans); trans->getMatrix().setTranslate(x,y,z); if(!filename) { geoNode=Node::create(); geoNode->setCore(geo); } else { geoNode = OSG::SceneFileHandler::the().read(filename); } node->addChild( geoNode ); beginEditCP(scene); scene->addChild(node); endEditCP(geoNode); endEditCP(scene); endEditCP(trans); endEditCP(node); } } } // create the SimpleSceneManager helper mgr = new MySceneManager; mgr->setWindow( gwin ); mgr->setRoot( scene ); mgr->showAll(); // GLUT main loop if(loop) glutIdleFunc(display); // glutReshapeWindow(720,576); glutReshapeWindow(1152,864); 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; }
//-----------------------------------------------------------------------------------------------------------------------// // main //-----------------------------------------------------------------------------------------------------------------------// int main(int argc, char * argv[]) { int rc=0; int rank=0; #ifdef MPI int comsize; // init MPI MPI_Init(&argc, &argv); MPI_Comm_size(MPI_COMM_WORLD, &comsize); MPI_Comm_rank(MPI_COMM_WORLD, &rank); fprintf(stderr,"rank=%d\n", rank); #ifdef BGQ install_signal_handler(); #endif #endif args = parseargs(argc, argv); // init, initcamera, initvolattrs if ((rc=init(args, rank) != 0)) { fprintf(stderr, "initialization failed: %d\n", rc); return 0; }; //---------------------------- Platform Specific Display and Interaction ----------------------------------------// #if LOCAL resettransforms(); mystate.alpha=0.25f; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); glutInitWindowSize(WINDOWWIDTH, WINDOWHEIGHT); glutCreateWindow("iVR"); glutReshapeFunc(reshape); glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMouseFunc(mousebutton); glutMotionFunc(mousemotion); // glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glDisable(GL_DEPTH_TEST); glutMainLoop(); #elif MPI // BEGIN MPI CODE #ifdef REMOTE // START OF REMOTE RENDERING HANDSHAKE // connect to relay server if (rank == 0) { sockfd = initconnection(HOSTNAME, PORT); if (sockfd == -1) { fprintf(stderr,"remote connection failed, sockfd=%d\n",sockfd); freeall(); exit(0); } fprintf(stderr,"relay connection succeeded\n"); } PRINTDEBUG("%3d: \n", rank); boolean_t connected = TRUE; int ctr = 0; while (connected) { // main loop when steering fprintf(stderr,"%3d: before steering control\n", rank); if (rank == 0) { rc = recvstate(sockfd, &mystate); fprintf(stderr,"bytes recvd=%d\n", rc); if (mystate.finish) connected = 0;; winwidth = mystate.winwidth; winheight=mystate.winheight; } // end if rank == 0 for remote visualization // wait until we've completed the handshake with steering client before proceeding; MPI_Barrier(MPI_COMM_WORLD); MPI_Bcast(&connected, 1, MPI_INT, 0, MPI_COMM_WORLD); if (!connected) break; MPI_Bcast((float *)&winwidth, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast((float *)&winheight, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(&mystate.alpha, 1, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(mystate.newconst, 6, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(mystate.mvm, 16, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(mystate.pm, 16, MPI_FLOAT, 0, MPI_COMM_WORLD); MPI_Bcast(mystate.vv, 4, MPI_FLOAT, 0, MPI_COMM_WORLD); #endif float planeconst[6] = {pzero[0], pzero[1], pzero[2], pzero[3], pzero[4], pzero[5]}; setviewport(&viewport, 0, 0, winwidth, winheight); setplaneconst(planeconst, mystate.newconst); setmvm(mvm, mystate.mvm); setpm(pm, mystate.pm); setfrustum(&viewvolume, mystate.vv); updatevolbbox(); initcolbufs(rank); // create and display the image unsigned long long lstart, lstop; for (int i=0; i<1; i++) { TIME(RENDER, lstart); createlocalimage(rank); // can't composite until all ranks have completed local image generation MPI_Barrier(MPI_COMM_WORLD); compositelocalimage(); TIME(RENDER, lstop); PERFORMANCE(lstart, lstop, framenum, elapsed, avg); } // wait until all ranks exit composite step before writing image MPI_Barrier(MPI_COMM_WORLD); writeimage(ctr++); #ifdef REMOTE } // end while remote loop if (rank == 0) disconnect(sockfd); #endif // END OF REMOTE CLIENT HANDSHAKE fprintf(stderr,"%3d: finished\n", rank); MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); #endif // clean up freeall(); exit(0); }
int main(int argc, char** argv) { // Standard stuff... glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(1080, 600); glutCreateWindow("Lighted Cube"); glutReshapeFunc(changeViewport); glutKeyboardFunc(keyboardFunc); glutDisplayFunc(render); glewInit(); initMatrices(); // New <======================================== // Make a shader char* vertexShaderSourceCode = readFile("vertexShader.vsh"); char* fragmentShaderSourceCode = readFile("fragmentShader.fsh"); GLuint vertShaderID = makeVertexShader(vertexShaderSourceCode); GLuint fragShaderID = makeFragmentShader(fragmentShaderSourceCode); shaderProgramID = makeShaderProgram(vertShaderID, fragShaderID); // Create the "remember all" glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); // Create the buffer, but don't load anything yet //glBufferData(GL_ARRAY_BUFFER, 7*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, 6 * NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW); // NEW! - we're only loading vertices and normals (6 elements, not 7) // Load the vertex points glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * NUM_VERTICES*sizeof(GLfloat), vertices); // Load the colors right after that //glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),4*NUM_VERTICES*sizeof(GLfloat), colors); glBufferSubData(GL_ARRAY_BUFFER, 3 * NUM_VERTICES*sizeof(GLfloat), 3 * NUM_VERTICES*sizeof(GLfloat), normals); #ifdef USING_INDEX_BUFFER glGenBuffers(1, &indexBufferID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, NUM_INDICES*sizeof(GLuint), indices, GL_STATIC_DRAW); #endif // Find the position of the variables in the shader positionID = glGetAttribLocation(shaderProgramID, "s_vPosition"); normalID = glGetAttribLocation(shaderProgramID, "s_vNormal"); // NEW lightID1 = glGetUniformLocation(shaderProgramID, "vLight1"); // NEW lightID2 = glGetUniformLocation(shaderProgramID, "vLight2"); // NEW // ============ New! glUniformLocation is how you pull IDs for uniform variables=============== perspectiveMatrixID = glGetUniformLocation(shaderProgramID, "mP"); viewMatrixID = glGetUniformLocation(shaderProgramID, "mV"); modelMatrixID = glGetUniformLocation(shaderProgramID, "mM"); allRotsMatrixID = glGetUniformLocation(shaderProgramID, "mRotations"); // NEW //============================================================================================= glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0); glVertexAttribPointer(normalID, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices))); glUseProgram(shaderProgramID); glEnableVertexAttribArray(positionID); glEnableVertexAttribArray(normalID); // NEW glEnable(GL_CULL_FACE); // NEW! - we're doing real 3D now glCullFace(GL_BACK); // Other options? GL_FRONT and GL_FRONT_AND_BACK glEnable(GL_DEPTH_TEST); // Make sure the depth buffer is on. As you draw a pixel, update the screen only if it's closer than previous ones glutMainLoop(); return 0; }
// ------------------------------------------------------------------- main --- int main( int argc, char **argv ) { FILE* test; size_t i, j; int arg; wchar_t * font_cache = L" !\"#$%&'()*+,-./0123456789:;<=>?" L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_" L"`abcdefghijklmnopqrstuvwxyz{|}~"; float font_size = 0.0; const char * font_filename = NULL; const char * header_filename = NULL; const char * variable_name = "font"; int show_help = 0; for ( arg = 1; arg < argc; ++arg ) { if ( 0 == strcmp( "--font", argv[arg] ) || 0 == strcmp( "-f", argv[arg] ) ) { ++arg; if ( font_filename ) { fprintf( stderr, "Multiple --font parameters.\n" ); print_help(); exit( 1 ); } if ( arg >= argc ) { fprintf( stderr, "No font file given.\n" ); print_help(); exit( 1 ); } font_filename = argv[arg]; continue; } if ( 0 == strcmp( "--header", argv[arg] ) || 0 == strcmp( "-o", argv[arg] ) ) { ++arg; if ( header_filename ) { fprintf( stderr, "Multiple --header parameters.\n" ); print_help(); exit( 1 ); } if ( arg >= argc ) { fprintf( stderr, "No header file given.\n" ); print_help(); exit( 1 ); } header_filename = argv[arg]; continue; } if ( 0 == strcmp( "--help", argv[arg] ) || 0 == strcmp( "-h", argv[arg] ) ) { show_help = 1; break; } if ( 0 == strcmp( "--size", argv[arg] ) || 0 == strcmp( "-s", argv[arg] ) ) { ++arg; if ( 0.0 != font_size ) { fprintf( stderr, "Multiple --size parameters.\n" ); print_help(); exit( 1 ); } if ( arg >= argc ) { fprintf( stderr, "No font size given.\n" ); print_help(); exit( 1 ); } errno = 0; font_size = atof( argv[arg] ); if ( errno ) { fprintf( stderr, "No valid font size given.\n" ); print_help(); exit( 1 ); } continue; } if ( 0 == strcmp( "--variable", argv[arg] ) || 0 == strcmp( "-arg", argv[arg] ) ) { ++arg; if ( 0 != strcmp( "font", variable_name ) ) { fprintf( stderr, "Multiple --variable parameters.\n" ); print_help(); exit( 1 ); } if ( arg >= argc ) { fprintf( stderr, "No variable name given.\n" ); print_help(); exit( 1 ); } variable_name = argv[arg]; continue; } fprintf( stderr, "Unknown parameter %s\n", argv[arg] ); print_help(); exit( 1 ); } if ( show_help ) { print_help(); exit( 1 ); } if ( !font_filename ) { fprintf( stderr, "No font file given.\n" ); print_help(); exit( 1 ); } if ( !( test = fopen( font_filename, "r" ) ) ) { fprintf( stderr, "Font file \"%s\" does not exist.\n", font_filename ); } fclose( test ); if ( 4.0 > font_size ) { fprintf( stderr, "Font size too small, expected at least 4 pt.\n" ); print_help(); exit( 1 ); } if ( !header_filename ) { fprintf( stderr, "No header file given.\n" ); print_help(); exit( 1 ); } texture_atlas_t * atlas = texture_atlas_new( 128, 128, 1 ); texture_font_t * font = texture_font_new_from_file( atlas, font_size, font_filename ); glutInit( &argc, argv ); glutInitWindowSize( atlas->width, atlas->height ); glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ); glutCreateWindow( "Freetype OpenGL" ); glutReshapeFunc( reshape ); glutDisplayFunc( display ); glutKeyboardFunc( keyboard ); size_t missed = texture_font_load_glyphs( font, font_cache ); wprintf( L"Font filename : %s\n", font_filename ); wprintf( L"Font size : %.1f\n", font_size ); wprintf( L"Number of glyphs : %ld\n", wcslen(font_cache) ); wprintf( L"Number of missed glyphs : %ld\n", missed ); wprintf( L"Texture size : %ldx%ldx%ld\n", atlas->width, atlas->height, atlas->depth ); wprintf( L"Texture occupancy : %.2f%%\n", 100.0*atlas->used/(float)(atlas->width*atlas->height) ); wprintf( L"\n" ); wprintf( L"Header filename : %s\n", header_filename ); wprintf( L"Variable name : %s\n", variable_name ); size_t texture_size = atlas->width * atlas->height *atlas->depth; size_t glyph_count = font->glyphs->size; size_t max_kerning_count = 1; for( i=0; i < glyph_count; ++i ) { texture_glyph_t *glyph = *(texture_glyph_t **) vector_get( font->glyphs, i ); if( vector_size(glyph->kerning) > max_kerning_count ) { max_kerning_count = vector_size(glyph->kerning); } } FILE *file = fopen( header_filename, "w" ); // ------------- // Header // ------------- fwprintf( file, L"/* ============================================================================\n" L" * Freetype GL - A C OpenGL Freetype engine\n" L" * Platform: Any\n" L" * WWW: http://code.google.com/p/freetype-gl/\n" L" * ----------------------------------------------------------------------------\n" L" * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.\n" L" *\n" L" * Redistribution and use in source and binary forms, with or without\n" L" * modification, are permitted provided that the following conditions are met:\n" L" *\n" L" * 1. Redistributions of source code must retain the above copyright notice,\n" L" * this list of conditions and the following disclaimer.\n" L" *\n" L" * 2. Redistributions in binary form must reproduce the above copyright\n" L" * notice, this list of conditions and the following disclaimer in the\n" L" * documentation and/or other materials provided with the distribution.\n" L" *\n" L" * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR\n" L" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n" L" * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO\n" L" * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\n" L" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n" L" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\n" L" * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND\n" L" * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" L" * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\n" L" * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" L" *\n" L" * The views and conclusions contained in the software and documentation are\n" L" * those of the authors and should not be interpreted as representing official\n" L" * policies, either expressed or implied, of Nicolas P. Rougier.\n" L" * ===============================================================================\n" L" */\n"); // ---------------------- // Structure declarations // ---------------------- fwprintf( file, L"#include <stddef.h>\n" L"#ifdef __cplusplus\n" L"extern \"C\" {\n" L"#endif\n" L"\n" L"typedef struct\n" L"{\n" L" wchar_t charcode;\n" L" float kerning;\n" L"} kerning_t;\n\n" ); fwprintf( file, L"typedef struct\n" L"{\n" L" wchar_t charcode;\n" L" int width, height;\n" L" int offset_x, offset_y;\n" L" float advance_x, advance_y;\n" L" float s0, t0, s1, t1;\n" L" size_t kerning_count;\n" L" kerning_t kerning[%d];\n" L"} texture_glyph_t;\n\n", max_kerning_count ); fwprintf( file, L"typedef struct\n" L"{\n" L" size_t tex_width;\n" L" size_t tex_height;\n" L" size_t tex_depth;\n" L" char tex_data[%d];\n" L" float size;\n" L" float height;\n" L" float linegap;\n" L" float ascender;\n" L" float descender;\n" L" size_t glyphs_count;\n" L" texture_glyph_t glyphs[%d];\n" L"} texture_font_t;\n\n", texture_size, glyph_count ); fwprintf( file, L"texture_font_t %s = {\n", variable_name ); // ------------ // Texture data // ------------ fwprintf( file, L" %d, %d, %d, \n", atlas->width, atlas->height, atlas->depth ); fwprintf( file, L" {" ); for( i=0; i < texture_size; i+= 32 ) { for( j=0; j < 32 && (j+i) < texture_size ; ++ j) { if( (j+i) < (texture_size-1) ) { fwprintf( file, L"%d,", atlas->data[i+j] ); } else { fwprintf( file, L"%d", atlas->data[i+j] ); } } if( (j+i) < texture_size ) { fwprintf( file, L"\n " ); } } fwprintf( file, L"}, \n" ); // ------------------- // Texture information // ------------------- fwprintf( file, L" %ff, %ff, %ff, %ff, %ff, %d, \n", font->size, font->height, font->linegap,font->ascender, font->descender, glyph_count ); // -------------- // Texture glyphs // -------------- fwprintf( file, L" {\n" ); for( i=0; i < glyph_count; ++i ) { texture_glyph_t * glyph = *(texture_glyph_t **) vector_get( font->glyphs, i ); /* // Debugging information wprintf( L"glyph : '%lc'\n", glyph->charcode ); wprintf( L" size : %dx%d\n", glyph->width, glyph->height ); wprintf( L" offset : %+d%+d\n", glyph->offset_x, glyph->offset_y ); wprintf( L" advance : %ff, %ff\n", glyph->advance_x, glyph->advance_y ); wprintf( L" tex coords.: %ff, %ff, %ff, %ff\n", glyph->u0, glyph->v0, glyph->u1, glyph->v1 ); wprintf( L" kerning : " ); if( glyph->kerning_count ) { for( j=0; j < glyph->kerning_count; ++j ) { wprintf( L"('%lc', %ff)", glyph->kerning[j].charcode, glyph->kerning[j].kerning ); if( j < (glyph->kerning_count-1) ) { wprintf( L", " ); } } } else { wprintf( L"None" ); } wprintf( L"\n\n" ); */ // TextureFont if( (glyph->charcode == L'\'' ) || (glyph->charcode == L'\\' ) ) { fwprintf( file, L" {L'\\%lc', ", glyph->charcode ); //wprintf( L" {L'\\%lc', ", glyph->charcode ); } else if( glyph->charcode == (wchar_t)(-1) ) { fwprintf( file, L" {L'\\0', " ); //wprintf( L" {L'\\0', " ); } else { fwprintf( file, L" {L'%lc', ", glyph->charcode ); //wprintf( L" {L'%lc', ", glyph->charcode ); } fwprintf( file, L"%d, %d, ", glyph->width, glyph->height ); fwprintf( file, L"%d, %d, ", glyph->offset_x, glyph->offset_y ); fwprintf( file, L"%ff, %ff, ", glyph->advance_x, glyph->advance_y ); fwprintf( file, L"%ff, %ff, %ff, %ff, ", glyph->s0, glyph->t0, glyph->s1, glyph->t1 ); fwprintf( file, L"%d, ", vector_size(glyph->kerning) ); fwprintf( file, L"{ " ); for( j=0; j < vector_size(glyph->kerning); ++j ) { kerning_t *kerning = (kerning_t *) vector_get( glyph->kerning, j); wchar_t charcode = kerning->charcode; if( (charcode == L'\'' ) || (charcode == L'\\') ) { fwprintf( file, L"{L'\\%lc', %ff}", charcode, kerning->kerning ); } else if( (charcode != (wchar_t)(-1) ) ) { fwprintf( file, L"{L'%lc', %ff}", charcode, kerning->kerning ); } if( j < (vector_size(glyph->kerning)-1)) { fwprintf( file, L", " ); } } fwprintf( file, L"} },\n" ); } fwprintf( file, L" }\n};\n" ); fwprintf( file, L"#ifdef __cplusplus\n" L"}\n" L"#endif\n" ); return 0; }
void RenderThread::operator()() { RENDER.SetTimeStamp(getElapsedTime()); // -- Start the Clock ------------------------------------------- // g_ullAppStartTime = RENDER.GrabTimeStamp(); PROF.StartProfiling(g_ullAppStartTime); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(GAMECONFIG.m_uiWindowWidth, GAMECONFIG.m_uiWindowHeight); glutInit(&m_argc, m_argv); if (!GAMECONFIG.m_bWindowedMode) { char temp[64]; sprintf_s(temp, "%dx%d:%d@%d", GAMECONFIG.m_uiWindowWidth, GAMECONFIG.m_uiWindowHeight, 32, 75); glutGameModeString(temp); // start fullscreen game mode glutEnterGameMode(); } else { glutCreateWindow("Swarm: Rise of the Transactional Tripods"); } atexit(gKillGame); glutKeyboardFunc(gKeyboard); glutDisplayFunc(gRender); glutReshapeFunc(gChangeSize); glutIdleFunc(gIdle); // -- VSync ----------------------------------------------------- // // Note that OpenGL by default blocks // rendering to match the actual monitor refresh rate // // We want to push frames ASAP, perhaps starting a new one // before the old one is presented to the monitor. This allows // for FPS of thousands on very simple apps. // // I do not know the linux equivalent of this code #ifdef _MSC_VER if (!GAMECONFIG.m_bVSyncLock) { typedef bool (APIENTRY *PFNWGLSWAPINTERVALFARPROC)(int); PFNWGLSWAPINTERVALFARPROC wglSwapIntervalEXT = 0; wglSwapIntervalEXT = (PFNWGLSWAPINTERVALFARPROC)wglGetProcAddress("wglSwapIntervalEXT"); if (wglSwapIntervalEXT) wglSwapIntervalEXT(0); } #endif // -- Set GL for RENDER ----------------------------------------- // RENDER.ConfigureRenderer(); // -- Give GLUT control of this thread forever ------------------ // glutMainLoop(); }
FreeGlutGLView* FreeGlutGLView::start(void* _renderer, std::string name, int _width, int _height) { printf("freglutglview start"); renderer = (RendererWin32*) _renderer; /* annoying useless setup for glutInit */ char* argv[] = {_strdup(name.c_str())}; int argc = 1; glutInit(&argc, argv); glutInitContextVersion(3,3); printf("freglutglview start"); glutInitWindowSize(_width, _height); glutCreateWindow(name.c_str()); //glew initialization glewExperimental = GL_TRUE; GLenum err = glewInit(); if (GLEW_OK != err) { cerr << "Error: " << glewGetErrorString(err) << endl; } else { if (GLEW_VERSION_3_3) { cout << "Driver supports OpenGL 3.3\nDetails:" << endl; } } err = glGetError(); //this is to ignore INVALID ENUM error 1282 // GL_CHECK_ERRORS //output hardware information cout << "\tUsing GLEW " << glewGetString(GLEW_VERSION) << endl; cout << "\tVendor: " << glGetString(GL_VENDOR) << endl; cout << "\tRenderer: " << glGetString(GL_RENDERER) << endl; cout << "\tVersion: " << glGetString(GL_VERSION) << endl; cout << "\tGLSL: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << endl; // call this ONLY when linking with FreeImage as a static library #ifdef FREEIMAGE_LIB FreeImage_Initialise(); cout << "\tFreeImage: " << FreeImage_GetVersion() << endl; #endif // glutGameModeString("1280x1024:32@60"); // glutEnterGameMode(); renderer->setStartTick(); renderer->onCreate(); glutDisplayFunc(&display); glutReshapeFunc(&reshape); glutKeyboardFunc(&keyboard); glutMouseFunc(&pressed); glutMotionFunc(&dragged); glutPassiveMotionFunc(&moved); glutIdleFunc(&animate); printf("freglutglview start"); //lastTime = std::clock(); //std::time(&lastTime); //gettimeofday(&lastTime, NULL); printf("freglutglview start"); glutMainLoop(); //glutInitDisplayMode(GL_RGBA); //glutInitWindowSize(200,200); //glutCreateWindow("test"); printf("freglutglview start"); return NULL; //return glView; }
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; }
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; }
void set_keyboard_function(void (*keyboard)(unsigned char key, int mouseX, int mouseY)) { glutKeyboardFunc(keyboard); }
int main (int argc, char** argv) { // Standard stuff... glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH); glutInitWindowSize(800, 600); glutCreateWindow("Index Buffers"); glutReshapeFunc(changeViewport); glewInit(); initMatrices(); // New <======================================== vao=gen_particles(); /*#ifdef USING_INDEX_BUFFER #endif*/ // Make a shader char* vertexShaderSourceCode = readFile("vertexShader1.vsh"); char* fragmentShaderSourceCode = readFile("fragmentShader1.fsh"); GLuint vertShaderID = makeVertexShader(vertexShaderSourceCode); GLuint fragShaderID = makeFragmentShader(fragmentShaderSourceCode); shaderProgramID = makeShaderProgram(vertShaderID, fragShaderID); /*/ / Create the "remember all" glGenVertexArrays(1, &vao); glBindVertexArray(vao); glGenBuffers(1, &vbo); glBindBuffer(GL_ARRAY_BUFFER, vbo); // Create the buffer, but don't load anything yet //glBufferData(GL_ARRAY_BUFFER, 7*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW); glBufferData(GL_ARRAY_BUFFER, 6*NUM_VERTICES*sizeof(GLfloat), NULL, GL_STATIC_DRAW); // Load the vertex points glBufferSubData(GL_ARRAY_BUFFER, 0, 3*NUM_VERTICES*sizeof(GLfloat), vertices); // Load the colors right after that //glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),4*NUM_VERTICES*sizeof(GLfloat), colors); glBufferSubData(GL_ARRAY_BUFFER, 3*NUM_VERTICES*sizeof(GLfloat),3*NUM_VERTICES*sizeof(GLfloat), normals);*/ /*#ifdef USING_INDEX_BUFFER glGenBuffers(1, &indexBufferID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBufferID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, NUM_INDICES*sizeof(GLuint), indices, GL_STATIC_DRAW); #endif*/ // Find the position of the variables in the shader //ositionID = glGetAttribLocation(shaderProgramID, "v_i"); //colorID = glGetAttribLocation(shaderProgramID, "elapsed_system_time"); // ============ New! glUniformLocation is how you pull IDs for uniform variables=============== perspectiveMatrixID = glGetUniformLocation(shaderProgramID, "P"); viewMatrixID = glGetUniformLocation(shaderProgramID, "V"); emitterID=glGetUniformLocation(shaderProgramID, "emitter_pos_wor"); timeID=glGetUniformLocation(shaderProgramID, "elapsed_system_time"); //============================================================================================= /*glVertexAttribPointer(positionID, 3, GL_FLOAT, GL_FALSE, 0, 0); //glVertexAttribPointer(colorID, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices))); glVertexAttribPointer(colorID, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(vertices))); printf ("BUFFER_OFFSET is: %d\n", sizeof(vertices));*/ glUseProgram(shaderProgramID); //glEnableVertexAttribArray(positionID); //glEnableVertexAttribArray(colorID); //glEnable(GL_DEPTH_TEST); //glClearColor( 0.0, 0.0, 0.0, 0.2 ); //current_seconds=Timer(); glutDisplayFunc(render); glutKeyboardFunc( keyboard ); glutMainLoop(); return 0; }
main(int argc, char *argv[]) { GLuint *tex; int texwid, texht, texcomps; GLUquadricObj *quadric; glutInitWindowSize(winWidth, winHeight); glutInit(&argc, argv); if(argc > 1) { char *args = argv[1]; int done = FALSE; while(!done) { switch(*args) { case 's': /* single buffer */ printf("Single Buffered\n"); dblbuf = FALSE; break; case '-': /* do nothing */ break; case 0: done = TRUE; break; } args++; } } if(dblbuf) glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); else glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH); (void)glutCreateWindow("example program"); glutDisplayFunc(redraw_original); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(key); /* draw a perspective scene */ glMatrixMode(GL_PROJECTION); glFrustum(-100., 100., -100., 100., 300., 600.); glMatrixMode(GL_MODELVIEW); /* look at scene from (0, 0, 450) */ gluLookAt(0., 0., 450., 0., 0., 0., 0., 1., 0.); /* turn on features */ glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glMateriali(GL_FRONT, GL_SHININESS, 128); /* cosine power */ /* remove back faces to speed things up */ glCullFace(GL_BACK); glBlendFunc(GL_ONE, GL_ONE); lightchanged[UPDATE_TEX] = GL_TRUE; lightchanged[UPDATE_OGL] = GL_TRUE; /* load pattern for current 2d texture */ tex = read_texture("../data/wood.rgb", &texwid, &texht, &texcomps); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, texwid, texht, GL_RGBA, GL_UNSIGNED_BYTE, tex); free(tex); CHECK_ERROR("end of main"); lighttex = (GLfloat *)malloc(texdim * texdim * sizeof(GL_FLOAT) * 3); /* XXX TODO use display list to avoid retesselating */ glNewList(1, GL_COMPILE); glutSolidSphere((GLdouble)texdim/2., 50, 50); glEndList(); glNewList(2, GL_COMPILE); glutSolidTeapot(70.); glEndList(); quadric = gluNewQuadric(); gluQuadricTexture(quadric, GL_TRUE); glNewList(3, GL_COMPILE); gluSphere(quadric, 70., 20, 20); glEndList(); gluDeleteQuadric(quadric); maxobject = 3; glutMainLoop(); 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[]) { elf_firmware_t f; const char * fname = "atmega168_timer_64led.axf"; //char path[256]; // sprintf(path, "%s/%s", dirname(argv[0]), fname); //printf("Firmware pathname is %s\n", path); elf_read_firmware(fname, &f); printf("firmware %s f=%d mmcu=%s\n", fname, (int)f.frequency, f.mmcu); avr = avr_make_mcu_by_name(f.mmcu); if (!avr) { fprintf(stderr, "%s: AVR '%s' now known\n", argv[0], f.mmcu); exit(1); } avr_init(avr); avr_load_firmware(avr, &f); // // initialize our 'peripherals' // hc595_init(avr, &shifter); button_init(avr, &button[B_START], "button.start"); avr_connect_irq( button[B_START].irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('C'), 0)); button_init(avr, &button[B_STOP], "button.stop"); avr_connect_irq( button[B_STOP].irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 1)); button_init(avr, &button[B_RESET], "button.reset"); avr_connect_irq( button[B_RESET].irq + IRQ_BUTTON_OUT, avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('B'), 0)); // connects the fake 74HC595 array to the pins avr_irq_t * i_mosi = avr_io_getirq(avr, AVR_IOCTL_SPI_GETIRQ(0), SPI_IRQ_OUTPUT), * i_reset = avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('D'), 4), * i_latch = avr_io_getirq(avr, AVR_IOCTL_IOPORT_GETIRQ('D'), 7); avr_connect_irq(i_mosi, shifter.irq + IRQ_HC595_SPI_BYTE_IN); avr_connect_irq(i_reset, shifter.irq + IRQ_HC595_IN_RESET); avr_connect_irq(i_latch, shifter.irq + IRQ_HC595_IN_LATCH); avr_irq_t * i_pwm = avr_io_getirq(avr, AVR_IOCTL_TIMER_GETIRQ('0'), TIMER_IRQ_OUT_PWM0); avr_irq_register_notify( i_pwm, pwm_changed_hook, NULL); avr_irq_register_notify( shifter.irq + IRQ_HC595_OUT, hc595_changed_hook, NULL); // even if not setup at startup, activate gdb if crashing avr->gdb_port = 1234; if (0) { //avr->state = cpu_Stopped; avr_gdb_init(avr); } /* * VCD file initialization * * This will allow you to create a "wave" file and display it in gtkwave * Pressing "r" and "s" during the demo will start and stop recording * the pin changes */ avr_vcd_init(avr, "gtkwave_output.vcd", &vcd_file, 10000 /* usec */); avr_vcd_add_signal(&vcd_file, avr_get_interrupt_irq(avr, 7), 1 /* bit */ , "TIMER2_COMPA" ); avr_vcd_add_signal(&vcd_file, avr_get_interrupt_irq(avr, 17), 1 /* bit */ , "SPI_INT" ); avr_vcd_add_signal(&vcd_file, i_mosi, 8 /* bits */ , "MOSI" ); avr_vcd_add_signal(&vcd_file, i_reset, 1 /* bit */ , "595_RESET" ); avr_vcd_add_signal(&vcd_file, i_latch, 1 /* bit */ , "595_LATCH" ); avr_vcd_add_signal(&vcd_file, button[B_START].irq + IRQ_BUTTON_OUT, 1 /* bits */ , "start" ); avr_vcd_add_signal(&vcd_file, button[B_STOP].irq + IRQ_BUTTON_OUT, 1 /* bits */ , "stop" ); avr_vcd_add_signal(&vcd_file, button[B_RESET].irq + IRQ_BUTTON_OUT, 1 /* bits */ , "reset" ); avr_vcd_add_signal(&vcd_file, shifter.irq + IRQ_HC595_OUT, 32 /* bits */ , "HC595" ); avr_vcd_add_signal(&vcd_file, i_pwm, 8 /* bits */ , "PWM" ); // 'raise' it, it's a "pullup" avr_raise_irq(button[B_START].irq + IRQ_BUTTON_OUT, 1); avr_raise_irq(button[B_STOP].irq + IRQ_BUTTON_OUT, 1); avr_raise_irq(button[B_RESET].irq + IRQ_BUTTON_OUT, 1); printf( "Demo : This is a real world firmware, a 'stopwatch'\n" " timer that can count up to 99 days. It features a PWM control of the\n" " brightness, blinks the dots, displays the number of days spent and so on.\n\n" " Press '0' to press the 'start' button\n" " Press '1' to press the 'stop' button\n" " Press '2' to press the 'reset' button\n" " Press 'q' to quit\n\n" " Press 'r' to start recording a 'wave' file - with a LOT of data\n" " Press 's' to stop recording\n" " + Make sure to watch the brightness dim once you stop the timer\n\n" ); /* * OpenGL init, can be ignored */ glutInit(&argc, argv); /* initialize GLUT system */ int w = 22, h = 8; glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); glutInitWindowSize(w * pixsize, h * pixsize); /* width=400pixels height=500pixels */ window = glutCreateWindow("Press 0, 1, 2 or q"); /* create window */ // Set up projection matrix glMatrixMode(GL_PROJECTION); // Select projection matrix glLoadIdentity(); // Start with an identity matrix glOrtho(0, w * pixsize, 0, h * pixsize, 0, 10); glScalef(1,-1,1); glTranslatef(0, -1 * h * pixsize, 0); glutDisplayFunc(displayCB); /* set window's display callback */ glutKeyboardFunc(keyCB); /* set window's key callback */ glutTimerFunc(1000 / 24, timerCB, 0); // the AVR run on it's own thread. it even allows for debugging! pthread_t run; pthread_create(&run, NULL, avr_run_thread, NULL); glutMainLoop(); }
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; /* **************************************************************************************************************************** */ }
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; }