From 9138103552e37ba6cd7e0f79d4d7acbc9490f2ae Mon Sep 17 00:00:00 2001 From: shweet Date: Sun, 3 Nov 2024 15:13:24 -0500 Subject: [PATCH] change to the rendering system so it's not god awful oh my lord --- CMakeLists.txt | 4 ++-- src/engine/renderer.c | 7 +++++-- src/game/ecs/entity/ui/entity_cursor.c | 2 ++ src/game/ecs/entity/ui/entity_cursor.h | 4 ++-- src/game/game.c | 15 +++++++-------- src/game/render/buffer.c | 2 -- 6 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2827f19..d7a5222 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,14 +35,14 @@ file(GLOB src add_executable(${PROJECT_NAME} ${src}) -set (CMAKE_C_FLAGS "-O2 -Wall -Wextra -pedantic -Wno-unused-variable -Wno-unused-parameter -Wno-parentheses") +set (CMAKE_C_FLAGS "-O2 -Wall -Wextra -pedantic -Wno-discarded-qualifiers -Wno-unused-variable -Wno-unused-parameter -Wno-parentheses") if (EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='['png']' -s USE_SDL_MIXER=2 -s SDL2_MIXER_FORMATS='['ogg']' -s USE_SDL_TTF=2 -s ASSERTIONS=1 -s ALLOW_MEMORY_GROWTH=1 -Wno-strict-prototypes -Wno-incompatible-pointer-types-discards-qualifiers -Wno-unused-command-line-argument -Wno-ignored-qualifiers") target_link_options(${PROJECT_NAME} PRIVATE --preload-file res -s USE_WEBGL2=1 ) elseif (WIN32) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows -Wno-discarded-qualifers") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mwindows") target_link_libraries(${PROJECT_NAME} mingw32 m SDL2main SDL2 SDL2_image SDL2_mixer SDL2_ttf opengl32 glew32) elseif (UNIX) target_link_libraries(${PROJECT_NAME} m SDL2 SDL2_image SDL2_mixer SDL2_ttf GL GLEW) diff --git a/src/engine/renderer.c b/src/engine/renderer.c index 86879b3..732350f 100644 --- a/src/engine/renderer.c +++ b/src/engine/renderer.c @@ -99,8 +99,8 @@ renderer_init(Renderer* self, Window* window, CameraType type, const ivec2* buff } glEnable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glDepthFunc(GL_LESS); + //glEnable(GL_DEPTH_TEST); + //glDepthFunc(GL_LESS); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } @@ -134,6 +134,9 @@ void renderer_clear(Renderer* self) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) + renderer_buffer_clear(self, i); } void diff --git a/src/game/ecs/entity/ui/entity_cursor.c b/src/game/ecs/entity/ui/entity_cursor.c index 0c15b1d..58a3cf5 100644 --- a/src/game/ecs/entity/ui/entity_cursor.c +++ b/src/game/ecs/entity/ui/entity_cursor.c @@ -20,6 +20,7 @@ entity_cursor_add(ECS* ecs) (f32*)ENTITY_CURSOR_POSITION ); + /* component_pulsate_init ( ecs_component_get(ecs, COMPONENT_PULSATE, id), @@ -28,6 +29,7 @@ entity_cursor_add(ECS* ecs) (f32*)ENTITY_CURSOR_PULSATE_MAX_SCALE, ENTITY_CURSOR_PULSATE_FREQUENCY ); + */ return id; } diff --git a/src/game/ecs/entity/ui/entity_cursor.h b/src/game/ecs/entity/ui/entity_cursor.h index 620e4c5..313efdd 100644 --- a/src/game/ecs/entity/ui/entity_cursor.h +++ b/src/game/ecs/entity/ui/entity_cursor.h @@ -6,12 +6,12 @@ EntityID entity_cursor_add(ECS* ecs); -#define ENTITY_CURSOR_DEPENDENCY_COUNT 3 +#define ENTITY_CURSOR_DEPENDENCY_COUNT 2 static const ComponentType ENTITY_CURSOR_DEPENDENCIES[ENTITY_CURSOR_DEPENDENCY_COUNT] = { COMPONENT_GAME_OBJECT, COMPONENT_COPY_MOUSE_POSITION, - COMPONENT_PULSATE, + //COMPONENT_PULSATE, }; static const RendererBuffer ENTITY_CURSOR_BUFFER = RENDERER_BUFFER_CURSOR; diff --git a/src/game/game.c b/src/game/game.c index 12792b3..99636d9 100644 --- a/src/game/game.c +++ b/src/game/game.c @@ -14,6 +14,9 @@ _game_quit(Game* self) ecs_free(&self->ecs); + for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) + renderer_buffer_free(&self->renderer, (RendererBuffer)i); + renderer_free(&self->renderer); window_free(&self->window); @@ -57,20 +60,16 @@ _game_tick(Game* self) static void _game_update(Game* self) { - renderer_update(&self->renderer); ecs_update(&self->ecs); } static void _game_draw(Game* self) { - renderer_clear_color_set(&self->renderer, (f32*)RENDERER_CLEAR_COLOR); + renderer_clear_color_set(&self->renderer, (f32*)BLACK); renderer_clear(&self->renderer); - for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) - renderer_buffer_init(&self->renderer, (RendererBuffer)i); - ecs_draw(&self->ecs); for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) @@ -85,9 +84,6 @@ _game_draw(Game* self) } renderer_present(&self->renderer); - - for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) - renderer_buffer_free(&self->renderer, (RendererBuffer)i); } void game_init(Game* self) @@ -111,6 +107,9 @@ game_init(Game* self) for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) postprocessing_init(&self->postprocessing[i], OPAQUE, TRANSPARENT); + for (s32 i = 0; i < RENDERER_BUFFER_COUNT; i++) + renderer_buffer_init(&self->renderer, (RendererBuffer)i); + if (!resources_init(&self->resources)) { printf("%s\n", STRING_RESOURCE_ERROR); diff --git a/src/game/render/buffer.c b/src/game/render/buffer.c index b5ce529..6d6bea1 100644 --- a/src/game/render/buffer.c +++ b/src/game/render/buffer.c @@ -24,8 +24,6 @@ buffer_draw(Renderer* renderer, Shader* shader, RendererBuffer buffer, Postproce camera_projection_get(&renderer->camera[buffer], projection); camera_view_get(&renderer->camera[buffer], view); - glDisable(GL_DEPTH_TEST); - texture_quad_draw ( &renderer->fboTextures[buffer],