Skip to content

Commit 4734a55

Browse files
committed
Refactored projects into Sandbox and Examples, also added event system example
1 parent e6b7836 commit 4734a55

File tree

13 files changed

+365
-199
lines changed

13 files changed

+365
-199
lines changed

.gitignore

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
# Directories
2-
.vs/
3-
/bin/
4-
bin-int/
2+
**bin/
3+
**bin-int/
54

65
# Files
7-
*.user
6+
*.user
7+
*imgui.ini
8+
9+
# Visual Studio
10+
.vs/
11+
*.sln
12+
*.vcxproj
13+
*.vcxproj.filters
14+
*.vcxproj.user

OpenGL-Core/premake5.lua

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
project "OpenGL-Core"
2+
kind "StaticLib"
3+
language "C++"
4+
cppdialect "C++17"
5+
staticruntime "on"
6+
7+
targetdir ("../bin/" .. outputdir .. "/%{prj.name}")
8+
objdir ("../bin-int/" .. outputdir .. "/%{prj.name}")
9+
10+
pchheader "glpch.h"
11+
pchsource "src/glpch.cpp"
12+
13+
files
14+
{
15+
"src/**.h",
16+
"src/**.cpp",
17+
"vendor/stb_image/**.h",
18+
"vendor/stb_image/**.cpp",
19+
"vendor/glm/glm/**.hpp",
20+
"vendor/glm/glm/**.inl",
21+
}
22+
23+
defines
24+
{
25+
"_CRT_SECURE_NO_WARNINGS"
26+
}
27+
28+
includedirs
29+
{
30+
"src",
31+
"vendor/spdlog/include",
32+
"%{IncludeDir.GLFW}",
33+
"%{IncludeDir.Glad}",
34+
"%{IncludeDir.ImGui}",
35+
"%{IncludeDir.glm}",
36+
"%{IncludeDir.stb_image}"
37+
}
38+
39+
links
40+
{
41+
"GLFW",
42+
"Glad",
43+
"ImGui",
44+
"opengl32.lib"
45+
}
46+
47+
filter "system:windows"
48+
systemversion "latest"
49+
50+
defines
51+
{
52+
"GLCORE_PLATFORM_WINDOWS",
53+
"GLFW_INCLUDE_NONE"
54+
}
55+
56+
filter "configurations:Debug"
57+
defines "GLCORE_DEBUG"
58+
runtime "Debug"
59+
symbols "on"
60+
61+
filter "configurations:Release"
62+
defines "GLCORE_RELEASE"
63+
runtime "Release"
64+
optimize "on"

OpenGL-Examples/premake5.lua

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
project "OpenGL-Examples"
2+
kind "ConsoleApp"
3+
language "C++"
4+
cppdialect "C++17"
5+
staticruntime "on"
6+
7+
targetdir ("../bin/" .. outputdir .. "/%{prj.name}")
8+
objdir ("../bin-int/" .. outputdir .. "/%{prj.name}")
9+
10+
files
11+
{
12+
"src/**.h",
13+
"src/**.cpp"
14+
}
15+
16+
includedirs
17+
{
18+
"../OpenGL-Core/vendor/spdlog/include",
19+
"../OpenGL-Core/src",
20+
"../OpenGL-Core/vendor",
21+
"../OpenGL-Core/%{IncludeDir.glm}",
22+
"../OpenGL-Core/%{IncludeDir.Glad}",
23+
"../OpenGL-Core/%{IncludeDir.ImGui}"
24+
}
25+
26+
links
27+
{
28+
"OpenGL-Core"
29+
}
30+
31+
filter "system:windows"
32+
systemversion "latest"
33+
34+
defines
35+
{
36+
"GLCORE_PLATFORM_WINDOWS"
37+
}
38+
39+
filter "configurations:Debug"
40+
defines "GLCORE_DEBUG"
41+
runtime "Debug"
42+
symbols "on"
43+
44+
filter "configurations:Release"
45+
defines "GLCORE_RELEASE"
46+
runtime "Release"
47+
optimize "on"

OpenGL-Examples/src/ExampleApp.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "GLCore.h"
2+
#include "ExampleLayer.h"
3+
4+
using namespace GLCore;
5+
6+
class Example : public Application
7+
{
8+
public:
9+
Example()
10+
: Application("OpenGL Examples")
11+
{
12+
PushLayer(new ExampleLayer());
13+
}
14+
};
15+
16+
int main()
17+
{
18+
std::unique_ptr<Example> app = std::make_unique<Example>();
19+
app->Run();
20+
}

OpenGL-Examples/src/ExampleLayer.cpp

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
#include "ExampleLayer.h"
2+
3+
using namespace GLCore;
4+
using namespace GLCore::Utils;
5+
6+
ExampleLayer::ExampleLayer()
7+
: m_CameraController(16.0f / 9.0f)
8+
{
9+
10+
}
11+
12+
ExampleLayer::~ExampleLayer()
13+
{
14+
15+
}
16+
17+
void ExampleLayer::OnAttach()
18+
{
19+
EnableGLDebugging();
20+
21+
glEnable(GL_DEPTH_TEST);
22+
glEnable(GL_BLEND);
23+
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
24+
25+
m_Shader = Shader::FromGLSLTextFiles(
26+
"assets/shaders/test.vert.glsl",
27+
"assets/shaders/test.frag.glsl"
28+
);
29+
30+
glCreateVertexArrays(1, &m_QuadVA);
31+
glBindVertexArray(m_QuadVA);
32+
33+
float vertices[] = {
34+
-0.5f, -0.5f, 0.0f,
35+
0.5f, -0.5f, 0.0f,
36+
0.5f, 0.5f, 0.0f,
37+
-0.5f, 0.5f, 0.0f
38+
};
39+
40+
glCreateBuffers(1, &m_QuadVB);
41+
glBindBuffer(GL_ARRAY_BUFFER, m_QuadVB);
42+
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
43+
44+
glEnableVertexAttribArray(0);
45+
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 3, 0);
46+
47+
uint32_t indices[] = { 0, 1, 2, 2, 3, 0 };
48+
glCreateBuffers(1, &m_QuadIB);
49+
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_QuadIB);
50+
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
51+
}
52+
53+
void ExampleLayer::OnDetach()
54+
{
55+
glDeleteVertexArrays(1, &m_QuadVA);
56+
glDeleteBuffers(1, &m_QuadVB);
57+
glDeleteBuffers(1, &m_QuadIB);
58+
}
59+
60+
void ExampleLayer::OnEvent(Event& event)
61+
{
62+
m_CameraController.OnEvent(event);
63+
64+
EventDispatcher dispatcher(event);
65+
dispatcher.Dispatch<MouseButtonPressedEvent>(
66+
[&](MouseButtonPressedEvent& e)
67+
{
68+
m_SquareColor = m_SquareAlternateColor;
69+
return false;
70+
});
71+
dispatcher.Dispatch<MouseButtonReleasedEvent>(
72+
[&](MouseButtonReleasedEvent& e)
73+
{
74+
m_SquareColor = m_SquareBaseColor;
75+
return false;
76+
});
77+
}
78+
79+
void ExampleLayer::OnUpdate(Timestep ts)
80+
{
81+
m_CameraController.OnUpdate(ts);
82+
83+
glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
84+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
85+
86+
glUseProgram(m_Shader->GetRendererID());
87+
88+
int location = glGetUniformLocation(m_Shader->GetRendererID(), "u_ViewProjection");
89+
glUniformMatrix4fv(location, 1, GL_FALSE, glm::value_ptr(m_CameraController.GetCamera().GetViewProjectionMatrix()));
90+
91+
location = glGetUniformLocation(m_Shader->GetRendererID(), "u_Color");
92+
glUniform4fv(location, 1, glm::value_ptr(m_SquareColor));
93+
94+
glBindVertexArray(m_QuadVA);
95+
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, nullptr);
96+
}
97+
98+
void ExampleLayer::OnImGuiRender()
99+
{
100+
ImGui::Begin("Controls");
101+
if (ImGui::ColorEdit4("Square Base Color", glm::value_ptr(m_SquareBaseColor)))
102+
m_SquareColor = m_SquareBaseColor;
103+
ImGui::ColorEdit4("Square Alternate Color", glm::value_ptr(m_SquareAlternateColor));
104+
ImGui::End();
105+
}

OpenGL-Examples/src/ExampleLayer.h

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
3+
#include <GLCore.h>
4+
#include <GLCoreUtils.h>
5+
6+
class ExampleLayer : public GLCore::Layer
7+
{
8+
public:
9+
ExampleLayer();
10+
virtual ~ExampleLayer();
11+
12+
virtual void OnAttach() override;
13+
virtual void OnDetach() override;
14+
virtual void OnEvent(GLCore::Event& event) override;
15+
virtual void OnUpdate(GLCore::Timestep ts) override;
16+
virtual void OnImGuiRender() override;
17+
private:
18+
GLCore::Utils::Shader* m_Shader;
19+
GLCore::Utils::OrthographicCameraController m_CameraController;
20+
21+
GLuint m_QuadVA, m_QuadVB, m_QuadIB;
22+
23+
glm::vec4 m_SquareBaseColor = { 0.8f, 0.2f, 0.3f, 1.0f };
24+
glm::vec4 m_SquareAlternateColor = { 0.2f, 0.3f, 0.8f, 1.0f };
25+
glm::vec4 m_SquareColor = m_SquareBaseColor;
26+
};

OpenGL-Sandbox/imgui.ini

-18
This file was deleted.

OpenGL-Sandbox/premake5.lua

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
project "OpenGL-Sandbox"
2+
kind "ConsoleApp"
3+
language "C++"
4+
cppdialect "C++17"
5+
staticruntime "on"
6+
7+
targetdir ("../bin/" .. outputdir .. "/%{prj.name}")
8+
objdir ("../bin-int/" .. outputdir .. "/%{prj.name}")
9+
10+
files
11+
{
12+
"src/**.h",
13+
"src/**.cpp"
14+
}
15+
16+
includedirs
17+
{
18+
"../OpenGL-Core/vendor/spdlog/include",
19+
"../OpenGL-Core/src",
20+
"../OpenGL-Core/vendor",
21+
"../OpenGL-Core/%{IncludeDir.glm}",
22+
"../OpenGL-Core/%{IncludeDir.Glad}",
23+
"../OpenGL-Core/%{IncludeDir.ImGui}"
24+
}
25+
26+
links
27+
{
28+
"OpenGL-Core"
29+
}
30+
31+
filter "system:windows"
32+
systemversion "latest"
33+
34+
defines
35+
{
36+
"GLCORE_PLATFORM_WINDOWS"
37+
}
38+
39+
filter "configurations:Debug"
40+
defines "GLCORE_DEBUG"
41+
runtime "Debug"
42+
symbols "on"
43+
44+
filter "configurations:Release"
45+
defines "GLCORE_RELEASE"
46+
runtime "Release"
47+
optimize "on"

0 commit comments

Comments
 (0)