- glutInitWindowSize(1024, 768);
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_MULTISAMPLE);
- glutCreateWindow("demo");
-
- glutDisplayFunc(display);
- glutIdleFunc(idle);
- glutReshapeFunc(reshape);
- glutKeyboardFunc(key_press);
- glutKeyboardUpFunc(key_release);
- glutMouseFunc(mouse);
- glutMotionFunc(app_mouse_motion);
- glutPassiveMotionFunc(app_mouse_motion);
-
- if(!init()) {
+ if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
+ fprintf(stderr, "failed to initialize SDL\n");
+ return 1;
+ }
+
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
+ SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 8);
+ SDL_GL_SetAttribute(SDL_GL_FRAMEBUFFER_SRGB_CAPABLE, 1);
+
+ int defpos = SDL_WINDOWPOS_UNDEFINED;
+ unsigned int sdlflags = SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI;
+
+ 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");
+
+ 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));
+ }
+ }
+
+ if(!init(argc, argv)) {
+ SDL_Quit();