46 lines
1.1 KiB
C
46 lines
1.1 KiB
C
#include <stdbool.h>
|
|
#include <stdio.h>
|
|
#include "SDL2/SDL.h"
|
|
#include "SDL2/SDL_timer.h"
|
|
#include "GL/glew.h"
|
|
#include "SDL2/SDL_opengl.h"
|
|
#include "game.h"
|
|
|
|
GameState *Game_New()
|
|
{
|
|
GameState *gs = calloc(1, sizeof(GameState));
|
|
|
|
SDL_Init(SDL_INIT_VIDEO);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
|
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
|
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
|
|
|
gs->window = SDL_CreateWindow("Game", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1920, 1080, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);;
|
|
gs->glContext = SDL_GL_CreateContext(gs->window);
|
|
printf("Created OpenGL window.\n");
|
|
|
|
glewInit();
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_CULL_FACE);
|
|
glEnable(GL_TEXTURE_2D);
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
printf("Initialized OpenGL.\n");
|
|
|
|
gs->running = true;
|
|
return gs;
|
|
}
|
|
|
|
void Game_Update(GameState *gs)
|
|
{
|
|
SDL_Delay(100);
|
|
}
|
|
|
|
void Game_Destroy(GameState *gs)
|
|
{
|
|
SDL_GL_DeleteContext(gs->glContext);
|
|
SDL_DestroyWindow(gs->window);
|
|
free(gs);
|
|
}
|