Skip to content

Commit

Permalink
v0.8.2-beta - see patch notes
Browse files Browse the repository at this point in the history
  • Loading branch information
jopo86 committed Apr 19, 2024
1 parent 3ba2528 commit 54a96c5
Show file tree
Hide file tree
Showing 17 changed files with 418 additions and 42 deletions.
8 changes: 4 additions & 4 deletions Onyx/Onyx.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
Expand Down
Binary file added Onyx/resources/textures/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions Onyx/src/CharRenderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ Onyx::CharRenderable::CharRenderable(char c, const Font& font, uint advance)

glBindVertexArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

#if defined(ONYX_GL_DEBUG_LOW) || defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::CharRenderable::render()
Expand All @@ -53,6 +57,10 @@ void Onyx::CharRenderable::render()
glBindVertexArray(vao);
glDrawArrays(GL_TRIANGLES, 0, 6);
glBindVertexArray(0);

#if defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

char Onyx::CharRenderable::getChar() const
Expand Down Expand Up @@ -80,4 +88,8 @@ void Onyx::CharRenderable::dispose()
if (vao) glDeleteVertexArrays(1, &vao);
if (vbo) glDeleteBuffers(1, &vbo);
vao = vbo = tex = 0;

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}
32 changes: 32 additions & 0 deletions Onyx/src/Core.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning(disable : 4244; disable: 4267)


#include "Core.h"

#include <string>
Expand All @@ -20,6 +21,30 @@ FT_Library ft;
void* p_user;
std::vector<std::pair<void*, bool>> mallocs;

const char* _glErrorToString(uint errorCode)
{
switch (errorCode)
{
case GL_INVALID_ENUM: return "INVALID_ENUM";
case GL_INVALID_VALUE: return "INVALID_VALUE";
case GL_INVALID_OPERATION: return "INVALID_OPERATION";
case GL_STACK_OVERFLOW: return "STACK_OVERFLOW";
case GL_STACK_UNDERFLOW: return "STACK_UNDERFLOW";
case GL_OUT_OF_MEMORY: return "OUT_OF_MEMORY";
case GL_INVALID_FRAMEBUFFER_OPERATION: return "INVALID_FRAMEBUFFER_OPERATION";
}
}

uint _glCheckError(const std::string& file, int line)
{
uint errorCode;
while ((errorCode = glGetError()) != GL_NO_ERROR)
{
std::cout << "[OpenGL Error] " << glErrorToString(errorCode) << " | " << file.substr(file.find_last_of("\\") + 1) << " (" << line << ")\n";
}
return errorCode;
}

void setOpenGLInitialized(bool val)
{
glInitialized = val;
Expand Down Expand Up @@ -122,6 +147,9 @@ void Onyx::Demo()
window.init();
window.setBackgroundColor(Vec3(0.0f, 0.7f, 1.0f));

WindowIcon icon = WindowIcon::Load(Onyx::Resources("textures/icon.png"));
window.setIcon(icon);

InputHandler input(window);

float bgVertices[] = {
Expand Down Expand Up @@ -325,6 +353,10 @@ std::string Onyx::GetGraphics()
{
if (!glInitialized) Err("OpenGL must be initialized before calling GetGraphics(). Initialize a window.");
return (const char*)glGetString(GL_RENDERER);

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::AddMalloc(void* ptr, bool array)
Expand Down
12 changes: 11 additions & 1 deletion Onyx/src/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@

#define ONYX_VERSION_MAJOR 0
#define ONYX_VERSION_MINOR 8
#define ONYX_VERSION_PATCH 1
#define ONYX_VERSION_PATCH 2
#define ONYX_BETA true

//#define ONYX_GL_DEBUG_LOW
//#define ONYX_GL_DEBUG_MED
//#define ONYX_GL_DEBUG_HIGH

/*
Definitions for system info.
*/
Expand Down Expand Up @@ -55,6 +59,12 @@ typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ulonglong;

const char* _glErrorToString(uint errorCode);
uint _glCheckError(const std::string& file, int line);

#define glErrorToString(uint) _glErrorToString(uint)
#define glCheckError() _glCheckError(__FILE__, __LINE__)

/*
@brief A namespace for global Onyx functions/settings.
*/
Expand Down
13 changes: 11 additions & 2 deletions Onyx/src/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ Onyx::Font Onyx::Font::Load(const std::string& ttfFilePath, uint size)

glBindTexture(GL_TEXTURE_2D, 0);

#if defined(ONYX_GL_DEBUG_LOW) || defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif

return font;
}

Expand Down Expand Up @@ -102,8 +106,13 @@ void Onyx::Font::dispose()
{
for (const std::pair<char, Glyph>& g : glyphs)
{
if (g.second.tex) glDeleteTextures(1, &g.second.tex);
}
if (g.second.tex) glDeleteTextures(1, &g.second.tex);
}

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif

glyphs.clear();
FT_Done_Face(face);
p_ft = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Onyx/src/InputHandler.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma warning(disable : 4244)
#pragma warning(disable : 4244; disable: 33011)

#include "InputHandler.h"

Expand Down
12 changes: 12 additions & 0 deletions Onyx/src/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ Onyx::Mesh::Mesh(VertexBuffer vertexBuffer, IndexBuffer indexBuffer)

if (vertexBuffer.heap) delete[] vertexBuffer.vertices;
if (indexBuffer.heap) delete[] indexBuffer.indices;

#if defined(ONYX_GL_DEBUG_LOW) || defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

Onyx::Mesh::Mesh(const Mesh& other)
Expand All @@ -129,6 +133,10 @@ void Onyx::Mesh::render() const
glBindVertexArray(vao);
glDrawElements(GL_TRIANGLES, indicesSize / sizeof(uint), GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);

#if defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

uint Onyx::Mesh::getVerticesSize() const
Expand Down Expand Up @@ -162,6 +170,10 @@ void Onyx::Mesh::dispose()
if (vbo) glDeleteBuffers(1, &vbo);
if (ibo) glDeleteBuffers(1, &ibo);
vao = vbo = ibo = 0;

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

Onyx::Mesh Onyx::Mesh::Triangle(float side)
Expand Down
66 changes: 37 additions & 29 deletions Onyx/src/Renderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ void Onyx::Renderable::render()
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);

#if defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::Renderable::render(const Mat4& view, const Mat4& proj)
Expand All @@ -67,6 +71,10 @@ void Onyx::Renderable::render(const Mat4& view, const Mat4& proj)
glBindVertexArray(0);
glBindTexture(GL_TEXTURE_2D, 0);
glUseProgram(0);

#if defined(ONYX_GL_DEBUG_MED) || defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::Renderable::hide()
Expand Down Expand Up @@ -444,35 +452,35 @@ Onyx::Renderable Onyx::Renderable::ColoredCube(float side, Vec4 rgba)
Onyx::Renderable Onyx::Renderable::TexturedCube(float side, Texture texture)
{
float* vertices = new float[192] {
-side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,

-side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-side / 2.0f, -side / 2.0f, side / 2.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, -side / 2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,

side / 2.0f, -side / 2.0f, -side / 2.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
-side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, -side / 2.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, -side / 2.0f, side / 2.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f,

-side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f,

-side / 2.0f, -side / 2.0f, -side / 2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
-side / 2.0f, -side / 2.0f, side / 2.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
-side / 2.0f, side / 2.0f, side / 2.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
-side / 2.0f, side / 2.0f, -side / 2.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f,

side / 2.0f, -side / 2.0f, -side / 2.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f,
side / 2.0f, -side / 2.0f, side / 2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f,
side / 2.0f, side / 2.0f, side / 2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f,
side / 2.0f, side / 2.0f, -side / 2.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f,
};

uint* indices = new uint[36]{
Expand Down
14 changes: 13 additions & 1 deletion Onyx/src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ void Onyx::Renderer::render()
SetWireframe(_wireframe);
}
glEnable(GL_DEPTH_TEST);

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::Renderer::add(Renderable& renderable)
Expand Down Expand Up @@ -93,7 +97,7 @@ void Onyx::Renderer::add(UiRenderable& uiRenderable)

void Onyx::Renderer::add(TextRenderable& textRenderable)
{
textRenderables.push_back(&textRenderable);
textRenderables.push_back(&textRenderable);
}

bool Onyx::Renderer::isLightingEnabled() const
Expand Down Expand Up @@ -162,6 +166,10 @@ void Onyx::Renderer::SetWireframe(bool _wireframe)

wireframe = _wireframe;
glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL);

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

void Onyx::Renderer::SetUiWireframeAllowed(bool allowed)
Expand Down Expand Up @@ -193,6 +201,10 @@ void Onyx::Renderer::SetLineWidth(float width)
{
glLineWidth(width);
lineWidth = width;

#if defined(ONYX_GL_DEBUG_HIGH)
glCheckError();
#endif
}

float Onyx::Renderer::GetLineWidth()
Expand Down
Loading

0 comments on commit 54a96c5

Please sign in to comment.