+ if(!(win = SDL_CreateWindow("demo", defpos, defpos, 1024, 768, sdlflags))) {
+ // try again without sRGB capability
+ SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 0);
+ if(!(win = SDL_CreateWindow("demo", defpos, defpos, 1024, 768, sdlflags))) {
+ fprintf(stderr, "failed to create window\n");
+ SDL_Quit();
+ return 1;
+ }
+ fprintf(stderr, "failed to get an sRGB framebuffer.\n");
+ }
+ int val;
+ SDL_GL_GetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, &val);
+ printf("SDL says we %s an sRGB framebuffer\n", val ? "got" : "didn't get");
+ fb_srgb = val;
+
+ if(!(ctx = SDL_GL_CreateContext(win))) {
+ fprintf(stderr, "failed to create OpenGL context\n");
+ SDL_Quit();
+ return 1;
+ }
+ SDL_GL_GetDrawableSize(win, &win_width, &win_height);
+ win_aspect = (float)win_width / (float)win_height;
+
+ printf("detected %d joysticks\n", SDL_NumJoysticks());
+ for(int i=0; i<SDL_NumJoysticks(); i++) {
+ if(SDL_IsGameController(i)) {
+ if(!(gamepad = SDL_GameControllerOpen(i))) {
+ fprintf(stderr, "failed to open game controller %i: %s\n", i, SDL_GetError());
+ continue;
+ }
+ printf("Using gamepad: %s\n", SDL_GameControllerNameForIndex(i));
+ }
+ }