1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| #include <stddef.h> #include <SDL.h> #include "glad/glad.h" #pragma comment(lib, "SDL2.lib") #pragma comment(lib, "SDL2main.lib") #define SCREEN_WIDTH 800 #define SCREEN_HEIGHT 600
int main(int argc, char *argv[]) { SDL_Window *window = NULL; SDL_GLContext context = NULL; SDL_Event event; int ret = -1; if (SDL_Init(SDL_INIT_VIDEO) < 0) { return ret; } SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); window = SDL_CreateWindow("SDL-OpenGL3.3", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if (!window) { goto end; } context = SDL_GL_CreateContext(window); gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress); glClearColor(1.0f, 1.0f, 0.5f, 1.0f); while (1) { while (SDL_PollEvent(&event)) { if (event.type == SDL_QUIT) { goto end; }; } glClear(GL_COLOR_BUFFER_BIT); SDL_GL_SwapWindow(window); SDL_Delay(100); } ret = 0; end: if (context) { SDL_GL_DeleteContext(context); } if (window) { SDL_DestroyWindow(window); } SDL_Quit(); return ret; }
|