diff --git a/include/blt/gfx/loader/obj_loader.h b/include/blt/gfx/loader/obj_loader.h new file mode 100644 index 0000000..ab63d00 --- /dev/null +++ b/include/blt/gfx/loader/obj_loader.h @@ -0,0 +1,38 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef BLT_WITH_GRAPHICS_OBJ_LOADER_H +#define BLT_WITH_GRAPHICS_OBJ_LOADER_H + +#include "blt/math/vectors.h" + +namespace blt::gfx +{ + + typedef blt::vec4 vertex_t; + typedef blt::vec3 uv_t; + typedef blt::vec3 normal_t; + + struct face_t + { + std::int32_t vertex, uv, normal; + }; + +} + +#endif //BLT_WITH_GRAPHICS_OBJ_LOADER_H diff --git a/include/blt/gfx/renderer/batch_2d_renderer.h b/include/blt/gfx/renderer/batch_2d_renderer.h index 6ee9ce9..2e72f29 100644 --- a/include/blt/gfx/renderer/batch_2d_renderer.h +++ b/include/blt/gfx/renderer/batch_2d_renderer.h @@ -30,14 +30,14 @@ namespace blt::gfx { - struct rectangle_t + struct rectangle2d_t { float x, y, width, height, rotation = 0; - rectangle_t(float x, float y, float width, float height, float rotation): x(x), y(y), width(width), height(height), rotation(rotation) + rectangle2d_t(float x, float y, float width, float height, float rotation): x(x), y(y), width(width), height(height), rotation(rotation) {} - rectangle_t(float x, float y, float width, float height): x(x), y(y), width(width), height(height) + rectangle2d_t(float x, float y, float width, float height): x(x), y(y), width(width), height(height) {} }; @@ -68,7 +68,7 @@ namespace blt::gfx vertex_array* square_vao = nullptr; shader_t* shader = nullptr; resource_manager& resources; - HASHMAP, vec_hash>, vec_hash>> complex_rectangles; + HASHMAP, vec_hash>, vec_hash>> complex_rectangles; size_t draw_count_ = 0; public: explicit batch_renderer_2d(resource_manager& resources): resources(resources) @@ -76,20 +76,20 @@ namespace blt::gfx void create(); - inline void drawRectangle(std::string_view texture, const rectangle_t& rectangle) + inline void drawRectangle(std::string_view texture, const rectangle2d_t& rectangle) { const static blt::vec4 empty{0, 0, 0, 0}; const static blt::vec4 full{1, 1, 1, 1}; complex_rectangles[texture][empty][full].push_back(rectangle); } - inline void drawRectangle(const blt::vec4& color, const rectangle_t& rectangle) + inline void drawRectangle(const blt::vec4& color, const rectangle2d_t& rectangle) { const static blt::vec4 empty{0, 0, 0, 0}; complex_rectangles[""][color][empty].push_back(rectangle); } - inline void drawRectangle(const draw_state& draw_info, const rectangle_t& rectangle) + inline void drawRectangle(const draw_state& draw_info, const rectangle2d_t& rectangle) { complex_rectangles[draw_info.texture_name][draw_info.color][draw_info.blend].push_back(rectangle); } diff --git a/include/blt/gfx/window.h b/include/blt/gfx/window.h index cfdf6c7..f56efac 100644 --- a/include/blt/gfx/window.h +++ b/include/blt/gfx/window.h @@ -88,6 +88,7 @@ namespace blt::gfx bool isKeyPressed(int key); + // TODO: maybe make this per key? bool keyPressedLastFrame(); double getFrameDeltaSeconds(); diff --git a/src/blt/gfx/loader/obj_loader.cpp b/src/blt/gfx/loader/obj_loader.cpp new file mode 100644 index 0000000..a25db51 --- /dev/null +++ b/src/blt/gfx/loader/obj_loader.cpp @@ -0,0 +1,18 @@ +/* + * + * Copyright (C) 2024 Brett Terpstra + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include \ No newline at end of file diff --git a/src/blt/gfx/renderer/camera.cpp b/src/blt/gfx/renderer/camera.cpp index 5ee4074..095b441 100644 --- a/src/blt/gfx/renderer/camera.cpp +++ b/src/blt/gfx/renderer/camera.cpp @@ -25,7 +25,13 @@ void blt::gfx::first_person_camera::update() float speed_multi = 1; - if (isKeyPressed(GLFW_KEY_ESCAPE) && ) + if (isKeyPressed(GLFW_KEY_ESCAPE) && keyPressedLastFrame()) + { + if (isCursorLocked()) + unlockCursor(); + else + lockCursor(); + } if (isKeyPressed(GLFW_KEY_LEFT_CONTROL)) speed_multi = 10; @@ -63,7 +69,8 @@ void blt::gfx::first_person_camera::update() // TODO; const float sensitivity = 10; - if (mouseMovedLastFrame() && isCursorLocked()) { + if (mouseMovedLastFrame() && isCursorLocked()) + { auto dYaw = getMouseDX() * sensitivity * getFrameDeltaSeconds(); auto dPitch = getMouseDY() * sensitivity * getFrameDeltaSeconds(); @@ -82,9 +89,9 @@ void blt::gfx::first_person_camera::update() if (isKeyPressed(GLFW_KEY_DOWN)) rotation_[0] += static_cast(sSpeed * getFrameDeltaSeconds() * vertFact); - if(rotation_[0] > 89.0f) + if (rotation_[0] > 89.0f) rotation_[0] = 89.0f; - if(rotation_[0] < -89.0f) + if (rotation_[0] < -89.0f) rotation_[0] = -89.0f; if (rotation_[1] < 0)