summaryrefslogtreecommitdiff
path: root/graph.c
diff options
context:
space:
mode:
authorkitty piapiac <kcp@bsd.computer>2023-04-15 22:57:36 -0700
committerkitty piapiac <kcp@bsd.computer>2023-04-15 22:57:36 -0700
commit4136e8f2e1e5da874d58fcea3b1f004b07c9677f (patch)
tree93350473689fef10155c4598a43fef7374871b47 /graph.c
init sdl2,opengl
Diffstat (limited to 'graph.c')
-rw-r--r--graph.c36
1 files changed, 36 insertions, 0 deletions
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<stdio.h>
+#include<glad/glad.h>
+#define SDL_MAIN_HANDLED
+#include<SDL.h>
+#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();}