updating renderer work done
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
cmake-build-debug
|
||||
SDL
|
||||
.idea/
|
||||
external/
|
||||
|
||||
@@ -8,10 +8,23 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/$<CONFIGURATION>")
|
||||
|
||||
# This assumes the SDL source is available in SDL
|
||||
add_subdirectory(SDL EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(external/SDL EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(external/cglm EXCLUDE_FROM_ALL)
|
||||
#add_subdirectory(glad EXCLUDE_FROM_ALL)
|
||||
|
||||
# Create your game executable target as usual
|
||||
add_executable(BeyondDepth WIN32 main.c)
|
||||
add_executable(BeyondDepth src/main.c
|
||||
src/engine/core/logger/log.c
|
||||
src/engine/renderer/camera/camera.c
|
||||
src/engine/renderer/camera/camera.h
|
||||
external/glad/src/glad.c
|
||||
src/engine/renderer/shaders/shader.c
|
||||
src/engine/renderer/shaders/shader.h)
|
||||
|
||||
# Link to the actual SDL3 library.
|
||||
target_link_libraries(BeyondDepth PRIVATE SDL3::SDL3)
|
||||
set_target_properties(BeyondDepth PROPERTIES WIN32_EXECUTABLE FALSE)
|
||||
|
||||
target_include_directories(BeyondDepth PRIVATE external/glad/include)
|
||||
|
||||
target_link_libraries(BeyondDepth PRIVATE
|
||||
SDL3::SDL3
|
||||
cglm)
|
||||
49
src/engine/core/logger/log.h
Normal file
49
src/engine/core/logger/log.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Copyright (c) 2020 rxi
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the MIT license. See `log.c` for details.
|
||||
*/
|
||||
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
#define LOG_VERSION "0.1.0"
|
||||
|
||||
typedef struct {
|
||||
va_list ap;
|
||||
const char *fmt;
|
||||
const char *file;
|
||||
struct tm *time;
|
||||
void *udata;
|
||||
int line;
|
||||
int level;
|
||||
} log_Event;
|
||||
|
||||
typedef void (*log_LogFn)(log_Event *ev);
|
||||
typedef void (*log_LockFn)(bool lock, void *udata);
|
||||
|
||||
enum { LOG_TRACE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL };
|
||||
|
||||
#define log_trace(...) log_log(LOG_TRACE, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define log_debug(...) log_log(LOG_DEBUG, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define log_info(...) log_log(LOG_INFO, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define log_warn(...) log_log(LOG_WARN, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define log_error(...) log_log(LOG_ERROR, __FILE__, __LINE__, __VA_ARGS__)
|
||||
#define log_fatal(...) log_log(LOG_FATAL, __FILE__, __LINE__, __VA_ARGS__)
|
||||
|
||||
const char* log_level_string(int level);
|
||||
void log_set_lock(log_LockFn fn, void *udata);
|
||||
void log_set_level(int level);
|
||||
void log_set_quiet(bool enable);
|
||||
int log_add_callback(log_LogFn fn, void *udata, int level);
|
||||
int log_add_fp(FILE *fp, int level);
|
||||
|
||||
void log_log(int level, const char *file, int line, const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
@@ -3,3 +3,34 @@
|
||||
//
|
||||
|
||||
#include "camera.h"
|
||||
|
||||
Camera l_camera = {
|
||||
.Position = { 0.0f, 0.0f, 0.0f },
|
||||
.Orientation = { 0.0f, 0.0f, -1.0f },
|
||||
.Up = { 0.0f, 1.0f, 0.0f }
|
||||
};
|
||||
|
||||
void matrix(float FOVdeg, float nearPlane, float farPlane, Shader* shader_instance, const char* uniform) {
|
||||
mat4 view, projection;
|
||||
glm_mat4_identity(view);
|
||||
glm_mat4_identity(projection);
|
||||
|
||||
// store the result of the vector addition
|
||||
vec3 target;
|
||||
|
||||
// cglm function to perform vector addition
|
||||
glm_vec3_add(l_camera.Position, l_camera.Orientation, target);
|
||||
|
||||
mat4 target_2;
|
||||
|
||||
glm_mat4_mul(projection[0], view[0], target_2);
|
||||
|
||||
// now we can use the addition of the two vec3's in the glm_lookat() function
|
||||
glm_lookat(l_camera.Position, target, l_camera.Up, view);
|
||||
|
||||
glm_perspective(glm_rad(FOVdeg), (float)(l_camera.width / l_camera.height), nearPlane, farPlane, projection);
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(shader_instance->ID, uniform), 1, GL_FALSE, target_2);
|
||||
}
|
||||
|
||||
void inputs(SDL_Window* window);
|
||||
@@ -5,4 +5,21 @@
|
||||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <cglm/cglm.h>
|
||||
#include "../shaders/shader.h"
|
||||
|
||||
typedef struct {
|
||||
vec3 Position;
|
||||
vec3 Orientation;
|
||||
vec3 Up;
|
||||
float speed;
|
||||
float sensitivity;
|
||||
int width;
|
||||
int height;
|
||||
} Camera;
|
||||
|
||||
void matrix(float FOVdeg, float nearPlane, float farPlane, Shader* shader_instance, const char* uniform);
|
||||
void inputs(SDL_Window* window);
|
||||
|
||||
#endif //CAMERA_H
|
||||
|
||||
@@ -5,4 +5,24 @@
|
||||
#ifndef SHADER_H
|
||||
#define SHADER_H
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct {
|
||||
// Reference ID of the shader program
|
||||
GLuint ID;
|
||||
} Shader;
|
||||
|
||||
char *get_file_contents(const char *filename);
|
||||
|
||||
Shader shader_create(const char *vertexFile, const char *fragmentFile);
|
||||
|
||||
// Takes a pointer to the instance
|
||||
void shader_activate(Shader *self);
|
||||
void shader_delete(Shader *self);
|
||||
|
||||
// Private helper on shaderClass.h C++ header -- no private in C :)
|
||||
void compile_errors(unsigned int shader, const char *type);
|
||||
|
||||
|
||||
#endif //SHADER_H
|
||||
|
||||
13
src/main.c
13
src/main.c
@@ -12,6 +12,9 @@
|
||||
#define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */
|
||||
#include <SDL3/SDL.h>
|
||||
#include <SDL3/SDL_main.h>
|
||||
#include <cglm/cglm.h>
|
||||
#include "engine/core/logger/log.h"
|
||||
#include "engine/renderer/camera/camera.h"
|
||||
|
||||
static SDL_Window *window = NULL;
|
||||
static SDL_Renderer *renderer = NULL;
|
||||
@@ -19,9 +22,14 @@ static SDL_Renderer *renderer = NULL;
|
||||
/* This function runs once at startup. */
|
||||
SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[])
|
||||
{
|
||||
//log_set_level(2);
|
||||
log_info("Starting program and initializing SDL...");
|
||||
/* Create the window */
|
||||
if (!SDL_CreateWindowAndRenderer("Hello World", 800, 600, SDL_WINDOW_FULLSCREEN, &window, &renderer)) {
|
||||
|
||||
// SDL_WINDOW_FULLSCREEN overrides with window_flags to make window fullscreen
|
||||
if (!SDL_CreateWindowAndRenderer("Hello World", 800, 600, 0, &window, &renderer)) {
|
||||
SDL_Log("Couldn't create window and renderer: %s", SDL_GetError());
|
||||
log_error("Couldn't create window and renderer %s", SDL_GetError());
|
||||
return SDL_APP_FAILURE;
|
||||
}
|
||||
return SDL_APP_CONTINUE;
|
||||
@@ -32,6 +40,7 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
|
||||
{
|
||||
if (event->type == SDL_EVENT_KEY_DOWN ||
|
||||
event->type == SDL_EVENT_QUIT) {
|
||||
log_info("User pressed a key");
|
||||
return SDL_APP_SUCCESS; /* end the program, reporting success to the OS. */
|
||||
}
|
||||
return SDL_APP_CONTINUE;
|
||||
@@ -58,6 +67,8 @@ SDL_AppResult SDL_AppIterate(void *appstate)
|
||||
SDL_RenderDebugText(renderer, x, y, message);
|
||||
SDL_RenderPresent(renderer);
|
||||
|
||||
|
||||
|
||||
return SDL_APP_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user