- 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(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 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;
+ }
+ }
+
+ 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;