From a1b4bcd5461b80e9b43cba7e6cf84c7d9d5eea9a Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 21 Jan 2021 16:20:18 +0000 Subject: [PATCH] moved from sdl's renderer to a gl context. (still nothing on screen) --- Makefile | 2 +- src/main.cpp | 87 +++++++++++++++++++++++++++++----------------------- 2 files changed, 49 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 7451c33..bdf91c5 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ # Set default options CC = clang++ -CFLAGS = -g -Wall -lSDL2 -lSDL2main +CFLAGS = -g -Wall -lSDL2 -lSDL2main -lGLEW TARGET = Game SRCDIR = src/ diff --git a/src/main.cpp b/src/main.cpp index 9da7d55..8b3f3e0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,59 +1,68 @@ //#include +#include +#include #include +#include //TODO: Create Error handling class int main(int argc, char ** argv){ - // Initialise SDL2 - SDL_Init(SDL_INIT_EVERYTHING); + // Initialise SDL2 + //TODO: Check if sdl initialised + SDL_Init(SDL_INIT_EVERYTHING); - // Create Window - SDL_Window *window = - SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, - 800, 600, SDL_WINDOW_SHOWN); - //TODO: Test that window was created successfully + //Make OpenGL use double buffering (Render game first then shove to output) + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - // Create Renderer - SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); - // TODO: Test that renderer was created successfully + //TODO: Understand what a depth buffer is + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - //Create event handling struct - SDL_Event input; + //TODO: Discover if thid is necessary for linux and what values they need be + //SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + //SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + //SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + //SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8); + + // Create Window + SDL_Window *window = + SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + 800, 600, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL); + //TODO: Test that window was created successfully - //Temporary until GL context is added - // Set the draw color of renderer to green - SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); + //Create glContext + SDL_GLContext glContext = SDL_GL_CreateContext(window); + //TODO: Test that glContext was created successfully - //update renderer with prior prefix - SDL_RenderPresent(renderer); - - //wait used until close window hook implemented - //SDL_Delay(3000); + //Initialise Glew + if (glewInit() != GLEW_OK){ + //TODO: Throw an error lol + } - // Game loop - bool running = true; - while(running){ - //SDL Event handling loop - while (SDL_PollEvent(&input) > 0){ - // Handle SDL quit event - if (input.type == SDL_QUIT){ - running = false; - } - //TODO: Do something with keys lol + //Create event handling struct + SDL_Event input; + // Game loop + bool running = true; + while(running){ + //SDL Event handling loop + while (SDL_PollEvent(&input) > 0){ + // Handle SDL quit event + if (input.type == SDL_QUIT){ + running = false; + } + //TODO: Do something with keys lol + + }; }; - }; - // Escaped Game loop + // Escaped Game loop - // On close destroy renderer - SDL_DestroyRenderer(renderer); - // On close also destroy window - SDL_DestroyWindow(window); + // On close also destroy window + SDL_DestroyWindow(window); - // Close all leftover SDL systems - SDL_Quit(); + // Close all leftover SDL systems + SDL_Quit(); - return 0; + return 0; }