Ortho re-added
This commit is contained in:
14
cmake/modules/Findcglm.cmake
Normal file
14
cmake/modules/Findcglm.cmake
Normal file
@@ -0,0 +1,14 @@
|
||||
# Copyright (c) 2025 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
include(FetchContent)
|
||||
FetchContent_Declare(
|
||||
cglm
|
||||
GIT_REPOSITORY https://github.com/recp/cglm.git
|
||||
GIT_TAG v0.9.6
|
||||
)
|
||||
|
||||
FetchContent_MakeAvailable(cglm)
|
||||
set(cglm_FOUND ON)
|
@@ -12,12 +12,14 @@ target_compile_definitions(${DUSK_TARGET_NAME}
|
||||
# Libs
|
||||
find_package(SDL2 REQUIRED)
|
||||
find_package(OpenGL REQUIRED)
|
||||
find_package(cglm REQUIRED)
|
||||
|
||||
target_link_libraries(${DUSK_TARGET_NAME}
|
||||
PUBLIC
|
||||
SDL2::SDL2
|
||||
OpenGL::GL
|
||||
GL
|
||||
cglm
|
||||
)
|
||||
|
||||
|
||||
|
@@ -12,13 +12,19 @@
|
||||
|
||||
void cameraUIPush(void) {
|
||||
glPushMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
glViewport(0, 0, RENDER_WIDTH, RENDER_HEIGHT);
|
||||
glOrtho(
|
||||
0.0f, (float_t)RENDER_WIDTH,
|
||||
(float_t)RENDER_HEIGHT, 0.0f,
|
||||
-1.0f, 1.0f
|
||||
);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void cameraUIPop(void) {
|
||||
@@ -27,6 +33,8 @@ void cameraUIPop(void) {
|
||||
|
||||
void cameraScreenPush(void) {
|
||||
glPushMatrix();
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
#if RENDER_USE_FRAMEBUFFER
|
||||
@@ -46,6 +54,9 @@ void cameraScreenPush(void) {
|
||||
-1.0f, 1.0f
|
||||
);
|
||||
#endif
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
}
|
||||
|
||||
void cameraScreenPop(void) {
|
||||
@@ -56,17 +67,58 @@ void cameraOverworldPush(void) {
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glViewport(0, 0, RENDER_WIDTH, RENDER_HEIGHT);
|
||||
glOrtho(
|
||||
0.0f, (float_t)RENDER_WIDTH,
|
||||
(float_t)RENDER_HEIGHT, 0.0f,
|
||||
-1.0f, 1.0f
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
const float_t fov = glm_rad(75.0f);
|
||||
const float_t camOffset = 12.0f;
|
||||
const float_t aspect = (float_t)RENDER_WIDTH / (float_t)RENDER_HEIGHT;
|
||||
const float_t pixelPerfectOffset = (
|
||||
tanf((glm_rad(180) - fov) / 2.0f) *
|
||||
((float_t)RENDER_HEIGHT/ 2.0f)
|
||||
);
|
||||
|
||||
glTranslatef(
|
||||
-((float_t)OVERWORLD_CAMERA_X) + ((float_t)RENDER_WIDTH / 2.0f),
|
||||
-((float_t)OVERWORLD_CAMERA_Y) + ((float_t)RENDER_HEIGHT / 2.0f),
|
||||
vec3 look = {
|
||||
OVERWORLD_CAMERA_X,
|
||||
OVERWORLD_CAMERA_Y,
|
||||
0.0f
|
||||
);
|
||||
};
|
||||
vec3 eye = {
|
||||
look[0],
|
||||
look[1] + camOffset,
|
||||
look[2] + pixelPerfectOffset
|
||||
};
|
||||
vec3 up = { 0.0f, 1.0f, 0.0f };
|
||||
|
||||
mat4 proj;
|
||||
glm_perspective(fov, aspect, 0.1f, 1000.0f, proj);
|
||||
|
||||
// Flips rendering on the Y axis, so that it is still right-down even in 3D;
|
||||
proj[1][1] = -proj[1][1];
|
||||
|
||||
mat4 view;
|
||||
glm_lookat(eye, look, up, view);
|
||||
|
||||
mat4 pv;
|
||||
glm_mat4_mul(proj, view, pv);
|
||||
|
||||
glLoadMatrixf((const GLfloat*)pv);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
// glOrtho(
|
||||
// 0.0f, (float_t)RENDER_WIDTH,
|
||||
// (float_t)RENDER_HEIGHT, 0.0f,
|
||||
// -1.0f, 1.0f
|
||||
// );
|
||||
|
||||
// glTranslatef(
|
||||
// -((float_t)OVERWORLD_CAMERA_X) + ((float_t)RENDER_WIDTH / 2.0f),
|
||||
// -((float_t)OVERWORLD_CAMERA_Y) + ((float_t)RENDER_HEIGHT / 2.0f),
|
||||
// 0.0f
|
||||
// );
|
||||
}
|
||||
|
||||
void cameraOverworldPop(void) {
|
||||
|
@@ -12,3 +12,5 @@
|
||||
#define GL_GLEXT_PROTOTYPES
|
||||
#include <GL/gl.h>
|
||||
#include <GL/glext.h>
|
||||
|
||||
#include <cglm/cglm.h>
|
Reference in New Issue
Block a user