Skip to content

Commit

Permalink
v1.5.0 - see patch notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jopo86 committed Jul 10, 2024
1 parent 6179655 commit 361a013
Show file tree
Hide file tree
Showing 24 changed files with 471 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.13)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

project(Onyx VERSION 1.4.1)
project(Onyx VERSION 1.5.0)

add_compile_options(-Wno-volatile -Wno-delete-incomplete)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Onyx is a high-level, cross-platform C++ rendering engine using OpenGL 4.1, with
The intuitive and well-structured codebase makes it simpler than ever to code games, apps, or any graphical interface using a language as complex as C++.

## Download
There is a pre-compiled binary compiled on my system (WSL x64), but it is recommended to compile yourself using CMake. See [Build](https://github.com/jopo86/onyx/wiki/Build) for detailed download/build instructions.
There is a pre-compiled binary compiled on my system (Windows x64), but it is recommended to compile yourself using CMake. See [Build](https://github.com/jopo86/onyx/wiki/Build) for detailed download/build instructions.

[Latest Release (1.4.1)](https://github.com/jopo86/onyx/releases/tag/v1.4.1)
[Latest Release (1.5.0)](https://github.com/jopo86/onyx/releases/tag/v1.5.0)
[All Releases](https://github.com/jopo86/onyx/releases)

## Get Started
Expand All @@ -28,3 +28,4 @@ There is also a [Guides](https://github.com/jopo86/onyx/wiki/guides) page, with
- Presets for Meshes, Shaders, and Renderables
- Monitor info
- Extensive Matrix & Vector Math
- Various system functions (clipboard access, key states, and more)
Binary file modified build/CMakeFiles/onyx.dir/src/Core.cpp.obj
Binary file not shown.
Binary file modified build/CMakeFiles/onyx.dir/src/InputHandler.cpp.obj
Binary file not shown.
Binary file modified build/CMakeFiles/onyx.dir/src/Window.cpp.obj
Binary file not shown.
Binary file modified build/CMakeFiles/test.dir/objects.a
Binary file not shown.
Binary file modified build/CMakeFiles/test.dir/tests/BouncingBallTest.cpp.obj
Binary file not shown.
Binary file modified build/CMakeFiles/test.dir/tests/PresetTests.cpp.obj
Binary file not shown.
Binary file modified build/CMakeFiles/test.dir/tests/WindowTest.cpp.obj
Binary file not shown.
Binary file modified build/libonyx.a
Binary file not shown.
Binary file modified build/test.exe
Binary file not shown.
Binary file modified resources/shaders/bin/PN_Color.bin
Binary file not shown.
Binary file modified resources/shaders/bin/PT_UI.bin
Binary file not shown.
Binary file modified resources/shaders/bin/P_UI_Color.bin
Binary file not shown.
Binary file modified resources/shaders/bin/UI_Text.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions src/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/

#define ONYX_VERSION_MAJOR 1
#define ONYX_VERSION_MINOR 4
#define ONYX_VERSION_PATCH 1
#define ONYX_VERSION_MINOR 5
#define ONYX_VERSION_PATCH 0

#define ONYX_PRE_RELEASE_NUM 0

Expand Down
42 changes: 41 additions & 1 deletion src/InputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ void onyx_warn(const Onyx::Warning&);
Onyx::InputHandler::InputHandler()
{
m_pWin = nullptr;
m_pKeyCallback = nullptr;
m_pMouseButtonCallback = nullptr;
m_pMousePosCallback = nullptr;
m_pScrollCallback = nullptr;
m_pJoystickCallback = nullptr;

for (int i = 0; i < (int)Onyx::Key::MaxKey; i++)
{
Expand Down Expand Up @@ -200,6 +205,31 @@ void Onyx::InputHandler::toggleCursorLock()
setCursorLock(!m_cursorLock);
}

void Onyx::InputHandler::setKeyCallback(KeyCallbackFn callback)
{
m_pKeyCallback = callback;
}

void Onyx::InputHandler::setMouseButtonCallback(MouseButtonCallbackFn callback)
{
m_pMouseButtonCallback = callback;
}

void Onyx::InputHandler::setMousePosCallback(MousePosCallbackFn callback)
{
m_pMousePosCallback = callback;
}

void Onyx::InputHandler::setScrollCallback(ScrollCallbackFn callback)
{
m_pScrollCallback = callback;
}

void Onyx::InputHandler::setJoystickCallback(JoystickCallbackFn callback)
{
m_pJoystickCallback = callback;
}

bool Onyx::InputHandler::isCursorLocked() const
{
return m_cursorLock;
Expand Down Expand Up @@ -331,29 +361,39 @@ void Onyx::InputHandler::keyCallback(int key, int scancode, int action, int mods
{
m_keys[key] = (Onyx::KeyState)action;
if (action == GLFW_PRESS) m_keysTapped[key] = true;

if (m_pKeyCallback) m_pKeyCallback(key, scancode, action, mods);
}

void Onyx::InputHandler::mouseButtonCallback(int button, int action, int mods)
{
m_buttons[button] = (Onyx::KeyState)action;
if (action == GLFW_PRESS) m_buttonsTapped[button] = true;

if (m_pMouseButtonCallback) m_pMouseButtonCallback(button, action, mods);
}

void Onyx::InputHandler::cursorPosCallback(double x, double y)
void Onyx::InputHandler::mousePosCallback(double x, double y)
{
m_mousePos.set(x, y);

if (m_pMousePosCallback) m_pMousePosCallback(x, y);
}

void Onyx::InputHandler::scrollCallback(double dx, double dy)
{
m_scrollDeltas.set(dx, dy);
m_scrollThisFrame = true;

if (m_pScrollCallback) m_pScrollCallback(dx, dy);
}

void Onyx::InputHandler::joystickCallback(int jid, int event)
{
if (!glfwJoystickIsGamepad(jid)) return;

if (m_pJoystickCallback != nullptr) m_pJoystickCallback(jid, event);

bool found = false;
for (Gamepad& gamepad : m_gamepads)
{
Expand Down
81 changes: 80 additions & 1 deletion src/InputHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,44 @@ namespace Onyx
{
friend class Window;

/*
@brief The key callback function signature.
@param key The GLFW key.
TODO: scancode param
@param action The GLFW action.
TODO: mods param
*/
typedef void(*KeyCallbackFn)(int key, int scancode, int action, int mods);

/*
@brief The mouse button callback function signature.
@param key The GLFW button.
@param action The GLFW action.
TODO: mods param
*/
typedef void(*MouseButtonCallbackFn)(int button, int action, int mods);

/*
@brief The mouse position callback function signature.
@param x The X position of the mouse as a window coordinate.
@param y The Y position of the mouse as a window coordinate.
*/
typedef void(*MousePosCallbackFn)(double x, double y);

/*
@brief The scroll callback function signature.
@param dx The change in scroll on the X axis.
@param dy The change in scroll on the Y axis (the only axis for mice).
*/
typedef void(*ScrollCallbackFn)(double dx, double dy);

/*
@brief The key callback function signature.
@param jid The GLFW joystick ID.
@param event The GLFW event.
*/
typedef void(*JoystickCallbackFn)(int jid, int event);

public:
/*
@brief Creates an InputHandler.
Expand Down Expand Up @@ -147,6 +185,41 @@ namespace Onyx
*/
void toggleCursorLock();

/*
@brief Sets the key callback function.
@param callback The callback function.
See definition of `KeyCallbackFn` for parameter info.
*/
void setKeyCallback(KeyCallbackFn callback);

/*
@brief Sets the mouse button callback function.
@param callback The callback function.
See definition of `MouseButtonCallbackFn` for parameter info.
*/
void setMouseButtonCallback(MouseButtonCallbackFn callback);

/*
@brief Sets the mouse position callback function.
@param callback The callback function.
See definition of `MousePosCallbackFn` for parameter info.
*/
void setMousePosCallback(MousePosCallbackFn callback);

/*
@brief Sets the scroll callback function.
@param callback The callback function.
See definition of `ScrollCallbackFn` for parameter info.
*/
void setScrollCallback(ScrollCallbackFn callback);

/*
@brief Sets the joystick callback function.
@param callback The callback function.
See definition of `JoystickCallbackFn` for parameter info.
*/
void setJoystickCallback(JoystickCallbackFn callback);

/*
@brief Gets whether the cursor is locked.
@return Whether the cursor is locked.
Expand Down Expand Up @@ -231,9 +304,15 @@ namespace Onyx

bool m_cursorLock;

KeyCallbackFn m_pKeyCallback;
MouseButtonCallbackFn m_pMouseButtonCallback;
MousePosCallbackFn m_pMousePosCallback;
ScrollCallbackFn m_pScrollCallback;
JoystickCallbackFn m_pJoystickCallback;

void keyCallback(int key, int scancode, int action, int mods);
void mouseButtonCallback(int button, int action, int mods);
void cursorPosCallback(double x, double y);
void mousePosCallback(double x, double y);
void scrollCallback(double dx, double dy);
void joystickCallback(int jid, int event);
};
Expand Down
109 changes: 107 additions & 2 deletions src/TextRenderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Onyx::TextRenderable::TextRenderable()
m_scale = Vec2(1.0f);
}

Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 color, bool* result)
Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, const Vec3& color, bool* result)
{
m_pFont = &font;
m_hidden = false;
Expand Down Expand Up @@ -65,7 +65,7 @@ Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 c
if (result != nullptr) *result = true;
}

Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec4 color, bool* result)
Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, const Vec4& color, bool* result)
{
m_pFont = &font;
m_hidden = false;
Expand Down Expand Up @@ -122,6 +122,111 @@ Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec4 c
if (result != nullptr) *result = true;
}

Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, const Vec3& color, Shader shaderOverride, bool* result)
{
m_pFont = &font;
m_hidden = false;
m_text = text;
m_color = Vec4(color, 1.0f);
m_model = Mat4::Identity();
m_z = 0.0f;
m_rotation = 0.0f;
m_scale = Vec2(1.0f);
m_dimensions = font.getStringDimensions(text);

if (font.getGlyphs().size() == 0)
{
onyx_err(Error{
.sourceFunction = "Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 color)",
.message = "Font has no glyphs loaded.",
.howToFix = "Load a font from a TTF file before creating a TextRenderable with it."
}
);
if (result != nullptr) *result = false;
return;
}
if (text == "")
{
onyx_warn(Warning{
.sourceFunction = "Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 color)",
.message = "Text is empty.",
.howToFix = "Provide a non-empty string to render.",
.severity = Warning::Severity::Low
}
);
}

uint advance = 0;
for (int i = 0; i < text.size(); i++)
{
m_chars.push_back(CharRenderable(text[i], font, advance));
advance += font[text[i]].advance >> 6;
}

m_shader = shaderOverride;
m_shader.use();
m_shader.setVec4("u_color", m_color);

if (result != nullptr) *result = true;
}

Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, const Vec4& color, Shader shaderOverride, bool* result)
{
m_pFont = &font;
m_hidden = false;
m_text = text;
m_color = color;
m_model = Mat4::Identity();
m_rotation = 0.0f;
m_scale = Vec2(1.0f);
m_dimensions = font.getStringDimensions(text);

if (font.getGlyphs().size() == 0)
{
onyx_err(Error{
.sourceFunction = "Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 color)",
.message = "Font has no glyphs loaded.",
.howToFix = "Load a font from a TTF file before creating a TextRenderable with it."
}
);
if (result != nullptr) *result = false;
return;
}
if (text == "")
{
onyx_warn(Warning{
.sourceFunction = "Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec3 color)",
.message = "Text is empty.",
.howToFix = "Provide a non-empty string to render.",
.severity = Warning::Severity::Low
}
);
}
if (color.getW() == 0.0f)
{
onyx_warn(Warning{
.sourceFunction = "Onyx::TextRenderable::TextRenderable(const std::string& text, Font& font, Vec4 color)",
.message = "Alpha value of text color is 0, text will not be visible.",
.howToFix = "Change the alpha value to be between 0 and 1, reflecting the text's opacity.",
.severity = Warning::Severity::Low
}
);
}

uint advance = 0;
for (int i = 0; i < text.size(); i++)
{
m_chars.push_back(CharRenderable(text[i], font, advance));
advance += font[text[i]].advance >> 6;
}

m_shader = shaderOverride;
m_shader.use();
m_shader.setVec4("u_color", color);

if (result != nullptr) *result = true;
}

void Onyx::TextRenderable::render()
{
if (m_hidden) return;
Expand Down
24 changes: 22 additions & 2 deletions src/TextRenderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace Onyx
@param color The color of the text.
@param result A pointer to a boolean that will be set to true if the object was created successfully, and false otherwise.
*/
TextRenderable(const std::string& text, Font& font, Math::Vec3 color, bool* result = nullptr);
TextRenderable(const std::string& text, Font& font, const Math::Vec3& color, bool* result = nullptr);

/*
@brief Creates a TextRenderable from the specified text, font, and color.
Expand All @@ -36,7 +36,27 @@ namespace Onyx
@param color The color of the text.
@param result A pointer to a boolean that will be set to true if the object was created successfully, and false otherwise.
*/
TextRenderable(const std::string& text, Font& font, Math::Vec4 color, bool* result = nullptr);
TextRenderable(const std::string& text, Font& font, const Math::Vec4& color, bool* result = nullptr);

/*
@brief Creates a TextRenderable from the specified text, font, and color.
@param text The text to render.
@param font The font to use.
@param color The color of the text.
@param shaderOverride The shader to use instead of the defaut text shader.
@param result A pointer to a boolean that will be set to true if the object was created successfully, and false otherwise.
*/
TextRenderable(const std::string& text, Font& font, const Math::Vec3& color, Shader shaderOverride, bool* result = nullptr);

/*
@brief Creates a TextRenderable from the specified text, font, and color.
@param text The text to render.
@param font The font to use.
@param color The color of the text.
@param shaderOverride The shader to use instead of the defaut text shader.
@param result A pointer to a boolean that will be set to true if the object was created successfully, and false otherwise.
*/
TextRenderable(const std::string& text, Font& font, const Math::Vec4& color, Shader shaderOverride, bool* result = nullptr);

/*
@brief Renders the object.
Expand Down
Loading

0 comments on commit 361a013

Please sign in to comment.