From 8fab8e60148ab3fac4168444f1420303f43b5d5d Mon Sep 17 00:00:00 2001 From: EPICGameGuy Date: Fri, 29 Dec 2023 16:12:43 -0500 Subject: [PATCH] Working on text support --- include/input/keyboard.hpp | 2 +- include/renderer/text.hpp | 2 +- src/input/keyboard.cpp | 9 ++++++--- src/objects/movement.cc | 12 ++++++++++++ src/renderer/gs.cc | 9 +++++---- src/renderer/text.cc | 2 +- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/include/input/keyboard.hpp b/include/input/keyboard.hpp index 9f1b129..9eb667e 100644 --- a/include/input/keyboard.hpp +++ b/include/input/keyboard.hpp @@ -7,5 +7,5 @@ namespace Input::Keyboard { void init(); void read_inputs(); -u8 get_key_status(char key); +u8 get_key_status(unsigned char key); } // namespace Input::Keyboard \ No newline at end of file diff --git a/include/renderer/text.hpp b/include/renderer/text.hpp index a915469..93b8b5b 100644 --- a/include/renderer/text.hpp +++ b/include/renderer/text.hpp @@ -1,6 +1,6 @@ #pragma once -void tsShowFont(const char* text); +void tsShowFont(); void tsResetCursor(); void tsDrawString(const char* text); void tsLoadFont(); \ No newline at end of file diff --git a/src/input/keyboard.cpp b/src/input/keyboard.cpp index 62e9067..bf0e6db 100644 --- a/src/input/keyboard.cpp +++ b/src/input/keyboard.cpp @@ -36,14 +36,17 @@ void Keyboard::read_inputs() PS2KbdRawKey key; while (PS2KbdReadRaw(&key) != 0) { - printf("New key: %u, %u\n", key.key, key.state); + unsigned char c = (key.key + 'a') - 4; + //printf("New key: %u, %u, (%u, %c)\n", key.key, key.state, c, c); keyboard_status[key.key] = key.state & 0xF; } } -u8 Keyboard::get_key_status(char key) +u8 Keyboard::get_key_status(unsigned char key) { - return keyboard_status[(key - 'a') + 4]; + const unsigned char actual_key = (key - 'a') + 4; + //check(actual_key >= 0 && actual_key <= 255); + return keyboard_status[actual_key]; } } // namespace Input \ No newline at end of file diff --git a/src/objects/movement.cc b/src/objects/movement.cc index ef4417e..a886fec 100644 --- a/src/objects/movement.cc +++ b/src/objects/movement.cc @@ -141,6 +141,18 @@ void ThirdPersonMovement::calculate_rotation_input(float delta_time) input_vector.yaw = (buttons.rjoy_h - 128.f) / 128.f; input_vector.pitch = (buttons.rjoy_v - 128.f) / 128.f; + // Left arrow + input_vector.yaw += Input::Keyboard::get_key_status(173) * -1; + + // Right arrow + input_vector.yaw += Input::Keyboard::get_key_status(172); + + // Up arrow + input_vector.pitch += Input::Keyboard::get_key_status(175); + + // Down arrow + input_vector.pitch += Input::Keyboard::get_key_status(174) * -1; + const float input_length = input_vector.length(); if (input_length > dead_zone) { diff --git a/src/renderer/gs.cc b/src/renderer/gs.cc index 8f92504..a290ec9 100644 --- a/src/renderer/gs.cc +++ b/src/renderer/gs.cc @@ -255,10 +255,11 @@ static int gs_render() glDisable(GL_ALPHA_TEST); glEnable(GL_TEXTURE_2D); glLoadIdentity(); - tsDrawString("Helllo!"); - tsDrawString("Helllo!"); - tsDrawString("Helllo!"); - tsDrawString("Helllo!"); + tsShowFont(); + tsDrawString("Hi mac!\n"); + // tsDrawString("Helllo!\n"); + // tsDrawString("Helllo!\n"); + // tsDrawString("Helllo!\n"); glDisable(GL_TEXTURE_2D); } diff --git a/src/renderer/text.cc b/src/renderer/text.cc index c53e623..02c77da 100644 --- a/src/renderer/text.cc +++ b/src/renderer/text.cc @@ -23,7 +23,7 @@ unsigned int* font_clut; float left_margin = 20, top_margin = 20; float cursor_x = left_margin, cursor_y = top_margin; -void tsShowFont(const char* text) +void tsShowFont() { glMatrixMode(GL_MODELVIEW); glPushMatrix();