From ee8da4db097c2b2174088cd4bf32b26236ac8ae0 Mon Sep 17 00:00:00 2001 From: Rebekah Rowe Date: Tue, 5 Apr 2022 13:43:53 -0400 Subject: [PATCH] removed mat4.c/h --- ftgl/CMakeLists.txt | 8 +- ftgl/mat4.c | 214 -------------------------------------------- ftgl/mat4.h | 63 ------------- src/glez.cpp | 10 +-- 4 files changed, 8 insertions(+), 287 deletions(-) delete mode 100644 ftgl/mat4.c delete mode 100644 ftgl/mat4.h diff --git a/ftgl/CMakeLists.txt b/ftgl/CMakeLists.txt index 0db011f..1055e1d 100644 --- a/ftgl/CMakeLists.txt +++ b/ftgl/CMakeLists.txt @@ -1,6 +1,4 @@ -target_sources(glez PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/freetype-gl.h" - "${CMAKE_CURRENT_LIST_DIR}/mat4.h") + -target_sources(glez PRIVATE - "${CMAKE_CURRENT_LIST_DIR}/mat4.c") \ No newline at end of file +#target_sources(glez PRIVATE + #"${CMAKE_CURRENT_LIST_DIR}/mat4.c") \ No newline at end of file diff --git a/ftgl/mat4.c b/ftgl/mat4.c deleted file mode 100644 index fbdecfe..0000000 --- a/ftgl/mat4.c +++ /dev/null @@ -1,214 +0,0 @@ -/* Freetype GL - A C OpenGL Freetype engine - * - * Distributed under the OSI-approved BSD 2-Clause License. See accompanying - * file `LICENSE` for more details. - */ -#include -#include -#include -#include "mat4.h" - -mat4 *mat4_new(void) -{ - mat4 *self = (mat4 *) malloc(sizeof(mat4)); - return self; -} - -void mat4_set_zero(mat4 *self) -{ - if (!self) - return; - - memset(self, 0, sizeof(mat4)); -} - -void mat4_set_identity(mat4 *self) -{ - if (!self) - return; - - memset(self, 0, sizeof(mat4)); - self->m00 = 1.0; - self->m11 = 1.0; - self->m22 = 1.0; - self->m33 = 1.0; -} - -void mat4_multiply(mat4 *self, mat4 *other) -{ - mat4 m; - size_t i; - - if (!self || !other) - return; - - for (i = 0; i < 4; ++i) - { - m.data[i * 4 + 0] = (self->data[i * 4 + 0] * other->data[0 * 4 + 0]) + - (self->data[i * 4 + 1] * other->data[1 * 4 + 0]) + - (self->data[i * 4 + 2] * other->data[2 * 4 + 0]) + - (self->data[i * 4 + 3] * other->data[3 * 4 + 0]); - - m.data[i * 4 + 1] = (self->data[i * 4 + 0] * other->data[0 * 4 + 1]) + - (self->data[i * 4 + 1] * other->data[1 * 4 + 1]) + - (self->data[i * 4 + 2] * other->data[2 * 4 + 1]) + - (self->data[i * 4 + 3] * other->data[3 * 4 + 1]); - - m.data[i * 4 + 2] = (self->data[i * 4 + 0] * other->data[0 * 4 + 2]) + - (self->data[i * 4 + 1] * other->data[1 * 4 + 2]) + - (self->data[i * 4 + 2] * other->data[2 * 4 + 2]) + - (self->data[i * 4 + 3] * other->data[3 * 4 + 2]); - - m.data[i * 4 + 3] = (self->data[i * 4 + 0] * other->data[0 * 4 + 3]) + - (self->data[i * 4 + 1] * other->data[1 * 4 + 3]) + - (self->data[i * 4 + 2] * other->data[2 * 4 + 3]) + - (self->data[i * 4 + 3] * other->data[3 * 4 + 3]); - } - memcpy(self, &m, sizeof(mat4)); -} - -void mat4_set_orthographic(mat4 *self, float left, float right, float bottom, - float top, float znear, float zfar) -{ - if (!self) - return; - - if (left == right || bottom == top || znear == zfar) - return; - - mat4_set_zero(self); - - self->m00 = +2.0f / (right - left); - self->m30 = -(right + left) / (right - left); - self->m11 = +2.0f / (top - bottom); - self->m31 = -(top + bottom) / (top - bottom); - self->m22 = -2.0f / (zfar - znear); - self->m32 = -(zfar + znear) / (zfar - znear); - self->m33 = 1.0f; -} - -void mat4_set_perspective(mat4 *self, float fovy, float aspect, float znear, - float zfar) -{ - float h, w; - - if (!self) - return; - - if (znear == zfar) - return; - - h = (float) tan(fovy / 360.0 * M_PI) * znear; - w = h * aspect; - - mat4_set_frustum(self, -w, w, -h, h, znear, zfar); -} - -void mat4_set_frustum(mat4 *self, float left, float right, float bottom, - float top, float znear, float zfar) -{ - - if (!self) - return; - - if (left == right || bottom == top || znear == zfar) - return; - - mat4_set_zero(self); - - self->m00 = (2.0f * znear) / (right - left); - self->m20 = (right + left) / (right - left); - - self->m11 = (2.0f * znear) / (top - bottom); - self->m21 = (top + bottom) / (top - bottom); - - self->m22 = -(zfar + znear) / (zfar - znear); - self->m32 = -(2.0f * zfar * znear) / (zfar - znear); - - self->m23 = -1.0f; -} - -void mat4_set_rotation(mat4 *self, float angle, float x, float y, float z) -{ - float c, s, norm; - - if (!self) - return; - - c = (float) cos(M_PI * angle / 180.0); - s = (float) sin(M_PI * angle / 180.0); - norm = (float) sqrt(x * x + y * y + z * z); - - x /= norm; - y /= norm; - z /= norm; - - mat4_set_identity(self); - - self->m00 = x * x * (1 - c) + c; - self->m10 = y * x * (1 - c) - z * s; - self->m20 = z * x * (1 - c) + y * s; - - self->m01 = x * y * (1 - c) + z * s; - self->m11 = y * y * (1 - c) + c; - self->m21 = z * y * (1 - c) - x * s; - - self->m02 = x * z * (1 - c) - y * s; - self->m12 = y * z * (1 - c) + x * s; - self->m22 = z * z * (1 - c) + c; -} - -void mat4_set_translation(mat4 *self, float x, float y, float z) -{ - if (!self) - return; - - mat4_set_identity(self); - self->m30 = x; - self->m31 = y; - self->m32 = z; -} - -void mat4_set_scaling(mat4 *self, float x, float y, float z) -{ - if (!self) - return; - - mat4_set_identity(self); - self->m00 = x; - self->m11 = y; - self->m22 = z; -} - -void mat4_rotate(mat4 *self, float angle, float x, float y, float z) -{ - mat4 m; - - if (!self) - return; - - mat4_set_rotation(&m, angle, x, y, z); - mat4_multiply(self, &m); -} - -void mat4_translate(mat4 *self, float x, float y, float z) -{ - mat4 m; - - if (!self) - return; - - mat4_set_translation(&m, x, y, z); - mat4_multiply(self, &m); -} - -void mat4_scale(mat4 *self, float x, float y, float z) -{ - mat4 m; - - if (!self) - return; - - mat4_set_scaling(&m, x, y, z); - mat4_multiply(self, &m); -} diff --git a/ftgl/mat4.h b/ftgl/mat4.h deleted file mode 100644 index 6f0aa93..0000000 --- a/ftgl/mat4.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Freetype GL - A C OpenGL Freetype engine - * - * Distributed under the OSI-approved BSD 2-Clause License. See accompanying - * file `LICENSE` for more details. - */ -#ifndef __MAT4_H__ -#define __MAT4_H__ - -#ifdef __cplusplus -extern "C" { -namespace ftgl -{ -#endif - -/** - * - */ -typedef union { - float data[16]; /**< All compoments at once */ - struct - { - float m00, m01, m02, m03; - float m10, m11, m12, m13; - float m20, m21, m22, m23; - float m30, m31, m32, m33; - }; -} mat4; - -mat4 *mat4_new(void); - -void mat4_set_identity(mat4 *self); - -// mat4_set_zero(mat4 *self); - -//void mat4_multiply(mat4 *self, mat4 *other); - -void mat4_set_orthographic(mat4 *self, float left, float right, float bottom, - float top, float znear, float zfar); - -/*void mat4_set_perspective(mat4 *self, float fovy, float aspect, float zNear, - float zFar); */ - -void mat4_set_frustum(mat4 *self, float left, float right, float bottom, - float top, float znear, float zfar); - -//void mat4_set_rotation(mat4 *self, float angle, float x, float y, float z); - -//void mat4_set_translation(mat4 *self, float x, float y, float z); - -//void mat4_set_scaling(mat4 *self, float x, float y, float z); - -//void mat4_rotate(mat4 *self, float angle, float x, float y, float z); - -//void mat4_translate(mat4 *self, float x, float y, float z); - -//void mat4_scale(mat4 *self, float x, float y, float z); - -#ifdef __cplusplus -} -} -#endif - -#endif /* __MAT4_H__ */ diff --git a/src/glez.cpp b/src/glez.cpp index ad4c22c..728c947 100644 --- a/src/glez.cpp +++ b/src/glez.cpp @@ -10,7 +10,9 @@ #include #include #include -#include +#include +#include +#include #include #include @@ -103,10 +105,8 @@ vertex_buffer_t* buffer { nullptr }; void resize(int width, int height) { glUseProgram(shader); - mat4 projection; - mat4_set_identity(&projection); - mat4_set_orthographic(&projection, 0, width, height, 0, -1, 1); - glUniformMatrix4fv(glGetUniformLocation(shader, "projection"), 1, 0, projection.data); + auto projection = glm::ortho(0.0f, width, height, 0.0f, -1.0f, 1.0f); + glUniformMatrix4fv(glGetUniformLocation(shader, "projection"), 1, 0, glm::value_ptr(projection)); glUseProgram(0); }