working on loader

main
Brett 2024-01-02 17:10:29 -05:00
parent 8b7dd47b53
commit fb29f1f513
5 changed files with 75 additions and 11 deletions

View File

@ -0,0 +1,38 @@
/*
* <Short Description>
* 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 <https://www.gnu.org/licenses/>.
*/
#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

View File

@ -30,14 +30,14 @@
namespace blt::gfx namespace blt::gfx
{ {
struct rectangle_t struct rectangle2d_t
{ {
float x, y, width, height, rotation = 0; 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; vertex_array* square_vao = nullptr;
shader_t* shader = nullptr; shader_t* shader = nullptr;
resource_manager& resources; resource_manager& resources;
HASHMAP<std::string, HASHMAP<blt::vec4, HASHMAP<blt::vec4, std::vector<rectangle_t>, vec_hash>, vec_hash>> complex_rectangles; HASHMAP<std::string, HASHMAP<blt::vec4, HASHMAP<blt::vec4, std::vector<rectangle2d_t>, vec_hash>, vec_hash>> complex_rectangles;
size_t draw_count_ = 0; size_t draw_count_ = 0;
public: public:
explicit batch_renderer_2d(resource_manager& resources): resources(resources) explicit batch_renderer_2d(resource_manager& resources): resources(resources)
@ -76,20 +76,20 @@ namespace blt::gfx
void create(); 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 empty{0, 0, 0, 0};
const static blt::vec4 full{1, 1, 1, 1}; const static blt::vec4 full{1, 1, 1, 1};
complex_rectangles[texture][empty][full].push_back(rectangle); 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}; const static blt::vec4 empty{0, 0, 0, 0};
complex_rectangles[""][color][empty].push_back(rectangle); 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); complex_rectangles[draw_info.texture_name][draw_info.color][draw_info.blend].push_back(rectangle);
} }

View File

@ -88,6 +88,7 @@ namespace blt::gfx
bool isKeyPressed(int key); bool isKeyPressed(int key);
// TODO: maybe make this per key?
bool keyPressedLastFrame(); bool keyPressedLastFrame();
double getFrameDeltaSeconds(); double getFrameDeltaSeconds();

View File

@ -0,0 +1,18 @@
/*
* <Short Description>
* 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 <https://www.gnu.org/licenses/>.
*/
#include <blt/gfx/loader/obj_loader.h>

View File

@ -25,7 +25,13 @@ void blt::gfx::first_person_camera::update()
float speed_multi = 1; 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)) if (isKeyPressed(GLFW_KEY_LEFT_CONTROL))
speed_multi = 10; speed_multi = 10;
@ -63,7 +69,8 @@ void blt::gfx::first_person_camera::update()
// TODO; // TODO;
const float sensitivity = 10; const float sensitivity = 10;
if (mouseMovedLastFrame() && isCursorLocked()) { if (mouseMovedLastFrame() && isCursorLocked())
{
auto dYaw = getMouseDX() * sensitivity * getFrameDeltaSeconds(); auto dYaw = getMouseDX() * sensitivity * getFrameDeltaSeconds();
auto dPitch = getMouseDY() * sensitivity * getFrameDeltaSeconds(); auto dPitch = getMouseDY() * sensitivity * getFrameDeltaSeconds();