void GLInit() { glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(0, 0); glutInitWindowSize(1024, 768); glutCreateWindow("Paper Tower Defense"); glutGameModeString("1024x768:32@60"); if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE) == true) { //glutEnterGameMode(); } else { //Exit(); } glutIgnoreKeyRepeat(true); glutKeyboardFunc(HandleNormalKeyDown); glutSpecialFunc(HandleSpecialKeyDown); glutSpecialUpFunc(HandleSpecialKeyUp); glutPassiveMotionFunc(HandlePassiveMouseMotion); glutMotionFunc(HandleMouseMotion); glutMouseFunc(HandleMouseEvent); glutDisplayFunc(ProcessFrame); glutIdleFunc(ProcessFrame); glutReshapeFunc(ResizeWindow); glutSetCursor(GLUT_CURSOR_NONE); glEnable(GL_TEXTURE_2D); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.0f); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); }
Window::Window(uword width, uword height, const char *title,bool fullscreen, word xpos, word ypos) : resized(true) { data = (void *) new WindowData; PRIV(WindowData, wd); wd->width = width; wd->height = height; wd->aspect = (double) width / (double) height; wd->fullscreen = fullscreen; glutInitWindowPosition(xpos, ypos); glutInitWindowSize(width, height); glutCreateWindow(title); if(fullscreen){ glutHideWindow(); glutDestroyWindow(glutGetWindow()); char gameModeString [50]; sprintf (gameModeString, "%dx%d",width,height); glutGameModeString(gameModeString); glutSetWindow(glutEnterGameMode()); } wd->wid = glutGetWindow(); glClearColor(0, 0, 0, 0); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glShadeModel(GL_SMOOTH); glEnable(GL_LIGHTING); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); //Clearing screen to get a black screen while loading.. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glutSwapBuffers(); windows.insert(this); }
void initGL(int argc, char** argv){ // Inicialização do GLUT glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH | GLUT_RGBA); glutGameModeString(OGLWindow_getGameModeString()); if(glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { OGLWindow_initGameMode(); } else // Cria Janela Normal { OGLWindow_initWindowMode(); } // Registar funções de callback glutDisplayFunc(display); glutReshapeFunc(reshape); glutIdleFunc(display); glutIgnoreKeyRepeat(1); glutKeyboardFunc(pressNormalKeys); glutKeyboardUpFunc(releaseNormalKeys); glutSpecialFunc(pressSpecialKey); glutSpecialUpFunc(releaseSpecialKey); glutMotionFunc(mouseMove); glutMouseFunc(mouseClick); // - Directly redirect GLUT mouse button events to AntTweakBar //glutMouseFunc((GLUTmousebuttonfun)TwEventMouseButtonGLUT); // - Directly redirect GLUT mouse "passive" motion events to AntTweakBar (same as MouseMotion) glutPassiveMotionFunc((GLUTmousemotionfun)TwEventMouseMotionGLUT); }
// Main Function For Bringing It All Together. int main(int argc, char** argv) { ask_gamemode(); // Ask For Fullscreen Mode glutInit(&argc, argv); // GLUT Initializtion glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE); // Display Mode (Rgb And Double Buffered) if (g_gamemode) { glutGameModeString("640x480:16"); // Select The 640x480 In 16bpp Mode if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) glutEnterGameMode(); // Enter Full Screen else g_gamemode = false; // Cannot Enter Game Mode, Switch To Windowed } if (!g_gamemode) { glutInitWindowSize(WCX, WCY); // Window Size If We Start In Windowed Mode glutCreateWindow("NeHe's OpenGL Framework"); // Window Title } init(); // Our Initialization glutDisplayFunc(render); // Register The Display Function glutReshapeFunc(reshape); // Register The Reshape Handler glutKeyboardFunc(keyboard); // Register The Keyboard Handler glutSpecialFunc(special_keys); // Register Special Keys Handler glutIdleFunc(render); // Do Rendering In Idle Time glutMainLoop(); // Go To GLUT Main Loop return 0; }
int main(int argc, char **argv) { bool fullscreen = false; glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(screen_x, screen_y); glutInitWindowPosition(50, 50); if (fullscreen) { glutGameModeString("800x600:32"); glutEnterGameMode(); } else { glutCreateWindow("Fractal"); } glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutReshapeFunc(reshape); glutMouseFunc(mouse); glColor3d(0, 0, 0); // Foreground color. glClearColor(1, 1, 1, 0); // Background color. InitializeMyStuff(); glutMainLoop(); return 0; }
// Make a window for doing OpenGL void makeWindow(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); glutInitContextVersion(4, 2); #ifdef DEBUG glutInitContextFlags(GLUT_CORE_PROFILE | GLUT_DEBUG); #else glutInitContextFlags(GLUT_COMPATIBILITY_PROFILE); #endif // Open window / full screen #ifdef FULLSCREEN char modeString[255] = ""; sprintf(modeString, "%dx%d:24", WINDOW_WIDTH, WINDOW_HEIGHT); glutGameModeString(modeString); glutEnterGameMode(); #else glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutCreateWindow(WINDOW_TITLE); #endif // Use GLEW, and make sure it imports EVERYTHING glewExperimental = GL_TRUE; glewInit(); #ifdef DEBUG registerGlDebugLogger(GL_DEBUG_SEVERITY_MEDIUM); #endif // Set up OpenGL features glEnable(GL_DEPTH_TEST); glClearDepth(1.0f); glDepthFunc(GL_LEQUAL); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); }
void specialKeyboard(int key, int x, int y) { float fraction = 0.2f; switch(key) { case GLUT_KEY_DOWN: //Code to move DOWN x -= lx*fraction; z -= lz*fraction; break; case GLUT_KEY_UP: //Code to move UPWN x += lx*fraction; z += lz*fraction; break; case GLUT_KEY_LEFT: //Code to move LEFT angle1 -= 0.1f; lx = sin(angle1); lz = -cos(angle1); break; case GLUT_KEY_RIGHT: //Code to move RIGHT angle1 += 0.1f; lx = sin(angle1); lz = -cos(angle1); break; //case GLUT_KEY_F1: //Code for opening HELP menu //case GLUT_KEY_F2: //Code for GAME refresh case GLUT_KEY_F1: // define resolution, color depth glutGameModeString("640x480:32"); // enter full screen if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { glutEnterGameMode(); sprintf(gameModeString,"640x480:32"); // register callbacks again // and init OpenGL context init(); } else glutGameModeString(gameModeString); break; case GLUT_KEY_F2: // define resolution, color depth glutGameModeString("800x600:32"); // enter full screen if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { glutEnterGameMode(); sprintf(gameModeString,"800x600:32"); // register callbacks again // and init OpenGL context init(); } else glutGameModeString(gameModeString); break; case GLUT_KEY_F3: // define resolution, color depth glutGameModeString("1024x768:32"); // enter full screen if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { glutEnterGameMode(); sprintf(gameModeString,"1024x768:32"); // register callbacks again // and init OpenGL context init(); } else glutGameModeString(gameModeString); break; case GLUT_KEY_F4: // define resolution, color depth glutGameModeString("1280x1024:32"); // enter full screen if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { glutEnterGameMode(); sprintf(gameModeString,"1280x1024:32"); // register callbacks again // and init OpenGL context init(); } else glutGameModeString(gameModeString); break; case GLUT_KEY_F5: // define resolution, color depth glutGameModeString("1920x1200"); // enter full screen if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { glutEnterGameMode(); sprintf(gameModeString,"1920x1200"); // register callbacks again // and init OpenGL context init(); } else glutGameModeString(gameModeString); break; case GLUT_KEY_F6: // return to default window width = 800;height = 600; if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) != 0) { glutLeaveGameMode(); //init(); } break; } if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE) == 0) sprintf(currentMode,"Current Mode: Window"); else sprintf(currentMode, "Current Mode: Game Mode %dx%d at %d hertz, %d bpp", glutGameModeGet(GLUT_GAME_MODE_WIDTH), glutGameModeGet(GLUT_GAME_MODE_HEIGHT), glutGameModeGet(GLUT_GAME_MODE_REFRESH_RATE), glutGameModeGet(GLUT_GAME_MODE_PIXEL_DEPTH)); }
int main(int argc, char **argv) { char glutGamemode[32]; char *cpara = NULL; char cparaDefault[] = "Data/camera_para.dat"; char *vconf = NULL; int patt_names_count = 0; char *patt_names[CHECK_ID_MULTIMARKERS_MAX] = {NULL}; ARdouble pattRatio = (ARdouble)AR_PATT_RATIO; AR_MATRIX_CODE_TYPE matrixCodeType = AR_MATRIX_CODE_TYPE_DEFAULT; int labelingMode = AR_DEFAULT_LABELING_MODE; int patternDetectionMode = AR_DEFAULT_PATTERN_DETECTION_MODE; int i, gotTwoPartOption; float tempF; int tempI; // // Library inits. // glutInit(&argc, argv); // // Startup options. // i = 1; // argv[0] is name of app, so start at 1. while (i < argc) { gotTwoPartOption = FALSE; // Look for two-part options first. if ((i + 1) < argc) { if (strcmp(argv[i], "--vconf") == 0) { i++; vconf = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--cpara") == 0) { i++; cpara = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--pattRatio") == 0) { i++; if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 1.0f) pattRatio = (ARdouble)tempF; else ARLOGe("Error: argument '%s' to --pattRatio invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--pattSize") == 0) { i++; if (sscanf(argv[i], "%d", &tempI) == 1 && tempI >= 16 && tempI <= AR_PATT_SIZE1_MAX) gPattSize = tempI; else ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--pattCountMax") == 0) { i++; if (sscanf(argv[i], "%d", &tempI) == 1 && tempI > 0) gPattCountMax = tempI; else ARLOGe("Error: argument '%s' to --pattSize invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--borderSize") == 0) { i++; if (sscanf(argv[i], "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f) pattRatio = (ARdouble)(1.0f - 2.0f * tempF); else ARLOGe("Error: argument '%s' to --borderSize invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--matrixCodeType") == 0) { i++; if (strcmp(argv[i], "AR_MATRIX_CODE_3x3") == 0) matrixCodeType = AR_MATRIX_CODE_3x3; else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_HAMMING63") == 0) matrixCodeType = AR_MATRIX_CODE_3x3_HAMMING63; else if (strcmp(argv[i], "AR_MATRIX_CODE_3x3_PARITY65") == 0) matrixCodeType = AR_MATRIX_CODE_3x3_PARITY65; else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4") == 0) matrixCodeType = AR_MATRIX_CODE_4x4; else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_9_3") == 0) matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_9_3; else if (strcmp(argv[i], "AR_MATRIX_CODE_4x4_BCH_13_5_5") == 0) matrixCodeType = AR_MATRIX_CODE_4x4_BCH_13_5_5; else if (strcmp(argv[i], "AR_MATRIX_CODE_5x5") == 0) matrixCodeType = AR_MATRIX_CODE_5x5; else if (strcmp(argv[i], "AR_MATRIX_CODE_6x6") == 0) matrixCodeType = AR_MATRIX_CODE_6x6; else if (strcmp(argv[i], "AR_MATRIX_CODE_GLOBAL_ID") == 0) matrixCodeType = AR_MATRIX_CODE_GLOBAL_ID; else ARLOGe("Error: argument '%s' to --matrixCodeType invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--labelingMode") == 0) { i++; if (strcmp(argv[i], "AR_LABELING_BLACK_REGION") == 0) labelingMode = AR_LABELING_BLACK_REGION; else if (strcmp(argv[i], "AR_LABELING_WHITE_REGION") == 0) labelingMode = AR_LABELING_WHITE_REGION; else ARLOGe("Error: argument '%s' to --labelingMode invalid.\n", argv[i]); gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--patternDetectionMode") == 0) { i++; if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR") == 0) patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR; else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO") == 0) patternDetectionMode = AR_TEMPLATE_MATCHING_MONO; else if (strcmp(argv[i], "AR_MATRIX_CODE_DETECTION") == 0) patternDetectionMode = AR_MATRIX_CODE_DETECTION; else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX") == 0) patternDetectionMode = AR_TEMPLATE_MATCHING_COLOR_AND_MATRIX; else if (strcmp(argv[i], "AR_TEMPLATE_MATCHING_MONO_AND_MATRIX") == 0) patternDetectionMode = AR_TEMPLATE_MATCHING_MONO_AND_MATRIX; else ARLOGe("Error: argument '%s' to --patternDetectionMode invalid.\n", argv[i]); gotTwoPartOption = TRUE; } } if (!gotTwoPartOption) { // Look for single-part options. if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) { usage(argv[0]); } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING); exit(0); } else if (strncmp(argv[i], "-border=", 8) == 0) { if (sscanf(&(argv[i][8]), "%f", &tempF) == 1 && tempF > 0.0f && tempF < 0.5f) pattRatio = (ARdouble)(1.0f - 2.0f * tempF); else ARLOGe("Error: argument '%s' to -border= invalid.\n", argv[i]); } else { if (patt_names_count < CHECK_ID_MULTIMARKERS_MAX) { patt_names[patt_names_count] = argv[i]; patt_names_count++; } // } else { // ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]); // usage(argv[0]); } } i++; } // // Video setup. // if (!cpara) cpara = cparaDefault; if (!setupCamera(cpara, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // AR init. // arSetPatternDetectionMode(gARHandle, patternDetectionMode); arSetLabelingMode(gARHandle, labelingMode); arSetPattRatio(gARHandle, pattRatio); arSetMatrixCodeType(gARHandle, matrixCodeType); // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!windowed) { if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh); else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); arUtilTimerReset(); // Load marker(s). if (!setupMarkers(patt_names_count, (const char**)patt_names, gMultiConfigs, gARHandle, &gARPattHandle)) { ARLOGe("main(): Unable to set up AR marker(s).\n"); cleanup(); exit(-1); } gMultiConfigCount = patt_names_count; // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
int main(int argc, char** argv) { int i; char glutGamemode[32]; char cparam_name[] = "Data/camera_para.dat"; char vconf[] = ""; char objectDataFilename[] = "Data/object_data_vrml"; // // Library inits. // glutInit(&argc, argv); // // Video setup. // if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } #ifdef _WIN32 CoInitialize(NULL); #endif // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!windowed) { if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh); else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); arUtilTimerReset(); if (!setupMarkersObjects(objectDataFilename, &gObjectData, &gObjectDataCount, gARHandle)) { ARLOGe("main(): Unable to set up AR objects and markers.\n"); cleanup(); exit(-1); } // Test render all the VRML objects. ARLOGi("Pre-rendering the VRML objects...\n"); glEnable(GL_TEXTURE_2D); for (i = 0; i < gObjectDataCount; i++) { arVrmlDraw(gObjectData[i].vrml_id); } glDisable(GL_TEXTURE_2D); ARLOGi(" done\n"); // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
int main(int argc, char **argv) { int width, height; int i; GLubyte *imageData; glutInit(&argc, argv); for (i=1; i<argc; i++) { if (!strcmp("-lesstex", argv[i])) { /* Only use 16 caustic textures. Saves texture memory and works better on slow machines. */ causticIncrement = 2; } else if (!strcmp("-evenlesstex", argv[i])) { /* Only use 8 caustic textures. Saves even more texture memory for slow machines. Temporal rippling suffers. */ causticIncrement = 4; } else if (!strcmp("-nomipmap", argv[i])) { /* Don't use linear mipmap linear texture filtering; instead use linear filtering. */ useMipmaps = 0; } else if (!strcmp("-fullscreen", argv[i])) { fullscreen = 1; } else { fprintf(stderr, "usage: caustics [-lesstex]\n"); fprintf(stderr, " -lesstex uses half the caustic textures.\n"); fprintf(stderr, " -evenlesstex uses one fourth of the caustic textures.\n"); exit(1); } } glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); if (fullscreen) { glutGameModeString("800x600:16@60"); glutEnterGameMode(); } else { glutCreateWindow("underwater"); } /* Check that renderer has the GL_EXT_texture_object extension or supports OpenGL 1.1 */ #ifdef TEXTURE_OBJECT { char *version = (char *) glGetString(GL_VERSION); if (glutExtensionSupported("GL_EXT_texture_object") || strncmp(version, "1.1", 3) == 0) { HaveTexObj = GL_TRUE; } } #endif glEnable(GL_TEXTURE_2D); #ifdef TEXTURE_OBJECT /* Replace texture environment not in OpenGL 1.0. */ if (HaveTexObj) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); #endif /* Load the caustic ripple textures. */ printf("loading caustics:"); for (i=0; i<NUM_PATTERNS; i += causticIncrement) { char filename[80]; sprintf(filename, "caust%02d.bw", i); printf(" %d", i); fflush(stdout); imageData = read_alpha_texture(filename, &width, &height); if (imageData == NULL) { fprintf(stderr, "\n%s: could not load image file\n", filename); exit(1); } if (HaveTexObj) glBindTexture(GL_TEXTURE_2D, i+1); else glNewList(i+101, GL_COMPILE); if (useMipmaps) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, width, height, GL_LUMINANCE, GL_UNSIGNED_BYTE, imageData); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, height, width, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, imageData); } free(imageData); if (!HaveTexObj) glEndList(); } printf(".\n"); /* Load an RGB file for the floor texture. */ printf("loading RGB textures: floor"); fflush(stdout); imageData = read_rgb_texture(FLOOR_FILE, &width, &height); if (imageData == NULL) { fprintf(stderr, "%s: could not load image file\n", FLOOR_FILE); exit(1); } printf(".\n"); if (HaveTexObj) glBindTexture(GL_TEXTURE_2D, 100); else glNewList(100, GL_COMPILE); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); if (useMipmaps) { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, imageData); } else { glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); } free(imageData); if (!HaveTexObj) glEndList(); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 8.0, 60.0, /* eye is at (0,8,60) */ 0.0, 8.0, 0.0, /* center is at (0,8,0) */ 0.0, 1.0, 0.); /* up is in postivie Y direction */ /* Setup initial OpenGL rendering state. */ glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuseColor); glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); /* Register assorted GLUT callback routines. */ glutDisplayFunc(display); glutReshapeFunc(reshape); glutVisibilityFunc(visible); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(keyboard); /* Create a pop-up menu. */ if (!fullscreen) { glutCreateMenu(menuSelect); glutAddMenuEntry("Positional light", M_POSITIONAL); glutAddMenuEntry("Directional light", M_DIRECTIONAL); glutAddMenuEntry("Greenish light", M_GREENISH_LIGHT); glutAddMenuEntry("White light", M_WHITE_LIGHT); glutAddMenuEntry("With caustics", M_WITH_CAUSTICS); glutAddMenuEntry("No caustics", M_NO_CAUSTICS); glutAddMenuEntry("Switch model", M_SWITCH_MODEL); glutAddMenuEntry("Increase ripple size", M_INCREASE_RIPPLE_SIZE); glutAddMenuEntry("Decrease ripple size", M_DECREASE_RIPPLE_SIZE); glutAttachMenu(GLUT_RIGHT_BUTTON); } /* For rendering the MODEL_DINO object. */ dinoDisplayList = makeDinosaur(); /* Enter GLUT's main loop; callback dispatching begins. */ glutMainLoop(); return 0; /* ANSI C requires main to return int. */ }
int main(int argc, char** argv) { char glutGamemode[32]; const char *cparam_name = "Data2/camera_para.dat"; char vconf[] = ""; const char markerConfigDataFilename[] = "Data2/markers.dat"; #ifdef DEBUG arLogLevel = AR_LOG_LEVEL_DEBUG; #endif // // Library inits. // glutInit(&argc, argv); // // Video setup. // #ifdef _WIN32 CoInitialize(NULL); #endif if (!setupCamera(cparam_name, vconf, &gCparamLT)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // AR init. // // Create the OpenGL projection from the calibrated camera parameters. arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens); if (!initNFT(gCparamLT, arVideoGetPixelFormat())) { ARLOGe("main(): Unable to init NFT.\n"); exit(-1); } // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arUtilTimerReset(); // // Markers setup. // // Load marker(s). newMarkers(markerConfigDataFilename, &markersNFT, &markersNFTCount); if (!markersNFTCount) { ARLOGe("Error loading markers from config. file '%s'.\n", markerConfigDataFilename); cleanup(); exit(-1); } ARLOGi("Marker count = %d\n", markersNFTCount); // Marker data has been loaded, so now load NFT data. if (!loadNFTData()) { ARLOGe("Error loading NFT data.\n"); cleanup(); exit(-1); } // Start the video. if (arVideoCapStart() != 0) { ARLOGe("setupCamera(): Unable to begin camera data capture.\n"); return (FALSE); } // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
int main(int argc, char** argv) { char glutGamemode[32]; char cparam_name[] = "Data/camera_para.dat"; char vconf[] = ""; char patt_name[] = "Data/patt.hiro"; char movieFileName[] = "Data/sample.mov"; char *movieURI; // // Library inits. // glutInit(&argc, argv); // // Video setup. // if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!windowed) { if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh); else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); arUtilTimerReset(); // Load marker(s). if (!setupMarker(patt_name, &gPatt_id, gARHandle, &gARPattHandle)) { ARLOGe("main(): Unable to set up AR marker.\n"); cleanup(); exit(-1); } // // Movie loading. // // In this example, we load a movie via a file URI, but other URIs allowed // by the QuickTime module would also be fine. // Movie relative path is in "movieFileName". Get a file:// URI for it. movieURI = arUtilGetFileURI(movieFileName); if (!movieURI) { ARLOGe("Error: Unable to construct URI for movie file '%s'.\n", movieFileName); cleanup(); exit(-1); } // Now open the movie. if (!setupMovie(movieURI)) { ARLOGe("Error: Unable to open movie at URI '%s'.\n", movieURI); free(movieURI); cleanup(); exit(-1); } free(movieURI); // We're finished with movieURI, so free it. // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
ScreenGL::ScreenGL( int inWide, int inHigh, char inFullScreen, unsigned int inMaxFrameRate, char inRecordEvents, const char *inWindowName, KeyboardHandlerGL *inKeyHandler, MouseHandlerGL *inMouseHandler, SceneHandlerGL *inSceneHandler ) : mWide( inWide ), mHigh( inHigh ), mImageSizeSet( false ), mImageWide( inWide ), mImageHigh( inHigh ), mFullScreen( inFullScreen ), m2DMode( false ), mViewPosition( new Vector3D( 0, 0, 0 ) ), mViewOrientation( new Angle3D( 0, 0, 0 ) ), mMouseHandlerVector( new SimpleVector<MouseHandlerGL*>() ), mKeyboardHandlerVector( new SimpleVector<KeyboardHandlerGL*>() ), mSceneHandlerVector( new SimpleVector<SceneHandlerGL*>() ), mRedrawListenerVector( new SimpleVector<RedrawListenerGL*>() ) { // add handlers if NULL (the default) was not passed in for them if( inMouseHandler != NULL ) { addMouseHandler( inMouseHandler ); } if( inKeyHandler != NULL ) { addKeyboardHandler( inKeyHandler ); } if( inSceneHandler != NULL ) { addSceneHandler( inSceneHandler ); } if( mFullScreen ) { glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); //| GLUT_FULLSCREEN ); } else { glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); } if( !mFullScreen ) { glutInitWindowSize( mWide, mHigh ); glutCreateWindow( inWindowName ); } else { // use game mode for full screen char *gameMode = autoSprintf( "%dx%d:32", mWide, mHigh ); glutGameModeString( gameMode ); if( glutGameModeGet( GLUT_GAME_MODE_POSSIBLE ) ) { glutEnterGameMode(); delete [] gameMode; } else { printf( "The full-screen mode %s is not available\n", gameMode ); delete [] gameMode; exit(1); } } glutIgnoreKeyRepeat( 1 ); glutKeyboardFunc( callbackKeyboard ); glutKeyboardUpFunc( callbackKeyboardUp ); glutSpecialFunc( callbackSpecialKeyboard ); glutSpecialUpFunc( callbackSpecialKeyboardUp ); glutReshapeFunc( callbackResize ); glutMotionFunc( callbackMotion ); glutMouseFunc( callbackMouse ); glutPassiveMotionFunc( callbackPassiveMotion ); glutDisplayFunc( callbackDisplay ); glutIdleFunc( callbackIdle ); glEnable( GL_DEPTH_TEST ); glEnable( GL_CULL_FACE ); glEnable( GL_BLEND ); glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); glCullFace( GL_BACK ); glFrontFace( GL_CCW ); }
int main(int argc, char** argv) { char glutGamemode[32]; char *cparam_name = "Data/camera_para.dat"; char *vconf = ""; char *patt_name = "Data/patt.hiro"; // ---------------------------------------------------------------------------- // Library inits. // glutInit(&argc, argv); // ---------------------------------------------------------------------------- // Hardware setup. // if (!setupCamera(cparam_name, vconf, &gARTCparam)) { fprintf(stderr, "main(): Unable to set up AR camera.\n"); exit(-1); } // ---------------------------------------------------------------------------- // Library setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); } // // Setup ARgsub_lite library for current OpenGL context. // if ((gArglSettings = arglSetupForCurrentContext()) == NULL) { // fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n"); // cleanup(); // exit(-1); // } // debugReportMode(gArglSettings); glEnable(GL_DEPTH_TEST); arUtilTimerReset(); // Load marker(s). if (!setupMarker(patt_name, &gPatt_id)) { fprintf(stderr, "main(): Unable to set up AR marker.\n"); cleanup(); exit(-1); } // // Register GLUT event-handling callbacks. // // NB: mainLoop() is registered by Visibility. // glutDisplayFunc(Display); // glutReshapeFunc(Reshape); // glutVisibilityFunc(Visibility); // glutKeyboardFunc(Keyboard); // glutMainLoop(); return (0); }
Scene::Scene(int width, int height, string title, bool fullscreen) { int dummyArgc = 1; this->fullscreen = fullscreen; graph = new Children; fishList = new Children; sharkList = new Children; // Start calls glutInit(&dummyArgc, NULL); glutInitDisplayMode (GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); if (fullscreen) { ostringstream mode; mode << width << "x" << height << ":16@60"; glutGameModeString(mode.str().c_str()); glutEnterGameMode(); } else { glutInitWindowSize(width, height); glutInitWindowPosition(100,0); glutCreateWindow(title.c_str()); } fpsDisplay = new Text(3, 3, "FPS:", 1.3); string helpText[] = { "Keys:", "H - Toggle help", "Space - Next camera", "Escape - Quit", "P - Pause", "X - Write TGAs", "+ - Increase light of glowing fish", "- - Decrease light of glowing fish", "F - Calculate maximum number of fish", "N - Toggle names", "O - Move camera up", "L - Move camera down", "T - Toggle lamp", "1 - Add fish", "2 - Remove fish", "3 - Add shark", "4 - Remove shark" }; for (int i = 0; i < 17; i++) { helpDisplay.push_front(new Text(50, 360 - (18 * i), helpText[i], 1.1)); helpDisplay.front()->setEnabled(drawHelp); } // Register callbacks glutDisplayFunc(display); glutMouseFunc(mouseHandler); glutKeyboardFunc(keyboardDownHandler); glutKeyboardUpFunc(keyboardUpHandler); glutReshapeFunc(reshapeHandler); glutIdleFunc(NULL); // Visibility settings etc. glClearColor(0.4, 0.4, 0.4, 1.0); glClearDepth(1.0); glDepthFunc(GL_LESS); // Kind of depth test glEnable(GL_DEPTH_TEST); glEnable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_LIGHTING); glShadeModel(GL_SMOOTH); // Light 0: Moving fish light GLfloat lightDiffuse[]= {1.0f, 1.0f, 1.0f}; GLfloat light0Pos[] = {0.0f, 0.0f, 0.0f}; glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, lightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, light0Pos); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.9f); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f); //glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, attenuation); glEnable(GL_LIGHT0); // Light 2: Spot light GLfloat lightAmbient[]= {0.5f, 0.5f, 0.5f}; GLfloat lightPos[] = {0.0f, 250.0f, 0.0f, 1.0f}; GLfloat spotDir[] = {0.0f, -100.0f, 0.0f}; //GLfloat cutoff = 90.0f; glLightfv(GL_LIGHT1, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT1, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT1, GL_POSITION, lightPos); glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, spotDir); //glLightfv(GL_LIGHT1, GL_SPOT_CUTOFF, &cutoff); glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 50); glLightf(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 1); if (topLight) { glEnable(GL_LIGHT1); } glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0f, (GLfloat)width / (GLfloat)height, 0.1f, 10000.0f); glMatrixMode(GL_MODELVIEW); glLineWidth(2.5f); // Count FPS frames = 0; glutTimerFunc(1000, fpsTimer, 1); // Animation timer glutTimerFunc(40, timer, 1); }
int main(int argc, char** argv) { char glutGamemode[32]; const char *cparam_name = "Data/camera_para.dat"; // // Camera configuration. // char *vconf = "v4l2src device=/dev/video0 ! ffmpegcolorspace ! capsfilter caps=video/x-raw-rgb,bpp=24,width=320,height=240 ! identity name=artoolkit ! fakesink"; const char *patt_name = "Data/patt.kanji"; // ---------------------------------------------------------------------------- // Library inits. // glutInit(&argc, argv); // ---------------------------------------------------------------------------- // Hardware setup. // if (!setupCamera(cparam_name, vconf, &gARTCparam)) { fprintf(stderr, "main(): Unable to set up AR camera.\n"); exit(-1); } //Read in ply file parse(); // ---------------------------------------------------------------------------- // Library setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); } // Setup argl library for current context. if ((gArglSettings = arglSetupForCurrentContext()) == NULL) { fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n"); exit(-1); } debugReportMode(gArglSettings); glEnable(GL_DEPTH_TEST); arUtilTimerReset(); if (!setupMarker(patt_name, &gPatt_id)) { fprintf(stderr, "main(): Unable to set up AR marker.\n"); Quit(); } // Register GLUT event-handling callbacks. // NB: Idle() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
/* * Class: gruenewa_opengl_GLUT__ * Method: glutGameModeString * Signature: (Ljava/lang/String;)V */ JNIEXPORT void JNICALL Java_gruenewa_opengl_GLUT_00024_glutGameModeString (JNIEnv * jenv, jobject jobj, jobject arg1) { glutGameModeString((*jenv)->GetDirectBufferAddress(jenv, arg1)); }
int main(int argc, char** argv) { char glutGamemode[32]; const char *cparam_name = "Data/camera_para.dat"; // // Camera configuration. // #ifdef _WIN32 char *vconf = "Data\\WDM_camera_flipVH.xml"; #else char *vconf = ""; #endif const char *patt_name = "Data/custom/kaki.pat"; // ---------------------------------------------------------------------------- // Library inits. // glutInit(&argc, argv); // ---------------------------------------------------------------------------- // Hardware setup. // if (!setupCamera(cparam_name, vconf, &gARTCparam)) { fprintf(stderr, "main(): Unable to set up AR camera.\n"); exit(-1); } /* if (!setupMarker(patt_name, &gPatt_id)) { fprintf(stderr, "main(): Unable to set up AR marker.\n"); exit(-1); } */ // ---------------------------------------------------------------------------- // Library setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) { sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); } else { sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); } glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); } // Setup argl library for current context. if ((gArglSettings = arglSetupForCurrentContext()) == NULL) { fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n"); exit(-1); } debugReportMode(); glEnable(GL_DEPTH_TEST); arUtilTimerReset(); // ---------------------------------------------------------------------------- // Program Init // Init(); // Register GLUT event-handling callbacks. // NB: Idle() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
void Tutorial::initGlut() { switch (_tutorialID) { case 1: case 2: case 3: _pGameCamera = nullptr; case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13: case 14: setWindowSize(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14); _pGameCamera = new Camera(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14); break; case 15: setWindowSize(WINDOW_WIDTH_15_17, WINDOW_HEIGHT_15_17); _pGameCamera = new Camera(WINDOW_WIDTH_15_17, WINDOW_HEIGHT_15_17); break; case 16: setWindowSize(WINDOW_WIDTH_16, WINDOW_HEIGHT_16); _pGameCamera = new Camera(WINDOW_WIDTH_16, WINDOW_HEIGHT_16); break; case 17: case 18: case 19: case 20: case 21: case 22: case 23: return; default: setWindowSize(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14); _pGameCamera = new Camera(WINDOW_WIDTH_1_14, WINDOW_HEIGHT_1_14); break; } setWindowLocation(); createWindow(_tutorialID); glutDisplayFunc(renderFunction); glutIdleFunc(idleFunction); glutSpecialFunc(specialKeyboardCB); glutKeyboardFunc(keyboardCB); glutPassiveMotionFunc(passiveMouseCB); if (_tutorialID == 15 || _tutorialID == 17) { glutGameModeString("1920x1080@24"); glutEnterGameMode(); } else if (_tutorialID == 16) { glutGameModeString("1280x1024@24"); } }
int main(int argc, char** argv) { char glutGamemode[32] = ""; char *vconf = NULL; char cparaDefault[] = "Data2/camera_para.dat"; char *cpara = NULL; int i; int gotTwoPartOption; const char markerConfigDataFilename[] = "Data2/markers.dat"; const char objectDataFilename[] = "Data2/objects.dat"; #ifdef DEBUG arLogLevel = AR_LOG_LEVEL_DEBUG; #endif // // Process command-line options. // glutInit(&argc, argv); i = 1; // argv[0] is name of app, so start at 1. while (i < argc) { gotTwoPartOption = FALSE; // Look for two-part options first. if ((i + 1) < argc) { if (strcmp(argv[i], "--vconf") == 0) { i++; vconf = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--cpara") == 0) { i++; cpara = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--width") == 0) { i++; // Get width from second field. if (sscanf(argv[i], "%d", &prefWidth) != 1) { ARLOGe("Error: --width option must be followed by desired width.\n"); } gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--height") == 0) { i++; // Get height from second field. if (sscanf(argv[i], "%d", &prefHeight) != 1) { ARLOGe("Error: --height option must be followed by desired height.\n"); } gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--refresh") == 0) { i++; // Get refresh rate from second field. if (sscanf(argv[i], "%d", &prefRefresh) != 1) { ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n"); } gotTwoPartOption = TRUE; } } if (!gotTwoPartOption) { // Look for single-part options. if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) { usage(argv[0]); } else if (strncmp(argv[i], "-cpara=", 7) == 0) { cpara = &(argv[i][7]); } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING); exit(0); } else if (strcmp(argv[i],"--windowed") == 0) { prefWindowed = TRUE; } else if (strcmp(argv[i],"--fullscreen") == 0) { prefWindowed = FALSE; } else { ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]); usage(argv[0]); } } i++; } // // Video setup. // if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // AR init. // if (!initNFT(gCparamLT, arVideoGetPixelFormat())) { ARLOGe("main(): Unable to init NFT.\n"); exit(-1); } // // Markers setup. // // Load marker(s). newMarkers(markerConfigDataFilename, &markersNFT, &markersNFTCount); if (!markersNFTCount) { ARLOGe("Error loading markers from config. file '%s'.\n", markerConfigDataFilename); cleanup(); exit(-1); } ARLOGi("Marker count = %d\n", markersNFTCount); // Marker data has been loaded, so now load NFT data. if (!loadNFTData()) { ARLOGe("Error loading NFT data.\n"); cleanup(); exit(-1); } // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (prefWindowed) { if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight); else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize); glutCreateWindow(argv[0]); } else { if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { if (prefWidth && prefHeight) { if (prefDepth) { if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth); } else { if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh); else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight); } } else { prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH); prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT); snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight); } glutGameModeString(glutGamemode); glutEnterGameMode(); } else { if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); glutFullScreen(); } } // Create the OpenGL projection from the calibrated camera parameters. arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens); cameraPoseValid = FALSE; // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } // Load objects (i.e. OSG models). VirtualEnvironmentInit(objectDataFilename); VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens); // // Setup complete. Start tracking. // // Start the video. if (arVideoCapStart() != 0) { ARLOGe("setupCamera(): Unable to begin camera data capture.\n"); return (FALSE); } arUtilTimerReset(); // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
int main(int argc, char **argv) { bool gameMode = false; int startX = 100, startY = 100; VECTOR4D Target = { 0.0f, 0.0f, 0.0f, 1.0f }; VECTOR4D Eye = { 3.0f, 3.0f, 3.0f, 1.0f }; VECTOR4D Up = { 0.0f, 0.0f, 1.0f, 0.0f }; VECTOR4D r = { 1, 0, 0, 1 }; VECTOR4D g = { 0, 1, 0, 1 }; VECTOR4D b = { 0, 0, 1, 1 }; VECTOR4D w = { 1, 1, 1, 1 }; VECTOR4D y = { 1, 1, 0, 1 }; // Init GLUT and create Window glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); if (argc > 1) { if (std::string(argv[1]) == "-game") { glutGameModeString("1024x768:32"); if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { gameMode = true; glutEnterGameMode(); } } if (std::string(argv[1]) == "-center") { startX = glutGet(GLUT_SCREEN_WIDTH) / 2 - WINDOW_WIDTH / 2; startY = glutGet(GLUT_SCREEN_HEIGHT) / 2 - WINDOW_HEIGHT / 2; } } if (!gameMode) { glutInitWindowPosition(startX, startY); glutInitWindowSize(WINDOW_WIDTH, WINDOW_HEIGHT); glutCreateWindow("MSC GC 705080 - Demo 4 (Analytic and Parametric Surfaces)"); } // Initialize viewport and rotation matrix Vi = View(Eye, Target, Up); R = Identity(); // Create surfaces g_EggCarton.BuildAnalyticSurface(30, 30, -1, -1, 2.0f / (30 - 1), 2.0f / (30 - 1), SinCos); g_EggCarton.SetColor(r, g, b, w); g_Plate.BuildAnalyticSurface(40, 40, -1, -1, 2.0f / (40 - 1), 2.0f / (40 - 1), x2y2); g_Plate.SetColor(r, g, b, w); g_Sphere.BuildParametricSurface(30, 30, -1, -1, 1.0f / (30 - 1), 1.0f / (30 - 1), Sphere); g_Sphere.SetColor(r, b, b, r); g_Flower.BuildParametricSurface(100, 30, -1, -1, 1.0f / (10 - 1), 1.0f / (10 - 1), Dini); g_Flower.SetColor(b, w, w, b); g_Bananas.BuildParametricSurface(30, 30, -1, -1, 1.0f / (30 - 1), 1.0f / (30 - 1), Bananas); g_Bananas.SetColor(y, w, w, y); // Register callbacks glutDisplayFunc(renderScene); glutKeyboardFunc(keyHandler); glutKeyboardUpFunc(keyUpHandler); glutTimerFunc(REFRESH_MILISECS, animateScene, 0); // Enter GLUT event processing cycle glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glutMainLoop(); return 0; }
// ------------------------------------------------------------------ // Name : initGlutWindow // ------------------------------------------------------------------ void DisplayEngine::initGlutWindow() { extern bool g_bIgnoreNextResize; g_bIgnoreNextResize = true; if (m_iWindow == -2) // was fullscreen glutLeaveGameMode(); else if (m_iWindow >= 0) // was windowed { m_pClientParams->winXPos = glutGet(GLUT_WINDOW_X); m_pClientParams->winYPos = glutGet(GLUT_WINDOW_Y); glutDestroyWindow(m_iWindow); } extern int g_iOldW; extern int g_iOldH; g_iOldW = m_pClientParams->screenXSize; g_iOldH = m_pClientParams->screenYSize; if (m_pClientParams->fullscreen) { glutGameModeString(m_pClientParams->sGameModeString); glutEnterGameMode(); m_pClientParams->screenXSize = glutGameModeGet(GLUT_GAME_MODE_WIDTH); m_pClientParams->screenYSize = glutGameModeGet(GLUT_GAME_MODE_HEIGHT); m_iWindow = -2; } else { glutInitWindowPosition(m_pClientParams->winXPos, m_pClientParams->winYPos); m_pClientParams->screenXSize = m_pClientParams->winWidth; m_pClientParams->screenYSize = m_pClientParams->winHeight; glutInitWindowSize(m_pClientParams->screenXSize, m_pClientParams->screenYSize); m_iWindow = glutCreateWindow("Shahnarman"); } resizeWindow(); glShadeModel(GL_SMOOTH); glDisable(GL_BLEND); glAlphaFunc(GL_GREATER, 0.0001f); glEnable(GL_ALPHA_TEST); glDepthFunc(GL_LEQUAL); glEnable(GL_DEPTH_TEST); glClearColor(0.1f, 0.05f, 0.1f, 0.0f); glClearDepth(1.0f); glClearStencil(0); GLenum err = glewInit(); if (err != GLEW_OK) { char sLog[1024] = ""; snprintf(sLog, 1024, "Error in glewInit: %s.\n", glewGetErrorString(err)); m_pDebug->notifyErrorMessage(sLog); } if (!glewIsSupported("GL_ARB_shading_language_100")) m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_shading_language_100 not supported."); if (!glewIsSupported("GL_ARB_shader_objects")) m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_shader_objects not supported."); if (!glewIsSupported("GL_ARB_vertex_shader")) m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_vertex_shader not supported."); if (!glewIsSupported("GL_ARB_fragment_shader")) m_pDebug->notifyErrorMessage("Warning: extension GL_ARB_fragment_shader not supported."); Geometry * pGeometry = (Geometry*) m_pRegisteredGeometries->getFirst(0); while (pGeometry != NULL) { pGeometry->reload(); pGeometry = (Geometry*) m_pRegisteredGeometries->getNext(0); } if (m_pTexEngine != NULL) m_pTexEngine->reloadAllTextures(); }
int main(int argc, char** argv) { char glutGamemode[32]; const char *cparam_name = "Data/camera_para.dat"; char vconf[] = ""; const char *patt_name = "Data/cubeMarkerConfig.dat"; // // Library inits. // glutInit(&argc, argv); // // Video setup. // if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); debugReportMode(gARHandle); glEnable(GL_DEPTH_TEST); arUtilTimerReset(); // Load marker(s). if (!setupCubeMarker(patt_name, &gMultiConfig, gARHandle, &gARPattHandle)) { ARLOGe("main(): Unable to set up AR marker.\n"); cleanup(); exit(-1); } // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
int main(int argc, char** argv) { // // load: // intrinsice camera parameters, video configuration, pattern configuration and model file // char glutGamemode[32]; char cparam_name[] = "Data/camera_para.dat"; char vconf[] = ""; char patt_name[] = "Data/patt.irc"; char obj_name[] = "Data/bunny.obj"; gObj = glmReadOBJ(obj_name); if (gObj == NULL) { ARLOGe("main(): Unable to load obj model file.\n"); exit(-1); } glmUnitize(gObj); glmScale(gObj, 1.5*markerSize); // // Library inits. // glutInit(&argc, argv); // // Video setup. // if (!setupCamera(cparam_name, vconf, &gCparamLT, &gARHandle, &gAR3DHandle)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // Load marker(s). if (!setupMarker(patt_name, &gPatt_id, gARHandle, &gARPattHandle)) { ARLOGe("main(): Unable to set up AR marker.\n"); cleanup(); exit(-1); } // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!windowed) { if (windowRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", windowWidth, windowHeight, windowDepth, windowRefresh); else sprintf(glutGamemode, "%ix%i:%i", windowWidth, windowHeight, windowDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(windowWidth, windowHeight); glutCreateWindow(argv[0]); } // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); arUtilTimerReset(); // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutVisibilityFunc(Visibility); glutReshapeFunc(Reshape); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
/* * The sample's entry point */ int main( int argc, char** argv ) { int menuID, subMenuA, subMenuB; glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" ); glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); glutInitWindowPosition( 100, 100 ); glutInit( &argc, argv ); glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); glutMenuStatusFunc( SampleMenuStatus ); glutIdleFunc( SampleIdle ); subMenuA = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Sub menu A1 (01)", 1 ); glutAddMenuEntry( "Sub menu A2 (02)", 2 ); glutAddMenuEntry( "Sub menu A3 (03)", 3 ); subMenuB = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Sub menu B1 (04)", 4 ); glutAddMenuEntry( "Sub menu B2 (05)", 5 ); glutAddMenuEntry( "Sub menu B3 (06)", 6 ); glutAddSubMenu( "Going to sub menu A", subMenuA ); menuID = glutCreateMenu( SampleMenu ); glutAddMenuEntry( "Entry one", 1 ); glutAddMenuEntry( "Entry two", 2 ); glutAddMenuEntry( "Entry three", 3 ); glutAddMenuEntry( "Entry four", 4 ); glutAddMenuEntry( "Entry five", 5 ); glutAddSubMenu( "Enter sub menu A", subMenuA ); glutAddSubMenu( "Enter sub menu B", subMenuB ); g_mainwin1 = glutCreateWindow( "Hello world!" ); glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); glutEntryFunc( SampleEntry ); glutAttachMenu( GLUT_LEFT_BUTTON ); glutInitWindowPosition( 200, 200 ); g_mainwin2 = glutCreateWindow( "I am not Jan B." ); glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleKeyboard ); glutSpecialFunc( SampleSpecial ); glutEntryFunc( SampleEntry ); glutAttachMenu( GLUT_LEFT_BUTTON ); glutSetMenu(subMenuA); glutAttachMenu( GLUT_RIGHT_BUTTON ); g_sw1=glutCreateSubWindow(g_mainwin2,200,0,100,100); glutDisplayFunc( SampleDisplay ); glutSetMenu(subMenuB); glutAttachMenu( GLUT_LEFT_BUTTON ); g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50); glutDisplayFunc( SampleDisplay ); glutSetMenu(menuID); glutAttachMenu( GLUT_RIGHT_BUTTON ); printf( "Testing game mode string parsing, don't panic!\n" ); glutGameModeString( "320x240:32@100" ); glutGameModeString( "640x480:16@72" ); glutGameModeString( "1024x768" ); glutGameModeString( ":32@120" ); glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" ); glutGameModeString( "640x480:37@300" ); /* this one should fail */ glutEnterGameMode(); glutGameModeString( "800x600" ); /* this one is likely to succeed */ g_gamemodewin = glutEnterGameMode(); if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE)) g_InGameMode = 1; glutDisplayFunc( SampleDisplay ); glutReshapeFunc( SampleReshape ); glutKeyboardFunc( SampleGameModeKeyboard ); glutEntryFunc( SampleEntry ); glutSetMenu(menuID); glutAttachMenu( GLUT_LEFT_BUTTON ); printf( "current window is %ix%i at (%i,%i)\n", glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ), glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y ) ); /* * Describe pixel format */ printf("The current window has %i red bits, %i green bits, %i blue bits and %i alpha bits for a total buffer size of %i bits\n",glutGet(GLUT_WINDOW_RED_SIZE),glutGet(GLUT_WINDOW_GREEN_SIZE),glutGet(GLUT_WINDOW_BLUE_SIZE),glutGet(GLUT_WINDOW_ALPHA_SIZE),glutGet(GLUT_WINDOW_BUFFER_SIZE)); printf("It furthermore has %i depth bits and %i stencil bits\n",glutGet(GLUT_WINDOW_DEPTH_SIZE),glutGet(GLUT_WINDOW_STENCIL_SIZE)); /* * Enter the main FreeGLUT processing loop */ glutMainLoop(); /* * returned from mainloop after window closed * see glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS); above */ printf( "glutMainLoop() termination works fine!\n" ); return EXIT_SUCCESS; }
int main(int argc, char **argv) { int i; if (argc > 1) { /* make sure at least 2 args, program and file */ strncpy(filename, argv[argc - 1], sizeof(filename)); /* get the last arg as the file always */ for (i = 0; i < argc; i++) { /* check for startup params */ if (strstr(argv[i], "-s")) stereo = 1; } } else { /* user only entered program name, help them */ printf("Usage: %s [-s] <obj filename>\n", argv[0]); exit(0); } glutInit(&argc, argv); if (stereo) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_STEREO); else glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); if (game_mode) { glutGameModeString("1024x768:32@75"); /* Select The 640x480 In 16bpp Mode */ if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) glutEnterGameMode(); /* Enter Full Screen */ else game_mode = 0; /* Cannot Enter Game Mode, Switch To Windowed */ } if (!game_mode) { glutInitWindowSize(1024, 768); /* Window Size If We Start In Windowed Mode */ glutCreateWindow("Wavefront Obj File Viewer"); } glutDisplayFunc(Display); glutKeyboardFunc(Keyboard); getMatrix(); glClearColor(0.0, 0.0, 0.0, 0.0); glClearAccum(0.0, 0.0, 0.0, 0.0); glutReshapeFunc(Reshape); glutMouseFunc(Mouse); glutMotionFunc(Motion); glutSpecialFunc(SpecialKeys); /* Register Special Keys Handler */ glutSpecialUpFunc(SpecialKeysUp); /* Called When A Special Key Released */ glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glEnable(GL_NORMALIZE); glEnable(GL_TEXTURE_2D); #ifdef SMOOTH_HINT if (smooth_hint) { glEnable(GL_LINE_SMOOTH); /* glEnable (GL_POLYGON_SMOOTH); */ glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); /* glHint (GL_POLYGON_SMOOTH_HINT, GL_NICEST); */ } #endif /* */ if (!pmodel) { /* load up the model */ pmodel = glmReadOBJ(filename); if (!pmodel) { printf("\nUsage: objviewV2 <-s> <obj filename>\n"); exit(0); } glmUnitize(pmodel); glmVertexNormals(pmodel, 90.0, GL_TRUE); } glutMainLoop(); exit(0); }
int main(int argc, char** argv) { int i; char glutGamemode[32]; const char *cparam_name = "Data/camera_para.dat"; #ifdef _WIN32 char *vconf = "Data\\WDM_camera_flipV.xml"; #else char *vconf = ""; #endif char objectDataFilename[] = "Data/object_data_vrml"; // ---------------------------------------------------------------------------- // Library inits. // glutInit(&argc, argv); // ---------------------------------------------------------------------------- // Hardware setup. // if (!setupCamera(cparam_name, vconf, &gARTCparam)) { fprintf(stderr, "main(): Unable to set up AR camera.\n"); exit(-1); } #ifdef _WIN32 CoInitialize(NULL); #endif // ---------------------------------------------------------------------------- // Library setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (!prefWindowed) { if (prefRefresh) sprintf(glutGamemode, "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else sprintf(glutGamemode, "%ix%i:%i", prefWidth, prefHeight, prefDepth); glutGameModeString(glutGamemode); glutEnterGameMode(); } else { glutInitWindowSize(gARTCparam.xsize, gARTCparam.ysize); glutCreateWindow(argv[0]); } // Setup argl library for current context. if ((gArglSettings = arglSetupForCurrentContext()) == NULL) { fprintf(stderr, "main(): arglSetupForCurrentContext() returned error.\n"); exit(-1); } debugReportMode(); arUtilTimerReset(); if (!setupMarkersObjects(objectDataFilename)) { fprintf(stderr, "main(): Unable to set up AR objects and markers.\n"); Quit(); } // Test render all the VRML objects. fprintf(stdout, "Pre-rendering the VRML objects..."); fflush(stdout); glEnable(GL_TEXTURE_2D); for (i = 0; i < gObjectDataCount; i++) { arVrmlDraw(gObjectData[i].vrml_id); } glDisable(GL_TEXTURE_2D); fprintf(stdout, " done\n"); // Register GLUT event-handling callbacks. // NB: Idle() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
/* ARGSUSED1 */ void key(unsigned char key, int px, int py) { switch (key) { case 27: exit(0); break; case 'A': case 'a': thrust = 1; thrustTime = glutGet(GLUT_ELAPSED_TIME); break; case 'S': case 's': shield = 1; break; case 'C': case 'c': cursor = !cursor; glutSetCursor( cursor ? GLUT_CURSOR_INHERIT : GLUT_CURSOR_NONE); break; case 'z': case 'Z': x = 20; y = 20; xv = 0; yv = 0; initRocks(); break; case 'd': glutGameModeString("1280x1024:32@60"); glutEnterGameMode(); initWindow(); break; case 'f': glutGameModeString("640x480:16@60"); glutEnterGameMode(); initWindow(); break; case 'g': glutGameModeString("800x600:16@60"); glutEnterGameMode(); initWindow(); break; case 'h': if (initialGameModeString) { glutGameModeString(initialGameModeString); glutEnterGameMode(); initWindow(); } break; case 'l': if (originalWindow != 0 && currentWindow != originalWindow) { glutLeaveGameMode(); currentWindow = originalWindow; } break; case 'P': case 'p': paused = !paused; if (paused) { glutIdleFunc(NULL); } else { glutIdleFunc(idle); resuming = 1; } break; case 'Q': case 'q': case ' ': shotBullet(); break; case 'i': printf("%dx%d+%d+%d of depth %d of format %d\n", glutGet(GLUT_WINDOW_WIDTH), glutGet(GLUT_WINDOW_HEIGHT), glutGet(GLUT_WINDOW_X), glutGet(GLUT_WINDOW_Y), glutGet(GLUT_WINDOW_BUFFER_SIZE), glutGet(GLUT_WINDOW_FORMAT_ID)); break; } }
int main(int argc, char** argv) { char glutGamemode[32] = ""; char *vconf = NULL; char cparaDefault[] = "../share/artoolkit-examples/Data/camera_para.dat"; char *cpara = NULL; int i; int gotTwoPartOption; const char markerConfigDataFilename[] = "../share/artoolkit-examples/Data/markers.dat"; const char objectDataFilename[] = "../share/artoolkit-examples/Data/objects.dat"; // // Process command-line options. // glutInit(&argc, argv); i = 1; // argv[0] is name of app, so start at 1. while (i < argc) { gotTwoPartOption = FALSE; // Look for two-part options first. if ((i + 1) < argc) { if (strcmp(argv[i], "--vconf") == 0) { i++; vconf = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--cpara") == 0) { i++; cpara = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--width") == 0) { i++; // Get width from second field. if (sscanf(argv[i], "%d", &prefWidth) != 1) { ARLOGe("Error: --width option must be followed by desired width.\n"); } gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--height") == 0) { i++; // Get height from second field. if (sscanf(argv[i], "%d", &prefHeight) != 1) { ARLOGe("Error: --height option must be followed by desired height.\n"); } gotTwoPartOption = TRUE; } else if (strcmp(argv[i],"--refresh") == 0) { i++; // Get refresh rate from second field. if (sscanf(argv[i], "%d", &prefRefresh) != 1) { ARLOGe("Error: --refresh option must be followed by desired refresh rate.\n"); } gotTwoPartOption = TRUE; } } if (!gotTwoPartOption) { // Look for single-part options. if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) { usage(argv[0]); } else if (strncmp(argv[i], "-cpara=", 7) == 0) { cpara = &(argv[i][7]); } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING); exit(0); } else if (strcmp(argv[i],"--windowed") == 0) { prefWindowed = TRUE; } else if (strcmp(argv[i],"--fullscreen") == 0) { prefWindowed = FALSE; } else { ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]); usage(argv[0]); } } i++; } // // Video setup. // if (!setupCamera((cpara ? cpara : cparaDefault), vconf, &gCparamLT)) { ARLOGe("main(): Unable to set up AR camera.\n"); exit(-1); } // // AR init. // // Init AR. gARPattHandle = arPattCreateHandle(); if (!gARPattHandle) { ARLOGe("Error creating pattern handle.\n"); exit(-1); } gARHandle = arCreateHandle(gCparamLT); if (!gARHandle) { ARLOGe("Error creating AR handle.\n"); exit(-1); } arPattAttach(gARHandle, gARPattHandle); if (arSetPixelFormat(gARHandle, arVideoGetPixelFormat()) < 0) { ARLOGe("Error setting pixel format.\n"); exit(-1); } gAR3DHandle = ar3DCreateHandle(&gCparamLT->param); if (!gAR3DHandle) { ARLOGe("Error creating 3D handle.\n"); exit(-1); } // // Markers setup. // // Load marker(s). newMarkers(markerConfigDataFilename, gARPattHandle, &markersSquare, &markersSquareCount, &gARPattDetectionMode); ARLOGi("Marker count = %d\n", markersSquareCount); // // Other ARToolKit setup. // arSetMarkerExtractionMode(gARHandle, AR_USE_TRACKING_HISTORY_V2); //arSetMarkerExtractionMode(gARHandle, AR_NOUSE_TRACKING_HISTORY); //arSetLabelingThreshMode(gARHandle, AR_LABELING_THRESH_MODE_MANUAL); // Uncomment to force manual thresholding. // Set the pattern detection mode (template (pictorial) vs. matrix (barcode) based on // the marker types as defined in the marker config. file. arSetPatternDetectionMode(gARHandle, gARPattDetectionMode); // Default = AR_TEMPLATE_MATCHING_COLOR // Other application-wide marker options. Once set, these apply to all markers in use in the application. // If you are using standard ARToolKit picture (template) markers, leave commented to use the defaults. // If you are usign a different marker design (see http://www.artoolworks.com/support/app/marker.php ) // then uncomment and edit as instructed by the marker design application. //arSetLabelingMode(gARHandle, AR_LABELING_BLACK_REGION); // Default = AR_LABELING_BLACK_REGION //arSetBorderSize(gARHandle, 0.25f); // Default = 0.25f //arSetMatrixCodeType(gARHandle, AR_MATRIX_CODE_3x3); // Default = AR_MATRIX_CODE_3x3 // // Graphics setup. // // Set up GL context(s) for OpenGL to draw into. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); if (prefWindowed) { if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight); else glutInitWindowSize(gCparamLT->param.xsize, gCparamLT->param.ysize); glutCreateWindow(argv[0]); } else { if (glutGameModeGet(GLUT_GAME_MODE_POSSIBLE)) { if (prefWidth && prefHeight) { if (prefDepth) { if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i@%i", prefWidth, prefHeight, prefDepth, prefRefresh); else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i:%i", prefWidth, prefHeight, prefDepth); } else { if (prefRefresh) snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i@%i", prefWidth, prefHeight, prefRefresh); else snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight); } } else { prefWidth = glutGameModeGet(GLUT_GAME_MODE_WIDTH); prefHeight = glutGameModeGet(GLUT_GAME_MODE_HEIGHT); snprintf(glutGamemode, sizeof(glutGamemode), "%ix%i", prefWidth, prefHeight); } glutGameModeString(glutGamemode); glutEnterGameMode(); } else { if (prefWidth > 0 && prefHeight > 0) glutInitWindowSize(prefWidth, prefHeight); glutCreateWindow(argv[0]); glutFullScreen(); } } // Create the OpenGL projection from the calibrated camera parameters. arglCameraFrustumRH(&(gCparamLT->param), VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, cameraLens); cameraPoseValid = FALSE; // Setup ARgsub_lite library for current OpenGL context. if ((gArglSettings = arglSetupForCurrentContext(&(gCparamLT->param), arVideoGetPixelFormat())) == NULL) { ARLOGe("main(): arglSetupForCurrentContext() returned error.\n"); cleanup(); exit(-1); } arglSetupDebugMode(gArglSettings, gARHandle); // Load objects (i.e. OSG models). VirtualEnvironmentInit(objectDataFilename); VirtualEnvironmentHandleARViewUpdatedCameraLens(cameraLens); // // Setup complete. Start tracking. // // Start the video. if (arVideoCapStart() != 0) { ARLOGe("setupCamera(): Unable to begin camera data capture.\n"); return (FALSE); } arUtilTimerReset(); // Register GLUT event-handling callbacks. // NB: mainLoop() is registered by Visibility. glutDisplayFunc(Display); glutReshapeFunc(Reshape); glutVisibilityFunc(Visibility); glutKeyboardFunc(Keyboard); glutMainLoop(); return (0); }
/** * POINT D'ENTREE PRINCIPAL **/ int main(int argc, char* argv[]) { LogConsole::createInstance(); int screen_width = 1280; int screen_height = 720; glutInit(&argc, argv); glutInitContextVersion(3, 0); glutSetOption( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_GLUTMAINLOOP_RETURNS ); glutInitWindowSize(screen_width, screen_height); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA | GLUT_MULTISAMPLE); glEnable(GL_MULTISAMPLE); Log::log(Log::ENGINE_INFO, (toString(argc) + " arguments en ligne de commande.").c_str()); bool gameMode = true; for (int i = 0; i < argc; i++) { if (argv[i][0] == 'w') { Log::log(Log::ENGINE_INFO, "Arg w mode fenetre.\n"); gameMode = false; } } if (gameMode) { int width = glutGet(GLUT_SCREEN_WIDTH); int height = glutGet(GLUT_SCREEN_HEIGHT); char gameModeStr[200]; sprintf(gameModeStr, "%dx%d:32@60", width, height); glutGameModeString(gameModeStr); g_main_window_id = glutEnterGameMode(); } else { g_main_window_id = glutCreateWindow("MyNecraft"); glutReshapeWindow(screen_width, screen_height); } if (g_main_window_id < 1) { Log::log(Log::ENGINE_ERROR, "Erreur creation de la fenetre."); exit(EXIT_FAILURE); } GLenum glewInitResult = glewInit(); if (glewInitResult != GLEW_OK) { Log::log(Log::ENGINE_ERROR, ("Erreur init glew " + std::string((char*)glewGetErrorString(glewInitResult))).c_str()); _cprintf("ERROR : %s", glewGetErrorString(glewInitResult)); exit(EXIT_FAILURE); } //Affichage des capacités du système Log::log(Log::ENGINE_INFO, ("OpenGL Version : " + std::string((char*)glGetString(GL_VERSION))).c_str()); glutDisplayFunc(update); glutReshapeFunc(resizeFunction); glutKeyboardFunc(keyboardDownFunction); glutKeyboardUpFunc(keyboardUpFunction); glutSpecialFunc(specialDownFunction); glutSpecialUpFunc(specialUpFunction); glutMouseFunc(mouseFunction); glutMotionFunc(mouseMoveActiveFunction); glutPassiveMotionFunc(mouseMovePassiveFunction); glutIgnoreKeyRepeat(1); //Initialisation du renderer g_renderer = NYRenderer::getInstance(); g_renderer->setRenderObjectFun(renderObjects); g_renderer->setRender2DFun(render2d); //g_renderer->setLightsFun(setLights); g_renderer->setLightsFun(setLightsBasedOnDayTime); //g_renderer->setBackgroundColor(NYColor(0, 181.f / 255.f, 221.f / 255.f, 1)); g_program = g_renderer->createProgram("shaders/psbase.glsl", "shaders/vsbase.glsl"); g_renderer->initialise(true); //On applique la config du renderer glViewport(0, 0, g_renderer->_ScreenWidth, g_renderer->_ScreenHeight); g_renderer->resize(g_renderer->_ScreenWidth, g_renderer->_ScreenHeight); //Ecran de jeu uint16 x = 10; uint16 y = 10; g_screen_jeu = new GUIScreen(); g_screen_manager = new GUIScreenManager(); //Bouton pour afficher les params BtnParams = new GUIBouton(); BtnParams->Titre = std::string("Params"); BtnParams->X = x; BtnParams->setOnClick(clickBtnParams); g_screen_jeu->addElement(BtnParams); y += BtnParams->Height + 1; LabelFps = new GUILabel(); LabelFps->Text = "FPS"; LabelFps->X = x; LabelFps->Y = y; LabelFps->Visible = true; g_screen_jeu->addElement(LabelFps); y += BtnParams->Height + 1; LabelCam = new GUILabel(); LabelCam->Text = "Position"; LabelCam->X = x; LabelCam->Y = y; LabelCam->Visible = true; g_screen_jeu->addElement(LabelCam); //Ecran de parametrage x = 10; y = 10; g_screen_params = new GUIScreen(); GUIBouton * btnClose = new GUIBouton(); btnClose->Titre = std::string("Close"); btnClose->X = x; btnClose->setOnClick(clickBtnCloseParam); g_screen_params->addElement(btnClose); y += btnClose->Height + 1; y += 10; x += 10; GUILabel * label = new GUILabel(); label->X = x; label->Y = y; label->Text = "Param :"; g_screen_params->addElement(label); y += label->Height + 1; g_slider = new GUISlider(); g_slider->setPos(x, y); g_slider->setMaxMin(1, 0); g_slider->Visible = true; g_screen_params->addElement(g_slider); y += g_slider->Height + 1; y += 10; //Ecran a rendre g_screen_manager->setActiveScreen(g_screen_jeu); //Init Camera g_renderer->_Camera->setPosition(NYVert3Df(-300, -300, 1300)); g_renderer->_Camera->setLookAt(NYVert3Df(1300, 1300, 500)); //Fin init moteur //Init application //Init Timer g_timer = new NYTimer(); //On start g_timer->start(); //Generation du monde g_world = new NYWorld(); g_world->_FacteurGeneration = 1; g_world->init_world(); avatar = new NYAvatar(g_renderer->_Camera, g_world, NYVert3Df(1, 1, 900)); glutMainLoop(); return 0; }