Skip to content

Commit

Permalink
v0.8.0-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 b06c7f2 commit d664fb0
Show file tree
Hide file tree
Showing 15 changed files with 760 additions and 310 deletions.
10 changes: 4 additions & 6 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>Application</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
Expand Down Expand Up @@ -185,7 +185,6 @@
<ClCompile Include="src\Window.cpp" />
<ClCompile Include="tests\PresetTests.cpp" />
<ClCompile Include="tests\Result.cpp" />
<ClCompile Include="tests\UnitTests.cpp" />
<ClCompile Include="src\TextRenderable.cpp" />
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -214,7 +213,6 @@
<ClInclude Include="src\Window.h" />
<ClInclude Include="tests\PresetTests.h" />
<ClInclude Include="tests\Result.h" />
<ClInclude Include="tests\UnitTests.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
19 changes: 13 additions & 6 deletions Onyx/src/CharRenderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,13 @@

Onyx::CharRenderable::CharRenderable()
{
c = 0;
vao = vbo = tex = 0;
}

Onyx::CharRenderable::CharRenderable(char c, const Font& font, uint advance)
{
glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);

glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

this->c = c;
Glyph glyph = font[c];
tex = glyph.tex;

Expand All @@ -35,6 +31,12 @@ Onyx::CharRenderable::CharRenderable(char c, const Font& font, uint advance)
{ x + w, y + h, 1.0f, 0.0f }
};

glGenVertexArrays(1, &vao);
glGenBuffers(1, &vbo);

glBindVertexArray(vao);
glBindBuffer(GL_ARRAY_BUFFER, vbo);

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(float), (void*)0);
Expand All @@ -52,6 +54,11 @@ void Onyx::CharRenderable::render()
glBindVertexArray(0);
}

char Onyx::CharRenderable::getChar() const
{
return c;
}

uint Onyx::CharRenderable::getVAO() const
{
return vao;
Expand Down
7 changes: 7 additions & 0 deletions Onyx/src/CharRenderable.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ namespace Onyx
*/
void render();

/*
@brief Gets the character.
@return The character.
*/
char getChar() const;

/*
@brief Gets the character mesh's VAO.
@return The VAO.
Expand All @@ -57,6 +63,7 @@ namespace Onyx
void dispose() override;

private:
char c;
uint vao, vbo, tex;
};
}
45 changes: 35 additions & 10 deletions Onyx/src/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ void Onyx::Init()
FT_Init_FreeType(&ft);

glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef ONYX_OS_MAC
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
#endif
}

void Onyx::Init(ErrorHandler& errorHandler)
Expand All @@ -54,6 +60,12 @@ void Onyx::Init(ErrorHandler& errorHandler)
{
Err("failed to initialize GLFW.");
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#ifdef ONYX_OS_MAC
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
#endif
}

int Onyx::GetVersionMajor()
Expand Down Expand Up @@ -86,6 +98,7 @@ void Onyx::Terminate()
if (!initialized) return;

FT_Done_FreeType(ft);
glfwTerminate();

for (int i = mallocs.size() - 1; i >= 0; i--)
{
Expand All @@ -98,8 +111,14 @@ void Onyx::Terminate()

void Onyx::Demo()
{
Window::SetMSAA(4);
Window window("Onyx", 1280, 720);
Window window(
WindowProperties {
.title = "Onyx Demo",
.width = 1280,
.height = 720,
.nSamplesMSAA = 4
}
);
window.init();
window.setBackgroundColor(Vec3(0.0f, 0.7f, 1.0f));

Expand Down Expand Up @@ -176,6 +195,18 @@ void Onyx::Demo()
textRenderables[10].translate(Vec2(25.0f, 205.0f));
textRenderables[10].scale(0.6f);

// make members of TextRenderable public for this to work
/*for (CharRenderable& c : textRenderables[0].chars)
{
std::cout << c.getChar() << ": VAO " << c.getVAO() << ", VBO " << c.getVBO() << ", Tex " << c.getTextureID() << "\n";
}
textRenderables[0].setText("Demo Onyx");
std::cout << "\n";
for (CharRenderable& c : textRenderables[0].chars)
{
std::cout << c.getChar() << ": VAO " << c.getVAO() << ", VBO " << c.getVBO() << ", Tex " << c.getTextureID() << "\n";
}*/

for (TextRenderable& tr : textRenderables) renderer.add(tr);

double camSpeed = 5.0;
Expand All @@ -191,11 +222,6 @@ void Onyx::Demo()

int fps = 0;

std::string vendor = (const char*)glGetString(GL_VENDOR);
std::string rendererStr = (const char*)glGetString(GL_RENDERER);

std::cout << vendor << "\n" << rendererStr << "\n";

while (window.isOpen())
{
input.update();
Expand Down Expand Up @@ -223,12 +249,11 @@ void Onyx::Demo()

car.rotate(20.0f * window.getDeltaTime(), Vec3(0, 1, 0));

window.startRender();
renderer.render();

textRenderables[1].setText("FPS: " + std::to_string(fps));
textRenderables[2].setText("FRAME " + std::to_string(window.getFrame()));

window.startRender();
renderer.render();
window.endRender();
}

Expand Down
4 changes: 2 additions & 2 deletions Onyx/src/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

#define ONYX_VERSION_MAJOR 0
#define ONYX_VERSION_MINOR 7
#define ONYX_VERSION_PATCH 6
#define ONYX_VERSION_MINOR 8
#define ONYX_VERSION_PATCH 0
#define ONYX_BETA true

/*
Expand Down
1 change: 1 addition & 0 deletions Onyx/src/Font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Onyx::Font::Font()
{
p_ft = nullptr;
ttfFilePath = "";
size = 0;
}

Onyx::Font Onyx::Font::Load(const std::string& ttfFilePath, uint size)
Expand Down
8 changes: 4 additions & 4 deletions Onyx/src/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ void Onyx::Renderer::render()

glDisable(GL_DEPTH_TEST);
if (uiWireframeAllowed) {
for (UiRenderable* r : uiRenderables) r->render(ortho);
for (TextRenderable* r : textRenderables) r->render(ortho);
for (UiRenderable* uir : uiRenderables) uir->render(ortho);
for (TextRenderable* tr : textRenderables) tr->render(ortho);
}
else
{
bool _wireframe = wireframe;
SetWireframe(false);
for (UiRenderable* r : uiRenderables) r->render(ortho);
for (TextRenderable* r : textRenderables) r->render(ortho);
for (UiRenderable* uir : uiRenderables) uir->render(ortho);
for (TextRenderable* tr : textRenderables) tr->render(ortho);
SetWireframe(_wireframe);
}
glEnable(GL_DEPTH_TEST);
Expand Down
7 changes: 5 additions & 2 deletions Onyx/src/TextRenderable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void Onyx::TextRenderable::resetTransform()

void Onyx::TextRenderable::setText(const std::string& text)
{
for (CharRenderable& c : chars) c.dispose();
this->text = text;
//for (CharRenderable& c : chars) c.dispose();
// ^ this line causes problems but is needed to prevent memory leaks, investigating
chars.clear();
uint advance = 0;
for (int i = 0; i < text.size(); i++)
Expand All @@ -127,7 +129,8 @@ void Onyx::TextRenderable::setText(const std::string& text)
void Onyx::TextRenderable::setFont(Font& font)
{
this->font = &font;
for (CharRenderable& c : chars) c.dispose();
//for (CharRenderable& c : chars) c.dispose();
// ^ this line causes problems but is needed to prevent memory leaks, investigating
chars.clear();
uint advance = 0;
for (int i = 0; i < text.size(); i++)
Expand Down
Loading

0 comments on commit d664fb0

Please sign in to comment.