Basic 3D rendering
This commit is contained in:
37
src/game.c
37
src/game.c
@@ -1,32 +1,15 @@
|
||||
#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"
|
||||
#include "render.h"
|
||||
#include "camera.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");
|
||||
if (!Render_Init(gs)) return NULL;
|
||||
|
||||
gs->running = true;
|
||||
return gs;
|
||||
@@ -34,12 +17,20 @@ GameState *Game_New()
|
||||
|
||||
void Game_Update(GameState *gs)
|
||||
{
|
||||
SDL_Delay(100);
|
||||
vec3 move;
|
||||
glm_vec3_zero(move);
|
||||
if (gs->input.w) move[0] = 0.3f;
|
||||
else if (gs->input.s) move[0] = -0.3f;
|
||||
if (gs->input.a) move[1] = 0.3f;
|
||||
else if (gs->input.d) move[1] = -0.3f;
|
||||
glm_vec3_add(gs->camera.position, move, gs->camera.position);
|
||||
|
||||
Camera_UpdateVectors(&gs->camera);
|
||||
SDL_Delay(5);
|
||||
}
|
||||
|
||||
void Game_Destroy(GameState *gs)
|
||||
{
|
||||
SDL_GL_DeleteContext(gs->glContext);
|
||||
SDL_DestroyWindow(gs->window);
|
||||
Render_Destroy(gs);
|
||||
free(gs);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user