XVisualInfo * glXChooseVisual (Display *dpy, int screen, int *attribList) { static int colordepth = -1; XVisualInfo theTemplate; XVisualInfo *visuals, *rv; int numVisuals; long mask; int i; /* process user flags */ while (*attribList != None) { switch (*attribList) { case GLX_USE_GL: glx_use_gl = 1; break; case GLX_RGBA: glx_rgba = 1; break; case GLX_DOUBLEBUFFER: glx_doublebuffer = 1; break; case GLX_RED_SIZE: glx_red_size = *++attribList; break; case GLX_GREEN_SIZE: glx_green_size = *++attribList; break; case GLX_BLUE_SIZE: glx_blue_size = *++attribList; break; case GLX_ALPHA_SIZE: glx_alpha_size = *++attribList; break; case GLX_DEPTH_SIZE: glx_depth_size = *++attribList; break; case GLX_STENCIL_SIZE: glx_stencil_size = *++attribList; break; } attribList++; } if (!glx_rgba) { return NULL; } if (colordepth <= 0) { colordepth = sage_init(); if (colordepth <= 0) { return NULL; } atexit(sage_fini); } /* get list of all visuals on this screen */ theTemplate.screen = screen; mask = VisualScreenMask; visuals = XGetVisualInfo(dpy, mask, &theTemplate, &numVisuals); for (i = 1; i < numVisuals; i++) { int c_class = #if defined(__cplusplus) || defined(c_plusplus) visuals[i].c_class #else visuals[i].class #endif ; if (c_class == DirectColor || c_class == TrueColor) { break; } } if (i >= numVisuals) { rv = NULL; } else { rv = malloc(sizeof(XVisualInfo)); if (rv != NULL) { *rv = visuals[i]; } } XFree(visuals); return rv; }
bool Renderer::init() { if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_JOYSTICK) != 0) { std::cerr << "Failed to initialise video subsytem" << std::endl << std::flush; return false; } SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 1); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); int sticks = SDL_NumJoysticks(); if (sticks > 0) { SDL_Joystick * stick = SDL_JoystickOpen(0); int axes = SDL_JoystickNumAxes(stick); // Returns the number of joysitck axes int buttons = SDL_JoystickNumButtons(stick); // Returns the number of joysitck buttons int balls = SDL_JoystickNumBalls(stick); // Returns the number of joysitck balls int hats = SDL_JoystickNumHats(stick); // Returns the number of joysitck hats std::cout << "Querying the first of " << sticks << " joysticks"; std::cout << "It has " << axes << " axes, " << buttons << " buttons, " << balls << " balls and " << hats << " hats" << std::endl << std::flush; } videoModes = SDL_ListModes(NULL, SDL_FULLSCREEN|SDL_HWSURFACE); /* Check is there are any modes available */ if(videoModes == 0){ printf("No modes available!\n"); } else if (videoModes == (SDL_Rect **)-1) { printf("All resolutions available.\n"); } else{ /* Print valid modes */ printf("Available Modes\n"); for(int i=0; videoModes[i]; ++i) { printf(" %d x %d\n", videoModes[i]->w, videoModes[i]->h); } } fflush(stdout); // These should be turned on when running in production mode, but they // make using a debugger really hard and are only required in the perspective // client // SDL_WM_GrabInput(SDL_GRAB_ON); // SDL_ShowCursor(0); shapeView(); Texture::getDefault(); std::string extensions((const char *)glGetString(GL_EXTENSIONS)); std::cout << "EXTENSIONS: " << extensions << std::endl << std::flush; sage_init(); if (sage_ext[GL_ARB_VERTEX_BUFFER_OBJECT]) { std::cout << "GL_ARB_VERTEX_BUFFER_OBJECT supported" << std::endl << std::flush; } else { std::cout << "GL_ARB_VERTEX_BUFFER_OBJECT NOT supported" << std::endl << std::flush; } int textureUnits = -23; glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &textureUnits); std::cout << "TEXTURE UNITS AVAILABLE: " << textureUnits << std::endl << std::flush; int depthbits = -1; SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depthbits); std::cout << "DEPTH BITS AVAILABLE: " << depthbits << std::endl << std::flush; model = new Cal3dModel(); if (!model->onInit(getMediaPath() + "/media/media_new/3d_skeletons/paladin/paladin.cfg")) { std::cerr << "Loading paladin model failed" << std::endl << std::flush; } model->setLodLevel(1.0f); return true; }