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 # Set default options
CC = clang++ CC = clang++
CFLAGS = -g -Wall -lSDL2 -lSDL2main CFLAGS = -g -Wall -lSDL2 -lSDL2main -lGLEW
TARGET = Game TARGET = Game
SRCDIR = src/ SRCDIR = src/

View file

@ -1,59 +1,68 @@
//#include <iostream> //#include <iostream>
#include <GL/glew.h>
#include <GL/gl.h>
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_opengl.h>
//TODO: Create Error handling class //TODO: Create Error handling class
int main(int argc, char ** argv){ int main(int argc, char ** argv){
// Initialise SDL2 // Initialise SDL2
SDL_Init(SDL_INIT_EVERYTHING); //TODO: Check if sdl initialised
SDL_Init(SDL_INIT_EVERYTHING);
// Create Window //Make OpenGL use double buffering (Render game first then shove to output)
SDL_Window *window = SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
800, 600, SDL_WINDOW_SHOWN);
//TODO: Test that window was created successfully
// Create Renderer //TODO: Understand what a depth buffer is
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
// TODO: Test that renderer was created successfully
//Create event handling struct //TODO: Discover if thid is necessary for linux and what values they need be
SDL_Event input; //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);
//Temporary until GL context is added // Create Window
// Set the draw color of renderer to green SDL_Window *window =
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255); SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
800, 600, SDL_WINDOW_SHOWN|SDL_WINDOW_OPENGL);
//TODO: Test that window was created successfully
//update renderer with prior prefix //Create glContext
SDL_RenderPresent(renderer); SDL_GLContext glContext = SDL_GL_CreateContext(window);
//TODO: Test that glContext was created successfully
//wait used until close window hook implemented //Initialise Glew
//SDL_Delay(3000); if (glewInit() != GLEW_OK){
//TODO: Throw an error lol
}
// Game loop //Create event handling struct
bool running = true; SDL_Event input;
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
// 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 // On close also destroy window
SDL_DestroyRenderer(renderer); SDL_DestroyWindow(window);
// On close also destroy window
SDL_DestroyWindow(window);
// Close all leftover SDL systems // Close all leftover SDL systems
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }