55 lines
1.2 KiB
C
55 lines
1.2 KiB
C
#include <stdio.h>
|
|
#include <assert.h>
|
|
|
|
#include <SDL3/SDL.h>
|
|
#include <glad/gl.h>
|
|
|
|
int main()
|
|
{
|
|
int ret;
|
|
SDL_Window * window;
|
|
|
|
ret = SDL_Init(SDL_INIT_VIDEO);
|
|
assert(ret == true);
|
|
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
|
|
|
window = SDL_CreateWindow("main",
|
|
640, // w
|
|
480, // h
|
|
SDL_WINDOW_OPENGL);
|
|
assert(window != NULL);
|
|
|
|
SDL_GLContext context = SDL_GL_CreateContext(window);
|
|
assert(context != NULL);
|
|
int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress);
|
|
assert(version != 0);
|
|
|
|
while (1) {
|
|
SDL_Event event;
|
|
while (SDL_PollEvent(&event)) {
|
|
switch (event.type) {
|
|
case SDL_EVENT_QUIT:
|
|
goto exit;
|
|
case SDL_EVENT_KEY_DOWN:
|
|
if (event.key.key == SDLK_ESCAPE)
|
|
goto exit;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
glClearColor(0.1, 0.2, 0.3, 1.0);
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
SDL_GL_SwapWindow(window);
|
|
}
|
|
exit:
|
|
SDL_GL_DestroyContext(context);
|
|
SDL_DestroyWindow(window);
|
|
SDL_Quit();
|
|
}
|