From 4136e8f2e1e5da874d58fcea3b1f004b07c9677f Mon Sep 17 00:00:00 2001 From: kitty piapiac Date: Sat, 15 Apr 2023 22:57:36 -0700 Subject: init sdl2,opengl --- graph.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 graph.c (limited to 'graph.c') diff --git a/graph.c b/graph.c new file mode 100644 index 0000000..1063a50 --- /dev/null +++ b/graph.c @@ -0,0 +1,36 @@ +#include +#include +#define SDL_MAIN_HANDLED +#include +#include"mino.h" +#include"graph.h" + +_ SDL_Window*win; +_ SDL_GLContext ctx; +_ U32 win_w=1280; +_ U32 win_h=720; +_ V on_err(IM C*d){die("Could not %s: %s\n",d,SDL_GetError());} + +V graph_init(V){SDL_version sdl_vh,sdl_vl; + Q(SDL_Init(SDL_INIT_VIDEO),on_err("init sdl2")) + 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); + N(win=SDL_CreateWindow("mino",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,win_w,win_h,SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL),on_err("create window")) + N(ctx=SDL_GL_CreateContext(win),on_err("create OpenGL context")) + N(gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress),on_err("load GL")) + SDL_GL_SetSwapInterval(-1); + + SDL_VERSION(&sdl_vh)SDL_GetVersion(&sdl_vl); + fprintf(stderr, + "Graphics initialization successful!\n" + "\tSDL Version: %d.%d.%d (built against)\n" + "\tSDL Version: %d.%d.%d (linked against)\n" + "\tOpenGL Version: %s\n" + "\tOpenGL Vendor: %s\n" + "\tOpenGL Renderer: %s\n", + sdl_vh.major,sdl_vh.minor,sdl_vh.patch, + sdl_vl.major,sdl_vl.minor,sdl_vl.patch, + glGetString(GL_VERSION),glGetString(GL_VENDOR),glGetString(GL_RENDERER));} + +V graph_deinit(V){SDL_GL_DeleteContext(ctx),SDL_DestroyWindow(win),SDL_Quit();} -- cgit v1.2.3