summaryrefslogtreecommitdiffhomepage
path: root/src/gfx
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2023-06-15 15:02:11 -0400
committerrealtradam <[email protected]>2023-06-15 15:02:11 -0400
commit024067ccbf80de1beccbcf2d3a641566c7c45c17 (patch)
tree3317cf61aed4a8786ee8af410ead69a7c62137c9 /src/gfx
parent425516a9c53183179c43517f1b6501a790378a05 (diff)
downloadRodeoKit-024067ccbf80de1beccbcf2d3a641566c7c45c17.tar.gz
RodeoKit-024067ccbf80de1beccbcf2d3a641566c7c45c17.zip
some non working progress
Diffstat (limited to 'src/gfx')
-rw-r--r--src/gfx/irodeo_gfx_t.h9
-rw-r--r--src/gfx/rodeo_gfx.c114
2 files changed, 100 insertions, 23 deletions
diff --git a/src/gfx/irodeo_gfx_t.h b/src/gfx/irodeo_gfx_t.h
index b367e0f..f0cf5e6 100644
--- a/src/gfx/irodeo_gfx_t.h
+++ b/src/gfx/irodeo_gfx_t.h
@@ -3,11 +3,10 @@
// -- internal --
// public
#include "rodeo/gfx_t.h"
+#include "rodeo/math.h"
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/mat4.h"
typedef uint16_t irodeo_index_type_t;
@@ -33,8 +32,10 @@ struct
bgfx_uniform_handle_t texture_uniforms[2];
float target_width;
float target_height;
- mat4 view_matrix;
- mat4 proj_matrix;
+ //mat4 view_matrix;
+ //mat4 proj_matrix;
+ rodeo_math_mat4_t view_matrix;
+ rodeo_math_mat4_t proj_matrix;
uint64_t frame_count;
uint32_t frame_limit;
uint32_t frame_start;
diff --git a/src/gfx/rodeo_gfx.c b/src/gfx/rodeo_gfx.c
index 33c4be3..1d2f4ee 100644
--- a/src/gfx/rodeo_gfx.c
+++ b/src/gfx/rodeo_gfx.c
@@ -12,8 +12,6 @@
// -- external --
#include "bgfx/c99/bgfx.h"
-#define CGLM_FORCE_DEPTH_ZERO_TO_ONE
-#include "cglm/cglm.h"
#include "SDL_image.h"
#include "SDL.h" // used for timing, need to replace in this file with BGFX at some point
@@ -196,6 +194,45 @@ rodeo_gfx_deinit(void)
bgfx_shutdown();
}
+void
+irodeo_print_matrix(rodeo_math_mat4_t mat)
+{
+ rodeo_log(
+ rodeo_logLevel_warning,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[0][0],
+ mat.raw[0][1],
+ mat.raw[0][2],
+ mat.raw[0][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[1][0],
+ mat.raw[1][1],
+ mat.raw[1][2],
+ mat.raw[1][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[2][0],
+ mat.raw[2][1],
+ mat.raw[2][2],
+ mat.raw[2][3]
+ );
+ rodeo_log(
+ rodeo_logLevel_info,
+ "%.05f, %.05f, %.05f, %.05f",
+ mat.raw[3][0],
+ mat.raw[3][1],
+ mat.raw[3][2],
+ mat.raw[3][3]
+ );
+}
+
+#include "math/irodeo_math.h"
+
void
rodeo_gfx_frame_begin(void)
{
@@ -205,7 +242,9 @@ rodeo_gfx_frame_begin(void)
//glm_lookat(eye, center, up, view);
- glm_mat4_identity(irodeo_gfx_state.view_matrix);
+ mat4 oldway_view_matrix;
+ glm_mat4_identity(oldway_view_matrix);
+ irodeo_gfx_state.view_matrix = rodeo_math_mat4_identity();
//glm_perspective(glm_rad(60.f), 640.f / 480.f, 0.1f, 100.0f, proj);
@@ -231,25 +270,62 @@ rodeo_gfx_frame_begin(void)
// "2" is 1 full screen width, therefore we multiply
// the target and result ratio by 1 for it to be a
// half of the screen size
- vec3 offset = {
- 1 - (1 * (target_width / result_width)), // x
- -(1 - (1 * (target_height / result_height))), // y
+ vec3 oldway_offset = {
+ 1 - (1 * (target_width / result_width)),
+ -(1 - (1 * (target_height / result_height))),
0
};
+ rodeo_math_vec3_t offset = {
+ .x = 1 - (1 * (target_width / result_width)),
+ .y = -(1 - (1 * (target_height / result_height))),
+ .z = 0
+ };
- glm_ortho_rh_zo(
- 0,
- result_width,
- result_height,
- 0,
- -100.0f,
- 100.0f,
- irodeo_gfx_state.proj_matrix
- );
-
- glm_translated(irodeo_gfx_state.proj_matrix, offset);
-
- bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix, irodeo_gfx_state.proj_matrix);
+ mat4 oldway_proj_matrix;
+ glm_mat4_identity(oldway_proj_matrix);
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_identity();
+
+ //rodeo_math_mat4_t translation = rodeo_math_mat4_identity();
+ rodeo_math_mat4_t translation = rodeo_math_mat4_translate(irodeo_gfx_state.proj_matrix, offset);
+ //irodeo_print_matrix(translation);
+
+ //rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
+ // 0 - (game_aspect < window_aspect ? rodeo_gfx_letterbox_first_get().width : 0),
+ // result_width - (game_aspect < window_aspect ? rodeo_gfx_letterbox_first_get().width : 0),
+ // result_height - (game_aspect > window_aspect ? rodeo_gfx_letterbox_first_get().height : 0),
+ // 0 - (game_aspect > window_aspect ? rodeo_gfx_letterbox_first_get().height : 0),
+ // -100.0f,
+ // 100.0f
+ //);
+ rodeo_math_mat4_t ortho = rodeo_math_mat4_orthographic(
+ 0,
+ result_width,
+ result_height,
+ 0,
+ -100.0f,
+ 100.0f
+ );
+ glm_ortho(
+ 0,
+ result_width,
+ result_height,
+ 0,
+ -100.0f,
+ 100.0f,
+ oldway_proj_matrix
+ );
+ glm_translate(oldway_proj_matrix, oldway_offset);
+ //irodeo_print_matrix(ortho);
+
+ irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(ortho, offset);
+ //irodeo_gfx_state.proj_matrix = rodeo_math_mat4_multiply(ortho, translation);
+ //irodeo_gfx_state.proj_matrix = rodeo_math_mat4_translate(ortho, offset);
+ //irodeo_gfx_state.proj_matrix = ortho;
+ irodeo_print_matrix(irodeo_gfx_state.proj_matrix);
+ //irodeo_gfx_state.proj_matrix = ortho;
+
+ bgfx_set_view_transform(0, irodeo_gfx_state.view_matrix.raw, irodeo_gfx_state.proj_matrix.raw);
+ //bgfx_set_view_transform(0, oldway_view_matrix, irodeo_gfx_state.proj_matrix.raw);
bgfx_set_view_rect(0, 0, 0, (uint16_t)rodeo_window_width_get(), (uint16_t)rodeo_window_height_get());
irodeo_gfx_render_buffer_transient_alloc();