moved from sdl's renderer to a gl context. (still nothing on screen)

This commit is contained in:
Warwick 2021-01-21 16:20:18 +00:00
parent 59d7a544a8
commit a1b4bcd546
2 changed files with 49 additions and 40 deletions

View file

@ -1,7 +1,7 @@
# Set default options
CC = clang++
CFLAGS = -g -Wall -lSDL2 -lSDL2main
CFLAGS = -g -Wall -lSDL2 -lSDL2main -lGLEW
TARGET = Game
SRCDIR = src/

View file

@ -1,59 +1,68 @@
//#include <iostream>
#include <GL/glew.h>
#include <GL/gl.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
//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;
}