From 457fd25a0ea155a2ac2f8a64f97b74352518f54c Mon Sep 17 00:00:00 2001
From: matthew <matthew@owens.tech>
Date: Fri, 17 Aug 2018 19:14:08 +0100
Subject: [PATCH] created a basic gl window, implemented gl/err.c skeleton

---
 gl/main.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/gl/main.c b/gl/main.c
index 0d07da1..7d2c057 100644
--- a/gl/main.c
+++ b/gl/main.c
@@ -5,6 +5,8 @@
 
 static SDL_Window *window = NULL;
 static SDL_GLContext *context = NULL;
+static int screen_width = 1280;
+static int screen_height = 720;
 
 static bool init()
 {
@@ -15,8 +17,8 @@ static bool init()
 		return false;
 	}
 
-	window = SDL_CreateWindow("csrpg", SDL_WINDOWPOS_CENTERED,
-			 SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL);
+	window = SDL_CreateWindow("csrpg - opengl", SDL_WINDOWPOS_CENTERED,
+			 SDL_WINDOWPOS_CENTERED, screen_width, screen_height, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
 
 	if (window == NULL){
 		printf("SDL couldn't make an OpenGL window! SDL_Error: %s\n", SDL_GetError());
@@ -37,6 +39,7 @@ static bool init()
 
 	/* syncing the buffer swap with the monitor's vertical refresh */
 	SDL_GL_SetSwapInterval(1);
+	glViewport(0, 0, screen_width, screen_height);
 
 	glewExperimental = GL_TRUE;
 	glewInit();
@@ -44,23 +47,38 @@ static bool init()
 	return true;
 }
 
+static void render()
+{
+	glClearColor(0.2, 0.3, 0.3, 1.0);
+	glClear(GL_COLOR_BUFFER_BIT);
+	SDL_GL_SwapWindow(window);
+}
+
 int main()
 {
 	Uint32 itime;
 	Uint32 ctime = 0;
+	SDL_Event e;
 
 	if(!init())
 		return -1;
 
 	itime = SDL_GetTicks();
 
-	glClearColor(0.0, 0.0, 0.0, 1.0);
-	glClear(GL_COLOR_BUFFER_BIT);
-	SDL_GL_SwapWindow(window);
 
-	while(ctime != itime + 2000){
+	while(ctime != itime + 10000){
 		ctime = SDL_GetTicks();
+
+		while(SDL_PollEvent(&e) != 0){
+			if (e.type == SDL_QUIT){
+				printf("quitting!\n");
+				ctime = itime + 10000;
+			}
+		}
+
+		render();
 	}
+
 	SDL_Quit();
 	return 0;
 }
-- 
2.20.1