├── Hazel ├── src │ ├── hzpch.cpp │ ├── Hazel │ │ ├── ImGui │ │ │ ├── ImGuiBuild.cpp │ │ │ ├── ImGuiLayer.h │ │ │ └── ImGuiLayer.cpp │ │ ├── Renderer │ │ │ ├── RenderCommand.cpp │ │ │ ├── GraphicsContext.h │ │ │ ├── UniformBuffer.h │ │ │ ├── Camera.h │ │ │ ├── VertexArray.cpp │ │ │ ├── RendererAPI.cpp │ │ │ ├── UniformBuffer.cpp │ │ │ ├── GraphicsContext.cpp │ │ │ ├── Framebuffer.cpp │ │ │ ├── VertexArray.h │ │ │ ├── RendererAPI.h │ │ │ ├── Texture.h │ │ │ ├── RenderCommand.h │ │ │ ├── Renderer.h │ │ │ ├── Texture.cpp │ │ │ ├── OrthographicCamera.h │ │ │ ├── OrthographicCamera.cpp │ │ │ ├── Renderer.cpp │ │ │ ├── OrthographicCameraController.h │ │ │ ├── Buffer.cpp │ │ │ ├── Shader.h │ │ │ ├── Framebuffer.h │ │ │ ├── Shader.cpp │ │ │ ├── EditorCamera.h │ │ │ ├── Renderer2D.h │ │ │ ├── OrthographicCameraController.cpp │ │ │ ├── Buffer.h │ │ │ └── EditorCamera.cpp │ │ ├── Core │ │ │ ├── Layer.cpp │ │ │ ├── Timestep.h │ │ │ ├── Input.h │ │ │ ├── Window.cpp │ │ │ ├── Layer.h │ │ │ ├── MouseCodes.h │ │ │ ├── Timer.h │ │ │ ├── EntryPoint.h │ │ │ ├── LayerStack.cpp │ │ │ ├── LayerStack.h │ │ │ ├── Window.h │ │ │ ├── Log.cpp │ │ │ ├── Base.h │ │ │ ├── PlatformDetection.h │ │ │ ├── Assert.h │ │ │ ├── Application.h │ │ │ ├── Log.h │ │ │ ├── Application.cpp │ │ │ └── KeyCodes.h │ │ ├── Scene │ │ │ ├── Entity.cpp │ │ │ ├── SceneSerializer.h │ │ │ ├── ScriptableEntity.h │ │ │ ├── Scene.h │ │ │ ├── SceneCamera.cpp │ │ │ ├── Entity.h │ │ │ ├── SceneCamera.h │ │ │ ├── Components.h │ │ │ └── Scene.cpp │ │ ├── Math │ │ │ ├── Math.h │ │ │ └── Math.cpp │ │ ├── Utils │ │ │ └── PlatformUtils.h │ │ └── Events │ │ │ ├── ApplicationEvent.h │ │ │ ├── KeyEvent.h │ │ │ ├── Event.h │ │ │ └── MouseEvent.h │ ├── Platform │ │ ├── OpenGL │ │ │ ├── OpenGLContext.h │ │ │ ├── OpenGLUniformBuffer.h │ │ │ ├── OpenGLRendererAPI.h │ │ │ ├── OpenGLUniformBuffer.cpp │ │ │ ├── OpenGLVertexArray.h │ │ │ ├── OpenGLBuffer.h │ │ │ ├── OpenGLContext.cpp │ │ │ ├── OpenGLTexture.h │ │ │ ├── OpenGLFramebuffer.h │ │ │ ├── OpenGLRendererAPI.cpp │ │ │ ├── OpenGLShader.h │ │ │ ├── OpenGLBuffer.cpp │ │ │ ├── OpenGLTexture.cpp │ │ │ └── OpenGLVertexArray.cpp │ │ └── Windows │ │ │ ├── WindowsWindow.h │ │ │ ├── WindowsInput.cpp │ │ │ ├── WindowsPlatformUtils.cpp │ │ │ └── WindowsWindow.cpp │ ├── hzpch.h │ └── Hazel.h ├── vendor │ ├── stb_image │ │ └── stb_image.cpp │ ├── Glad │ │ └── premake5.lua │ └── entt │ │ └── LICENSE.txt └── premake5.lua ├── scripts ├── Setup.bat ├── Win-GenProjects.bat ├── Setup.py ├── SetupPython.py ├── SetupPremake.py ├── SetupVulkan.py └── Utils.py ├── Sandbox ├── assets │ ├── textures │ │ ├── ChernoLogo.png │ │ └── Checkerboard.png │ ├── fonts │ │ └── opensans │ │ │ ├── OpenSans-Bold.ttf │ │ │ ├── OpenSans-Light.ttf │ │ │ ├── OpenSans-Italic.ttf │ │ │ ├── OpenSans-Regular.ttf │ │ │ ├── OpenSans-BoldItalic.ttf │ │ │ ├── OpenSans-ExtraBold.ttf │ │ │ ├── OpenSans-SemiBold.ttf │ │ │ ├── OpenSans-LightItalic.ttf │ │ │ ├── OpenSans-ExtraBoldItalic.ttf │ │ │ └── OpenSans-SemiBoldItalic.ttf │ └── shaders │ │ ├── FlatColor.glsl │ │ └── Texture.glsl ├── imgui.ini ├── src │ ├── SandboxApp.cpp │ ├── Sandbox2D.h │ ├── ExampleLayer.h │ ├── Sandbox2D.cpp │ └── ExampleLayer.cpp └── premake5.lua ├── Hazelnut ├── Resources │ └── Icons │ │ ├── PlayButton.png │ │ ├── StopButton.png │ │ └── ContentBrowser │ │ ├── FileIcon.png │ │ └── DirectoryIcon.png ├── assets │ ├── textures │ │ ├── ChernoLogo.png │ │ └── Checkerboard.png │ ├── fonts │ │ └── opensans │ │ │ ├── OpenSans-Bold.ttf │ │ │ ├── OpenSans-Italic.ttf │ │ │ ├── OpenSans-Light.ttf │ │ │ ├── OpenSans-ExtraBold.ttf │ │ │ ├── OpenSans-Regular.ttf │ │ │ ├── OpenSans-SemiBold.ttf │ │ │ ├── OpenSans-BoldItalic.ttf │ │ │ ├── OpenSans-LightItalic.ttf │ │ │ ├── OpenSans-SemiBoldItalic.ttf │ │ │ └── OpenSans-ExtraBoldItalic.ttf │ ├── shaders │ │ ├── FlatColor.glsl │ │ └── Texture.glsl │ └── scenes │ │ ├── PinkCube.hazel │ │ ├── Example.hazel │ │ └── 3DExample.hazel ├── src │ ├── Panels │ │ ├── ContentBrowserPanel.h │ │ ├── SceneHierarchyPanel.h │ │ └── ContentBrowserPanel.cpp │ ├── HazelnutApp.cpp │ └── EditorLayer.h ├── premake5.lua └── imgui.ini ├── Resources └── Branding │ └── Hazel_Logo_Text_Light_Square.png ├── .editorconfig ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ ├── issue--feature-request.md │ ├── other-issues--blank-template.md │ └── issue--bug-report.md ├── PULL_REQUEST_TEMPLATE.md └── CONTRIBUTING.md ├── .gitignore ├── vendor └── premake │ ├── premake5.lua │ └── premake_customization │ └── solution_items.lua ├── .gitmodules ├── premake5.lua ├── Dependencies.lua └── README.md /Hazel/src/hzpch.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" -------------------------------------------------------------------------------- /scripts/Setup.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | python Setup.py 3 | PAUSE -------------------------------------------------------------------------------- /Hazel/vendor/stb_image/stb_image.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | 3 | #define STB_IMAGE_IMPLEMENTATION 4 | #include "stb_image.h" -------------------------------------------------------------------------------- /Sandbox/assets/textures/ChernoLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/textures/ChernoLogo.png -------------------------------------------------------------------------------- /scripts/Win-GenProjects.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | pushd %~dp0\..\ 3 | call vendor\premake\bin\premake5.exe vs2019 4 | popd 5 | PAUSE 6 | -------------------------------------------------------------------------------- /Hazelnut/Resources/Icons/PlayButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/Resources/Icons/PlayButton.png -------------------------------------------------------------------------------- /Hazelnut/Resources/Icons/StopButton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/Resources/Icons/StopButton.png -------------------------------------------------------------------------------- /Hazelnut/assets/textures/ChernoLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/textures/ChernoLogo.png -------------------------------------------------------------------------------- /Sandbox/assets/textures/Checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/textures/Checkerboard.png -------------------------------------------------------------------------------- /Hazelnut/assets/textures/Checkerboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/textures/Checkerboard.png -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-Bold.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-Bold.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-Light.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-Italic.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-Light.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-Light.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-Italic.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /Hazelnut/Resources/Icons/ContentBrowser/FileIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/Resources/Icons/ContentBrowser/FileIcon.png -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-ExtraBold.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-Regular.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-SemiBold.ttf -------------------------------------------------------------------------------- /Resources/Branding/Hazel_Logo_Text_Light_Square.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Resources/Branding/Hazel_Logo_Text_Light_Square.png -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-BoldItalic.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-ExtraBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-ExtraBold.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-SemiBold.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-BoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-BoldItalic.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-LightItalic.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-LightItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-LightItalic.ttf -------------------------------------------------------------------------------- /Hazelnut/Resources/Icons/ContentBrowser/DirectoryIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/Resources/Icons/ContentBrowser/DirectoryIcon.png -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-ExtraBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-ExtraBoldItalic.ttf -------------------------------------------------------------------------------- /Sandbox/assets/fonts/opensans/OpenSans-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Sandbox/assets/fonts/opensans/OpenSans-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /Hazelnut/assets/fonts/opensans/OpenSans-ExtraBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/englercj/Hazel/master/Hazelnut/assets/fonts/opensans/OpenSans-ExtraBoldItalic.ttf -------------------------------------------------------------------------------- /Hazel/src/Hazel/ImGui/ImGuiBuild.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | 3 | #define IMGUI_IMPL_OPENGL_LOADER_GLAD 4 | #include 5 | #include -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = tab 9 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/RenderCommand.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/RenderCommand.h" 3 | 4 | namespace Hazel { 5 | 6 | Scope RenderCommand::s_RendererAPI = RendererAPI::Create(); 7 | 8 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Layer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/Layer.h" 3 | 4 | namespace Hazel { 5 | 6 | Layer::Layer(const std::string& debugName) 7 | : m_DebugName(debugName) 8 | { 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/Entity.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Entity.h" 3 | 4 | namespace Hazel { 5 | 6 | Entity::Entity(entt::entity handle, Scene* scene) 7 | : m_EntityHandle(handle), m_Scene(scene) 8 | { 9 | } 10 | 11 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Math/Math.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Hazel::Math { 6 | 7 | bool DecomposeTransform(const glm::mat4& transform, glm::vec3& translation, glm::vec3& rotation, glm::vec3& scale); 8 | 9 | } 10 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Hazel Community Support (Discord) 4 | url: https://thecherno.com/discord 5 | about: Please ask Hazel related questions in the game-engine-series thread. 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries 2 | **/bin/ 3 | bin-int/ 4 | 5 | # Hazel files 6 | *.log 7 | 8 | # Visual Studio files and folder 9 | .vs/ 10 | **.sln 11 | **.vcxproj 12 | **.vcxproj.filters 13 | **.vcxproj.user 14 | 15 | # Directories 16 | Hazel/vendor/VulkanSDK 17 | Hazelnut/assets/cache 18 | scripts/__pycache__ -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/GraphicsContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Hazel { 4 | 5 | class GraphicsContext 6 | { 7 | public: 8 | virtual ~GraphicsContext() = default; 9 | 10 | virtual void Init() = 0; 11 | virtual void SwapBuffers() = 0; 12 | 13 | static Scope Create(void* window); 14 | }; 15 | 16 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Utils/PlatformUtils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Hazel { 6 | 7 | class FileDialogs 8 | { 9 | public: 10 | // These return empty strings if cancelled 11 | static std::string OpenFile(const char* filter); 12 | static std::string SaveFile(const char* filter); 13 | }; 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/UniformBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | 5 | namespace Hazel { 6 | 7 | class UniformBuffer 8 | { 9 | public: 10 | virtual ~UniformBuffer() {} 11 | virtual void SetData(const void* data, uint32_t size, uint32_t offset = 0) = 0; 12 | 13 | static Ref Create(uint32_t size, uint32_t binding); 14 | }; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Timestep.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Hazel { 4 | 5 | class Timestep 6 | { 7 | public: 8 | Timestep(float time = 0.0f) 9 | : m_Time(time) 10 | { 11 | } 12 | 13 | operator float() const { return m_Time; } 14 | 15 | float GetSeconds() const { return m_Time; } 16 | float GetMilliseconds() const { return m_Time * 1000.0f; } 17 | private: 18 | float m_Time; 19 | }; 20 | 21 | } -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLContext.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/GraphicsContext.h" 4 | 5 | struct GLFWwindow; 6 | 7 | namespace Hazel { 8 | 9 | class OpenGLContext : public GraphicsContext 10 | { 11 | public: 12 | OpenGLContext(GLFWwindow* windowHandle); 13 | 14 | virtual void Init() override; 15 | virtual void SwapBuffers() override; 16 | private: 17 | GLFWwindow* m_WindowHandle; 18 | }; 19 | 20 | } -------------------------------------------------------------------------------- /Hazelnut/src/Panels/ContentBrowserPanel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Renderer/Texture.h" 6 | 7 | namespace Hazel { 8 | 9 | class ContentBrowserPanel 10 | { 11 | public: 12 | ContentBrowserPanel(); 13 | 14 | void OnImGuiRender(); 15 | private: 16 | std::filesystem::path m_CurrentDirectory; 17 | 18 | Ref m_DirectoryIcon; 19 | Ref m_FileIcon; 20 | }; 21 | 22 | } 23 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Camera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Hazel { 6 | 7 | class Camera 8 | { 9 | public: 10 | Camera() = default; 11 | Camera(const glm::mat4& projection) 12 | : m_Projection(projection) {} 13 | 14 | virtual ~Camera() = default; 15 | 16 | const glm::mat4& GetProjection() const { return m_Projection; } 17 | protected: 18 | glm::mat4 m_Projection = glm::mat4(1.0f); 19 | }; 20 | 21 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Input.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Core/KeyCodes.h" 6 | #include "Hazel/Core/MouseCodes.h" 7 | 8 | namespace Hazel { 9 | 10 | class Input 11 | { 12 | public: 13 | static bool IsKeyPressed(KeyCode key); 14 | 15 | static bool IsMouseButtonPressed(MouseCode button); 16 | static glm::vec2 GetMousePosition(); 17 | static float GetMouseX(); 18 | static float GetMouseY(); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Window.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/Window.h" 3 | 4 | #ifdef HZ_PLATFORM_WINDOWS 5 | #include "Platform/Windows/WindowsWindow.h" 6 | #endif 7 | 8 | namespace Hazel 9 | { 10 | Scope Window::Create(const WindowProps& props) 11 | { 12 | #ifdef HZ_PLATFORM_WINDOWS 13 | return CreateScope(props); 14 | #else 15 | HZ_CORE_ASSERT(false, "Unknown platform!"); 16 | return nullptr; 17 | #endif 18 | } 19 | 20 | } -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLUniformBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/UniformBuffer.h" 4 | 5 | namespace Hazel { 6 | 7 | class OpenGLUniformBuffer : public UniformBuffer 8 | { 9 | public: 10 | OpenGLUniformBuffer(uint32_t size, uint32_t binding); 11 | virtual ~OpenGLUniformBuffer(); 12 | 13 | virtual void SetData(const void* data, uint32_t size, uint32_t offset = 0) override; 14 | private: 15 | uint32_t m_RendererID = 0; 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /vendor/premake/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Premake" 2 | kind "Utility" 3 | 4 | targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") 5 | objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") 6 | 7 | files 8 | { 9 | "%{wks.location}/**premake5.lua" 10 | } 11 | 12 | postbuildmessage "Regenerating project files with Premake5!" 13 | postbuildcommands 14 | { 15 | "\"%{prj.location}bin/premake5\" %{_ACTION} --file=\"%{wks.location}premake5.lua\"" 16 | } 17 | -------------------------------------------------------------------------------- /Sandbox/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][Debug##Default] 2 | Pos=60,60 3 | Size=400,400 4 | Collapsed=0 5 | 6 | [Window][Test] 7 | Pos=60,60 8 | Size=92,48 9 | Collapsed=0 10 | 11 | [Window][ImGui Demo] 12 | ViewportPos=1404,134 13 | ViewportId=0x080FC883 14 | Size=550,680 15 | Collapsed=0 16 | 17 | [Window][Settings] 18 | ViewportPos=1214,617 19 | ViewportId=0x1C33C293 20 | Size=432,366 21 | Collapsed=0 22 | 23 | [Window][DockSpace Demo] 24 | Size=1280,720 25 | Collapsed=0 26 | 27 | [Docking][Data] 28 | 29 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/SceneSerializer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Scene.h" 4 | 5 | namespace Hazel { 6 | 7 | class SceneSerializer 8 | { 9 | public: 10 | SceneSerializer(const Ref& scene); 11 | 12 | void Serialize(const std::string& filepath); 13 | void SerializeRuntime(const std::string& filepath); 14 | 15 | bool Deserialize(const std::string& filepath); 16 | bool DeserializeRuntime(const std::string& filepath); 17 | private: 18 | Ref m_Scene; 19 | }; 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Sandbox/assets/shaders/FlatColor.glsl: -------------------------------------------------------------------------------- 1 | // Flat Color Shader 2 | 3 | #type vertex 4 | #version 330 core 5 | 6 | layout(location = 0) in vec3 a_Position; 7 | 8 | uniform mat4 u_ViewProjection; 9 | uniform mat4 u_Transform; 10 | 11 | void main() 12 | { 13 | gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0); 14 | } 15 | 16 | #type fragment 17 | #version 330 core 18 | 19 | layout(location = 0) out vec4 color; 20 | 21 | uniform vec4 u_Color; 22 | 23 | void main() 24 | { 25 | color = u_Color; 26 | } -------------------------------------------------------------------------------- /Hazelnut/assets/shaders/FlatColor.glsl: -------------------------------------------------------------------------------- 1 | // Flat Color Shader 2 | 3 | #type vertex 4 | #version 330 core 5 | 6 | layout(location = 0) in vec3 a_Position; 7 | 8 | uniform mat4 u_ViewProjection; 9 | uniform mat4 u_Transform; 10 | 11 | void main() 12 | { 13 | gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0); 14 | } 15 | 16 | #type fragment 17 | #version 330 core 18 | 19 | layout(location = 0) out vec4 color; 20 | 21 | uniform vec4 u_Color; 22 | 23 | void main() 24 | { 25 | color = u_Color; 26 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/ScriptableEntity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Entity.h" 4 | 5 | namespace Hazel { 6 | 7 | class ScriptableEntity 8 | { 9 | public: 10 | virtual ~ScriptableEntity() {} 11 | 12 | template 13 | T& GetComponent() 14 | { 15 | return m_Entity.GetComponent(); 16 | } 17 | protected: 18 | virtual void OnCreate() {} 19 | virtual void OnDestroy() {} 20 | virtual void OnUpdate(Timestep ts) {} 21 | private: 22 | Entity m_Entity; 23 | friend class Scene; 24 | }; 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Hazelnut/src/HazelnutApp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "EditorLayer.h" 5 | 6 | namespace Hazel { 7 | 8 | class Hazelnut : public Application 9 | { 10 | public: 11 | Hazelnut(ApplicationCommandLineArgs args) 12 | : Application("Hazelnut", args) 13 | { 14 | PushLayer(new EditorLayer()); 15 | } 16 | 17 | ~Hazelnut() 18 | { 19 | } 20 | }; 21 | 22 | Application* CreateApplication(ApplicationCommandLineArgs args) 23 | { 24 | return new Hazelnut(args); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Sandbox/src/SandboxApp.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Sandbox2D.h" 5 | #include "ExampleLayer.h" 6 | 7 | class Sandbox : public Hazel::Application 8 | { 9 | public: 10 | Sandbox(Hazel::ApplicationCommandLineArgs args) 11 | { 12 | // PushLayer(new ExampleLayer()); 13 | PushLayer(new Sandbox2D()); 14 | } 15 | 16 | ~Sandbox() 17 | { 18 | } 19 | }; 20 | 21 | Hazel::Application* Hazel::CreateApplication(Hazel::ApplicationCommandLineArgs args) 22 | { 23 | return new Sandbox(args); 24 | } 25 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLRendererAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/RendererAPI.h" 4 | 5 | namespace Hazel { 6 | 7 | class OpenGLRendererAPI : public RendererAPI 8 | { 9 | public: 10 | virtual void Init() override; 11 | virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) override; 12 | 13 | virtual void SetClearColor(const glm::vec4& color) override; 14 | virtual void Clear() override; 15 | 16 | virtual void DrawIndexed(const Ref& vertexArray, uint32_t indexCount = 0) override; 17 | }; 18 | 19 | 20 | } 21 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/VertexArray.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/VertexArray.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | #include "Platform/OpenGL/OpenGLVertexArray.h" 6 | 7 | namespace Hazel { 8 | 9 | Ref VertexArray::Create() 10 | { 11 | switch (Renderer::GetAPI()) 12 | { 13 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 14 | case RendererAPI::API::OpenGL: return CreateRef(); 15 | } 16 | 17 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 18 | return nullptr; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Layer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | #include "Hazel/Core/Timestep.h" 5 | #include "Hazel/Events/Event.h" 6 | 7 | namespace Hazel { 8 | 9 | class Layer 10 | { 11 | public: 12 | Layer(const std::string& name = "Layer"); 13 | virtual ~Layer() = default; 14 | 15 | virtual void OnAttach() {} 16 | virtual void OnDetach() {} 17 | virtual void OnUpdate(Timestep ts) {} 18 | virtual void OnImGuiRender() {} 19 | virtual void OnEvent(Event& event) {} 20 | 21 | const std::string& GetName() const { return m_DebugName; } 22 | protected: 23 | std::string m_DebugName; 24 | }; 25 | 26 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/RendererAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/RendererAPI.h" 3 | 4 | #include "Platform/OpenGL/OpenGLRendererAPI.h" 5 | 6 | namespace Hazel { 7 | 8 | RendererAPI::API RendererAPI::s_API = RendererAPI::API::OpenGL; 9 | 10 | Scope RendererAPI::Create() 11 | { 12 | switch (s_API) 13 | { 14 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 15 | case RendererAPI::API::OpenGL: return CreateScope(); 16 | } 17 | 18 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 19 | return nullptr; 20 | } 21 | 22 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/MouseCodes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Hazel 4 | { 5 | using MouseCode = uint16_t; 6 | 7 | namespace Mouse 8 | { 9 | enum : MouseCode 10 | { 11 | // From glfw3.h 12 | Button0 = 0, 13 | Button1 = 1, 14 | Button2 = 2, 15 | Button3 = 3, 16 | Button4 = 4, 17 | Button5 = 5, 18 | Button6 = 6, 19 | Button7 = 7, 20 | 21 | ButtonLast = Button7, 22 | ButtonLeft = Button0, 23 | ButtonRight = Button1, 24 | ButtonMiddle = Button2 25 | }; 26 | } 27 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/UniformBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "UniformBuffer.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | #include "Platform/OpenGL/OpenGLUniformBuffer.h" 6 | 7 | namespace Hazel { 8 | 9 | Ref UniformBuffer::Create(uint32_t size, uint32_t binding) 10 | { 11 | switch (Renderer::GetAPI()) 12 | { 13 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 14 | case RendererAPI::API::OpenGL: return CreateRef(size, binding); 15 | } 16 | 17 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 18 | return nullptr; 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/GraphicsContext.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/GraphicsContext.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | #include "Platform/OpenGL/OpenGLContext.h" 6 | 7 | namespace Hazel { 8 | 9 | Scope GraphicsContext::Create(void* window) 10 | { 11 | switch (Renderer::GetAPI()) 12 | { 13 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 14 | case RendererAPI::API::OpenGL: return CreateScope(static_cast(window)); 15 | } 16 | 17 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 18 | return nullptr; 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Framebuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/Framebuffer.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | 6 | #include "Platform/OpenGL/OpenGLFramebuffer.h" 7 | 8 | namespace Hazel { 9 | 10 | Ref Framebuffer::Create(const FramebufferSpecification& spec) 11 | { 12 | switch (Renderer::GetAPI()) 13 | { 14 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 15 | case RendererAPI::API::OpenGL: return CreateRef(spec); 16 | } 17 | 18 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 19 | return nullptr; 20 | } 21 | 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/VertexArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "Hazel/Renderer/Buffer.h" 5 | 6 | namespace Hazel { 7 | 8 | class VertexArray 9 | { 10 | public: 11 | virtual ~VertexArray() = default; 12 | 13 | virtual void Bind() const = 0; 14 | virtual void Unbind() const = 0; 15 | 16 | virtual void AddVertexBuffer(const Ref& vertexBuffer) = 0; 17 | virtual void SetIndexBuffer(const Ref& indexBuffer) = 0; 18 | 19 | virtual const std::vector>& GetVertexBuffers() const = 0; 20 | virtual const Ref& GetIndexBuffer() const = 0; 21 | 22 | static Ref Create(); 23 | }; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Timer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Hazel { 6 | 7 | class Timer 8 | { 9 | public: 10 | Timer() 11 | { 12 | Reset(); 13 | } 14 | 15 | void Timer::Reset() 16 | { 17 | m_Start = std::chrono::high_resolution_clock::now(); 18 | } 19 | 20 | float Timer::Elapsed() 21 | { 22 | return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_Start).count() * 0.001f * 0.001f * 0.001f; 23 | } 24 | 25 | float Timer::ElapsedMillis() 26 | { 27 | return Elapsed() * 1000.0f; 28 | } 29 | 30 | private: 31 | std::chrono::time_point m_Start; 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/ImGui/ImGuiLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Layer.h" 4 | 5 | #include "Hazel/Events/ApplicationEvent.h" 6 | #include "Hazel/Events/KeyEvent.h" 7 | #include "Hazel/Events/MouseEvent.h" 8 | 9 | namespace Hazel { 10 | 11 | class ImGuiLayer : public Layer 12 | { 13 | public: 14 | ImGuiLayer(); 15 | ~ImGuiLayer() = default; 16 | 17 | virtual void OnAttach() override; 18 | virtual void OnDetach() override; 19 | virtual void OnEvent(Event& e) override; 20 | 21 | void Begin(); 22 | void End(); 23 | 24 | void BlockEvents(bool block) { m_BlockEvents = block; } 25 | 26 | void SetDarkThemeColors(); 27 | private: 28 | bool m_BlockEvents = true; 29 | }; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Hazel/vendor/Glad/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Glad" 2 | kind "StaticLib" 3 | language "C" 4 | staticruntime "off" 5 | 6 | targetdir ("bin/" .. outputdir .. "/%{prj.name}") 7 | objdir ("bin-int/" .. outputdir .. "/%{prj.name}") 8 | 9 | files 10 | { 11 | "include/glad/glad.h", 12 | "include/KHR/khrplatform.h", 13 | "src/glad.c" 14 | } 15 | 16 | includedirs 17 | { 18 | "include" 19 | } 20 | 21 | filter "system:windows" 22 | systemversion "latest" 23 | 24 | filter "configurations:Debug" 25 | runtime "Debug" 26 | symbols "on" 27 | 28 | filter "configurations:Release" 29 | runtime "Release" 30 | optimize "on" 31 | -------------------------------------------------------------------------------- /Sandbox/src/Sandbox2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel.h" 4 | 5 | class Sandbox2D : public Hazel::Layer 6 | { 7 | public: 8 | Sandbox2D(); 9 | virtual ~Sandbox2D() = default; 10 | 11 | virtual void OnAttach() override; 12 | virtual void OnDetach() override; 13 | 14 | void OnUpdate(Hazel::Timestep ts) override; 15 | virtual void OnImGuiRender() override; 16 | void OnEvent(Hazel::Event& e) override; 17 | private: 18 | Hazel::OrthographicCameraController m_CameraController; 19 | 20 | // Temp 21 | Hazel::Ref m_SquareVA; 22 | Hazel::Ref m_FlatColorShader; 23 | 24 | Hazel::Ref m_CheckerboardTexture; 25 | 26 | glm::vec4 m_SquareColor = { 0.2f, 0.3f, 0.8f, 1.0f }; 27 | }; -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "Hazel/vendor/spdlog"] 2 | path = Hazel/vendor/spdlog 3 | url = ../../gabime/spdlog.git 4 | branch = v1.x 5 | [submodule "Hazel/vendor/GLFW"] 6 | path = Hazel/vendor/GLFW 7 | url = ../../TheCherno/glfw.git 8 | branch = master 9 | [submodule "Hazel/vendor/imgui"] 10 | path = Hazel/vendor/imgui 11 | url = ../../TheCherno/imgui.git 12 | branch = docking 13 | [submodule "Hazel/vendor/glm"] 14 | path = Hazel/vendor/glm 15 | url = ../../g-truc/glm.git 16 | branch = master 17 | [submodule "Hazel/vendor/yaml-cpp"] 18 | path = Hazel/vendor/yaml-cpp 19 | url = https://github.com/thecherno/yaml-cpp 20 | [submodule "Hazel/vendor/ImGuizmo"] 21 | path = Hazel/vendor/ImGuizmo 22 | url = https://github.com/thecherno/imguizmo 23 | -------------------------------------------------------------------------------- /Hazelnut/src/Panels/SceneHierarchyPanel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | #include "Hazel/Scene/Scene.h" 5 | #include "Hazel/Scene/Entity.h" 6 | 7 | namespace Hazel { 8 | 9 | class SceneHierarchyPanel 10 | { 11 | public: 12 | SceneHierarchyPanel() = default; 13 | SceneHierarchyPanel(const Ref& scene); 14 | 15 | void SetContext(const Ref& scene); 16 | 17 | void OnImGuiRender(); 18 | 19 | Entity GetSelectedEntity() const { return m_SelectionContext; } 20 | void SetSelectedEntity(Entity entity); 21 | private: 22 | void DrawEntityNode(Entity entity); 23 | void DrawComponents(Entity entity); 24 | private: 25 | Ref m_Context; 26 | Entity m_SelectionContext; 27 | }; 28 | 29 | } 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue--feature-request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Issue: Feature request' 3 | about: Suggest an idea/extension for Hazel 4 | 5 | --- 6 | 7 | #### Is your feature request related to a problem? Please describe 8 | A clear and concise description of what the problem is, e.g. "I'm always frustrated when [...]" 9 | 10 | #### Describe the solution you'd like 11 | A clear and concise description of what you want to happen. 12 | 13 | #### Describe alternatives you've considered 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | #### Additional context 17 | Add any other context or screenshots about the feature request here. Any relevant information for platform specific features could be useful. 18 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/EntryPoint.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Hazel/Core/Base.h" 3 | #include "Hazel/Core/Application.h" 4 | 5 | #ifdef HZ_PLATFORM_WINDOWS 6 | 7 | extern Hazel::Application* Hazel::CreateApplication(ApplicationCommandLineArgs args); 8 | 9 | int main(int argc, char** argv) 10 | { 11 | Hazel::Log::Init(); 12 | 13 | HZ_PROFILE_BEGIN_SESSION("Startup", "HazelProfile-Startup.json"); 14 | auto app = Hazel::CreateApplication({ argc, argv }); 15 | HZ_PROFILE_END_SESSION(); 16 | 17 | HZ_PROFILE_BEGIN_SESSION("Runtime", "HazelProfile-Runtime.json"); 18 | app->Run(); 19 | HZ_PROFILE_END_SESSION(); 20 | 21 | HZ_PROFILE_BEGIN_SESSION("Shutdown", "HazelProfile-Shutdown.json"); 22 | delete app; 23 | HZ_PROFILE_END_SESSION(); 24 | } 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLUniformBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "OpenGLUniformBuffer.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | OpenGLUniformBuffer::OpenGLUniformBuffer(uint32_t size, uint32_t binding) 9 | { 10 | glCreateBuffers(1, &m_RendererID); 11 | glNamedBufferData(m_RendererID, size, nullptr, GL_DYNAMIC_DRAW); // TODO: investigate usage hint 12 | glBindBufferBase(GL_UNIFORM_BUFFER, binding, m_RendererID); 13 | } 14 | 15 | OpenGLUniformBuffer::~OpenGLUniformBuffer() 16 | { 17 | glDeleteBuffers(1, &m_RendererID); 18 | } 19 | 20 | 21 | void OpenGLUniformBuffer::SetData(const void* data, uint32_t size, uint32_t offset) 22 | { 23 | glNamedBufferSubData(m_RendererID, offset, size, data); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /premake5.lua: -------------------------------------------------------------------------------- 1 | include "./vendor/premake/premake_customization/solution_items.lua" 2 | include "Dependencies.lua" 3 | 4 | workspace "Hazel" 5 | architecture "x86_64" 6 | startproject "Hazelnut" 7 | 8 | configurations 9 | { 10 | "Debug", 11 | "Release", 12 | "Dist" 13 | } 14 | 15 | solution_items 16 | { 17 | ".editorconfig" 18 | } 19 | 20 | flags 21 | { 22 | "MultiProcessorCompile" 23 | } 24 | 25 | outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}" 26 | 27 | group "Dependencies" 28 | include "vendor/premake" 29 | include "Hazel/vendor/GLFW" 30 | include "Hazel/vendor/Glad" 31 | include "Hazel/vendor/imgui" 32 | include "Hazel/vendor/yaml-cpp" 33 | group "" 34 | 35 | include "Hazel" 36 | include "Sandbox" 37 | include "Hazelnut" 38 | -------------------------------------------------------------------------------- /Hazel/src/hzpch.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/PlatformDetection.h" 4 | 5 | #ifdef HZ_PLATFORM_WINDOWS 6 | #ifndef NOMINMAX 7 | // See github.com/skypjack/entt/wiki/Frequently-Asked-Questions#warning-c4003-the-min-the-max-and-the-macro 8 | #define NOMINMAX 9 | #endif 10 | #endif 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | #include "Hazel/Core/Base.h" 26 | 27 | #include "Hazel/Core/Log.h" 28 | 29 | #include "Hazel/Debug/Instrumentor.h" 30 | 31 | #ifdef HZ_PLATFORM_WINDOWS 32 | #include 33 | #endif 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/other-issues--blank-template.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Other issues: Blank template' 3 | about: For issues that are not a bug report or feature request 4 | 5 | --- 6 | 7 | Please consider using the Bug report or Feature request template. If it doesn't belong there, feel free to use this (empty) template. Make sure to provide enough details so it is clear for contributors to help you out. Premature or incomplete issues cannot be resolved due to lack of information or unclear descriptions. 8 | 9 | Make sure your issue can be reproduced with the Hazel Engine and not by your own engine that you're creating alongside with Hazel. For issues with your own engine, we're happy to help you in [TheCherno Discord server](https://thecherno.com/discord). Thanks for your understanding. 10 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/RendererAPI.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Renderer/VertexArray.h" 6 | 7 | namespace Hazel { 8 | 9 | class RendererAPI 10 | { 11 | public: 12 | enum class API 13 | { 14 | None = 0, OpenGL = 1 15 | }; 16 | public: 17 | virtual ~RendererAPI() = default; 18 | 19 | virtual void Init() = 0; 20 | virtual void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) = 0; 21 | virtual void SetClearColor(const glm::vec4& color) = 0; 22 | virtual void Clear() = 0; 23 | 24 | virtual void DrawIndexed(const Ref& vertexArray, uint32_t indexCount = 0) = 0; 25 | 26 | static API GetAPI() { return s_API; } 27 | static Scope Create(); 28 | private: 29 | static API s_API; 30 | }; 31 | 32 | } 33 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Texture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Core/Base.h" 6 | 7 | namespace Hazel { 8 | 9 | class Texture 10 | { 11 | public: 12 | virtual ~Texture() = default; 13 | 14 | virtual uint32_t GetWidth() const = 0; 15 | virtual uint32_t GetHeight() const = 0; 16 | virtual uint32_t GetRendererID() const = 0; 17 | 18 | virtual void SetData(void* data, uint32_t size) = 0; 19 | 20 | virtual void Bind(uint32_t slot = 0) const = 0; 21 | 22 | virtual bool IsLoaded() const = 0; 23 | 24 | virtual bool operator==(const Texture& other) const = 0; 25 | }; 26 | 27 | class Texture2D : public Texture 28 | { 29 | public: 30 | static Ref Create(uint32_t width, uint32_t height); 31 | static Ref Create(const std::string& path); 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/RenderCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/RendererAPI.h" 4 | 5 | namespace Hazel { 6 | 7 | class RenderCommand 8 | { 9 | public: 10 | static void Init() 11 | { 12 | s_RendererAPI->Init(); 13 | } 14 | 15 | static void SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) 16 | { 17 | s_RendererAPI->SetViewport(x, y, width, height); 18 | } 19 | 20 | static void SetClearColor(const glm::vec4& color) 21 | { 22 | s_RendererAPI->SetClearColor(color); 23 | } 24 | 25 | static void Clear() 26 | { 27 | s_RendererAPI->Clear(); 28 | } 29 | 30 | static void DrawIndexed(const Ref& vertexArray, uint32_t count = 0) 31 | { 32 | s_RendererAPI->DrawIndexed(vertexArray, count); 33 | } 34 | private: 35 | static Scope s_RendererAPI; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Renderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/RenderCommand.h" 4 | 5 | #include "Hazel/Renderer/OrthographicCamera.h" 6 | #include "Hazel/Renderer/Shader.h" 7 | 8 | namespace Hazel { 9 | 10 | class Renderer 11 | { 12 | public: 13 | static void Init(); 14 | static void Shutdown(); 15 | 16 | static void OnWindowResize(uint32_t width, uint32_t height); 17 | 18 | static void BeginScene(OrthographicCamera& camera); 19 | static void EndScene(); 20 | 21 | static void Submit(const Ref& shader, const Ref& vertexArray, const glm::mat4& transform = glm::mat4(1.0f)); 22 | 23 | static RendererAPI::API GetAPI() { return RendererAPI::GetAPI(); } 24 | private: 25 | struct SceneData 26 | { 27 | glm::mat4 ViewProjectionMatrix; 28 | }; 29 | 30 | static Scope s_SceneData; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /Sandbox/src/ExampleLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel.h" 4 | 5 | class ExampleLayer : public Hazel::Layer 6 | { 7 | public: 8 | ExampleLayer(); 9 | virtual ~ExampleLayer() = default; 10 | 11 | virtual void OnAttach() override; 12 | virtual void OnDetach() override; 13 | 14 | void OnUpdate(Hazel::Timestep ts) override; 15 | virtual void OnImGuiRender() override; 16 | void OnEvent(Hazel::Event& e) override; 17 | private: 18 | Hazel::ShaderLibrary m_ShaderLibrary; 19 | Hazel::Ref m_Shader; 20 | Hazel::Ref m_VertexArray; 21 | 22 | Hazel::Ref m_FlatColorShader; 23 | Hazel::Ref m_SquareVA; 24 | 25 | Hazel::Ref m_Texture, m_ChernoLogoTexture; 26 | 27 | Hazel::OrthographicCameraController m_CameraController; 28 | glm::vec3 m_SquareColor = { 0.2f, 0.3f, 0.8f }; 29 | }; 30 | 31 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLVertexArray.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/VertexArray.h" 4 | 5 | namespace Hazel { 6 | 7 | class OpenGLVertexArray : public VertexArray 8 | { 9 | public: 10 | OpenGLVertexArray(); 11 | virtual ~OpenGLVertexArray(); 12 | 13 | virtual void Bind() const override; 14 | virtual void Unbind() const override; 15 | 16 | virtual void AddVertexBuffer(const Ref& vertexBuffer) override; 17 | virtual void SetIndexBuffer(const Ref& indexBuffer) override; 18 | 19 | virtual const std::vector>& GetVertexBuffers() const { return m_VertexBuffers; } 20 | virtual const Ref& GetIndexBuffer() const { return m_IndexBuffer; } 21 | private: 22 | uint32_t m_RendererID; 23 | uint32_t m_VertexBufferIndex = 0; 24 | std::vector> m_VertexBuffers; 25 | Ref m_IndexBuffer; 26 | }; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/Scene.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Timestep.h" 4 | #include "Hazel/Renderer/EditorCamera.h" 5 | 6 | #include "entt.hpp" 7 | 8 | namespace Hazel { 9 | 10 | class Entity; 11 | 12 | class Scene 13 | { 14 | public: 15 | Scene(); 16 | ~Scene(); 17 | 18 | Entity CreateEntity(const std::string& name = std::string()); 19 | void DestroyEntity(Entity entity); 20 | 21 | void OnUpdateRuntime(Timestep ts); 22 | void OnUpdateEditor(Timestep ts, EditorCamera& camera); 23 | void OnViewportResize(uint32_t width, uint32_t height); 24 | 25 | Entity GetPrimaryCameraEntity(); 26 | private: 27 | template 28 | void OnComponentAdded(Entity entity, T& component); 29 | private: 30 | entt::registry m_Registry; 31 | uint32_t m_ViewportWidth = 0, m_ViewportHeight = 0; 32 | 33 | friend class Entity; 34 | friend class SceneSerializer; 35 | friend class SceneHierarchyPanel; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /scripts/Setup.py: -------------------------------------------------------------------------------- 1 | 2 | import os 3 | import subprocess 4 | import platform 5 | 6 | from SetupPython import PythonConfiguration as PythonRequirements 7 | 8 | # Make sure everything we need for the setup is installed 9 | PythonRequirements.Validate() 10 | 11 | from SetupPremake import PremakeConfiguration as PremakeRequirements 12 | from SetupVulkan import VulkanConfiguration as VulkanRequirements 13 | os.chdir('./../') # Change from devtools/scripts directory to root 14 | 15 | premakeInstalled = PremakeRequirements.Validate() 16 | VulkanRequirements.Validate() 17 | 18 | print("\nUpdating submodules...") 19 | subprocess.call(["git", "submodule", "update", "--init", "--recursive"]) 20 | 21 | if (premakeInstalled): 22 | if platform.system() == "Windows": 23 | print("\nRunning premake...") 24 | subprocess.call([os.path.abspath("./scripts/Win-GenProjects.bat"), "nopause"]) 25 | 26 | print("\nSetup completed!") 27 | else: 28 | print("Hazel requires Premake to generate project files.") 29 | 30 | -------------------------------------------------------------------------------- /vendor/premake/premake_customization/solution_items.lua: -------------------------------------------------------------------------------- 1 | -- Implement the solution_items command for solution-scope files 2 | require('vstudio') 3 | 4 | premake.api.register { 5 | name = "solution_items", 6 | scope = "workspace", 7 | kind = "list:string", 8 | } 9 | 10 | premake.override(premake.vstudio.sln2005, "projects", function(base, wks) 11 | if wks.solution_items and #wks.solution_items > 0 then 12 | local solution_folder_GUID = "{2150E333-8FDC-42A3-9474-1A3956D46DE8}" -- See https://www.codeproject.com/Reference/720512/List-of-Visual-Studio-Project-Type-GUIDs 13 | premake.push("Project(\"" .. solution_folder_GUID .. "\") = \"Solution Items\", \"Solution Items\", \"{" .. os.uuid("Solution Items:" .. wks.name) .. "}\"") 14 | premake.push("ProjectSection(SolutionItems) = preProject") 15 | 16 | for _, path in ipairs(wks.solution_items) do 17 | premake.w(path .. " = " .. path) 18 | end 19 | 20 | premake.pop("EndProjectSection") 21 | premake.pop("EndProject") 22 | end 23 | base(wks) 24 | end) 25 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/Texture.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | #include "Platform/OpenGL/OpenGLTexture.h" 6 | 7 | namespace Hazel { 8 | 9 | Ref Texture2D::Create(uint32_t width, uint32_t height) 10 | { 11 | switch (Renderer::GetAPI()) 12 | { 13 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 14 | case RendererAPI::API::OpenGL: return CreateRef(width, height); 15 | } 16 | 17 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 18 | return nullptr; 19 | } 20 | 21 | Ref Texture2D::Create(const std::string& path) 22 | { 23 | switch (Renderer::GetAPI()) 24 | { 25 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 26 | case RendererAPI::API::OpenGL: return CreateRef(path); 27 | } 28 | 29 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 30 | return nullptr; 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | #### Describe the issue (if no issue has been made) 2 | A clear and concise description of what the issue is. Explain the difference between the expected and the current behavior. 3 | A screenshot or copy of the error could be helpful as well. 4 | 5 | #### PR impact _(Make sure to add [closing keywords](https://help.github.com/en/articles/closing-issues-using-keywords))_ 6 | List of related issues/PRs this will solve: 7 | 8 | Impact | Issue/PR 9 | ------------------------ | ------ 10 | Issues this solves | None or #number(s) 11 | Other PRs this solves | None or #number(s) 12 | 13 | #### Proposed fix _(Make sure you've read [on how to contribute](https://github.com/TheCherno/Hazel/blob/master/.github/CONTRIBUTING.md) to Hazel)_ 14 | A short description of what this fix is and how it fixed the issue you described. 15 | 16 | #### Additional context 17 | Add any other context about the solution here. Did you test the solution on all (relevant) platforms? 18 | If not, create a [task list](https://help.github.com/en/articles/about-task-lists) here. 19 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/LayerStack.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/LayerStack.h" 3 | 4 | namespace Hazel { 5 | 6 | LayerStack::~LayerStack() 7 | { 8 | for (Layer* layer : m_Layers) 9 | { 10 | layer->OnDetach(); 11 | delete layer; 12 | } 13 | } 14 | 15 | void LayerStack::PushLayer(Layer* layer) 16 | { 17 | m_Layers.emplace(m_Layers.begin() + m_LayerInsertIndex, layer); 18 | m_LayerInsertIndex++; 19 | } 20 | 21 | void LayerStack::PushOverlay(Layer* overlay) 22 | { 23 | m_Layers.emplace_back(overlay); 24 | } 25 | 26 | void LayerStack::PopLayer(Layer* layer) 27 | { 28 | auto it = std::find(m_Layers.begin(), m_Layers.begin() + m_LayerInsertIndex, layer); 29 | if (it != m_Layers.begin() + m_LayerInsertIndex) 30 | { 31 | layer->OnDetach(); 32 | m_Layers.erase(it); 33 | m_LayerInsertIndex--; 34 | } 35 | } 36 | 37 | void LayerStack::PopOverlay(Layer* overlay) 38 | { 39 | auto it = std::find(m_Layers.begin() + m_LayerInsertIndex, m_Layers.end(), overlay); 40 | if (it != m_Layers.end()) 41 | { 42 | overlay->OnDetach(); 43 | m_Layers.erase(it); 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Sandbox/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Sandbox" 2 | kind "ConsoleApp" 3 | language "C++" 4 | cppdialect "C++17" 5 | staticruntime "off" 6 | 7 | targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") 8 | objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") 9 | 10 | files 11 | { 12 | "src/**.h", 13 | "src/**.cpp" 14 | } 15 | 16 | includedirs 17 | { 18 | "%{wks.location}/Hazel/vendor/spdlog/include", 19 | "%{wks.location}/Hazel/src", 20 | "%{wks.location}/Hazel/vendor", 21 | "%{IncludeDir.glm}", 22 | "%{IncludeDir.entt}" 23 | } 24 | 25 | links 26 | { 27 | "Hazel" 28 | } 29 | 30 | filter "system:windows" 31 | systemversion "latest" 32 | 33 | filter "configurations:Debug" 34 | defines "HZ_DEBUG" 35 | runtime "Debug" 36 | symbols "on" 37 | 38 | postbuildcommands 39 | { 40 | "{COPYDIR} \"%{LibraryDir.VulkanSDK_DebugDLL}\" \"%{cfg.targetdir}\"" 41 | } 42 | 43 | filter "configurations:Release" 44 | defines "HZ_RELEASE" 45 | runtime "Release" 46 | optimize "on" 47 | 48 | filter "configurations:Dist" 49 | defines "HZ_DIST" 50 | runtime "Release" 51 | optimize "on" 52 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/issue--bug-report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 'Issue: Bug report' 3 | about: Create a report to help us improve Hazel 4 | 5 | --- 6 | 7 | #### Describe the bug 8 | A clear and concise description of what the bug is. 9 | A screenshot or copy of the error could be helpful as well. 10 | 11 | Make sure your bug can be reproduced with the Hazel Engine and not by your own engine that you're creating alongside with Hazel. For issues with your own engine, we're happy to help you in [TheCherno Discord server](https://thecherno.com/discord). Thanks for your understanding. 12 | 13 | #### To Reproduce 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error above 19 | 20 | #### Expected behavior 21 | A clear and concise description of what you expected to happen. 22 | 23 | #### Screenshots 24 | If applicable, add extra screenshots to help explain your problem. 25 | 26 | #### Operating system: (please complete the following information) 27 | - OS: [e.g. win-64] 28 | - Version: [e.g. Windows 10 home] 29 | 30 | #### Additional context 31 | Add any other context about the problem here. 32 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLBuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/Buffer.h" 4 | 5 | namespace Hazel { 6 | 7 | class OpenGLVertexBuffer : public VertexBuffer 8 | { 9 | public: 10 | OpenGLVertexBuffer(uint32_t size); 11 | OpenGLVertexBuffer(float* vertices, uint32_t size); 12 | virtual ~OpenGLVertexBuffer(); 13 | 14 | virtual void Bind() const override; 15 | virtual void Unbind() const override; 16 | 17 | virtual void SetData(const void* data, uint32_t size) override; 18 | 19 | virtual const BufferLayout& GetLayout() const override { return m_Layout; } 20 | virtual void SetLayout(const BufferLayout& layout) override { m_Layout = layout; } 21 | private: 22 | uint32_t m_RendererID; 23 | BufferLayout m_Layout; 24 | }; 25 | 26 | class OpenGLIndexBuffer : public IndexBuffer 27 | { 28 | public: 29 | OpenGLIndexBuffer(uint32_t* indices, uint32_t count); 30 | virtual ~OpenGLIndexBuffer(); 31 | 32 | virtual void Bind() const; 33 | virtual void Unbind() const; 34 | 35 | virtual uint32_t GetCount() const { return m_Count; } 36 | private: 37 | uint32_t m_RendererID; 38 | uint32_t m_Count; 39 | }; 40 | 41 | } -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLContext.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/OpenGL/OpenGLContext.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace Hazel { 8 | 9 | OpenGLContext::OpenGLContext(GLFWwindow* windowHandle) 10 | : m_WindowHandle(windowHandle) 11 | { 12 | HZ_CORE_ASSERT(windowHandle, "Window handle is null!") 13 | } 14 | 15 | void OpenGLContext::Init() 16 | { 17 | HZ_PROFILE_FUNCTION(); 18 | 19 | glfwMakeContextCurrent(m_WindowHandle); 20 | int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); 21 | HZ_CORE_ASSERT(status, "Failed to initialize Glad!"); 22 | 23 | HZ_CORE_INFO("OpenGL Info:"); 24 | HZ_CORE_INFO(" Vendor: {0}", glGetString(GL_VENDOR)); 25 | HZ_CORE_INFO(" Renderer: {0}", glGetString(GL_RENDERER)); 26 | HZ_CORE_INFO(" Version: {0}", glGetString(GL_VERSION)); 27 | 28 | HZ_CORE_ASSERT(GLVersion.major > 4 || (GLVersion.major == 4 && GLVersion.minor >= 5), "Hazel requires at least OpenGL version 4.5!"); 29 | } 30 | 31 | void OpenGLContext::SwapBuffers() 32 | { 33 | HZ_PROFILE_FUNCTION(); 34 | 35 | glfwSwapBuffers(m_WindowHandle); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLTexture.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/Texture.h" 4 | 5 | #include 6 | 7 | namespace Hazel { 8 | 9 | class OpenGLTexture2D : public Texture2D 10 | { 11 | public: 12 | OpenGLTexture2D(uint32_t width, uint32_t height); 13 | OpenGLTexture2D(const std::string& path); 14 | virtual ~OpenGLTexture2D(); 15 | 16 | virtual uint32_t GetWidth() const override { return m_Width; } 17 | virtual uint32_t GetHeight() const override { return m_Height; } 18 | virtual uint32_t GetRendererID() const override { return m_RendererID; } 19 | 20 | virtual void SetData(void* data, uint32_t size) override; 21 | 22 | virtual void Bind(uint32_t slot = 0) const override; 23 | 24 | virtual bool IsLoaded() const override { return m_IsLoaded; } 25 | 26 | virtual bool operator==(const Texture& other) const override 27 | { 28 | return m_RendererID == ((OpenGLTexture2D&)other).m_RendererID; 29 | } 30 | private: 31 | std::string m_Path; 32 | bool m_IsLoaded = false; 33 | uint32_t m_Width, m_Height; 34 | uint32_t m_RendererID; 35 | GLenum m_InternalFormat, m_DataFormat; 36 | }; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Hazel/src/Hazel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // For use by Hazel applications 4 | 5 | #include "Hazel/Core/Base.h" 6 | 7 | #include "Hazel/Core/Application.h" 8 | #include "Hazel/Core/Layer.h" 9 | #include "Hazel/Core/Log.h" 10 | #include "Hazel/Core/Assert.h" 11 | 12 | #include "Hazel/Core/Timestep.h" 13 | 14 | #include "Hazel/Core/Input.h" 15 | #include "Hazel/Core/KeyCodes.h" 16 | #include "Hazel/Core/MouseCodes.h" 17 | #include "Hazel/Renderer/OrthographicCameraController.h" 18 | 19 | #include "Hazel/ImGui/ImGuiLayer.h" 20 | 21 | #include "Hazel/Scene/Scene.h" 22 | #include "Hazel/Scene/Entity.h" 23 | #include "Hazel/Scene/ScriptableEntity.h" 24 | #include "Hazel/Scene/Components.h" 25 | 26 | // ---Renderer------------------------ 27 | #include "Hazel/Renderer/Renderer.h" 28 | #include "Hazel/Renderer/Renderer2D.h" 29 | #include "Hazel/Renderer/RenderCommand.h" 30 | 31 | #include "Hazel/Renderer/Buffer.h" 32 | #include "Hazel/Renderer/Shader.h" 33 | #include "Hazel/Renderer/Framebuffer.h" 34 | #include "Hazel/Renderer/Texture.h" 35 | #include "Hazel/Renderer/VertexArray.h" 36 | 37 | #include "Hazel/Renderer/OrthographicCamera.h" 38 | // ----------------------------------- 39 | -------------------------------------------------------------------------------- /Hazelnut/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Hazelnut" 2 | kind "ConsoleApp" 3 | language "C++" 4 | cppdialect "C++17" 5 | staticruntime "off" 6 | 7 | targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") 8 | objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") 9 | 10 | files 11 | { 12 | "src/**.h", 13 | "src/**.cpp" 14 | } 15 | 16 | includedirs 17 | { 18 | "%{wks.location}/Hazel/vendor/spdlog/include", 19 | "%{wks.location}/Hazel/src", 20 | "%{wks.location}/Hazel/vendor", 21 | "%{IncludeDir.glm}", 22 | "%{IncludeDir.entt}", 23 | "%{IncludeDir.ImGuizmo}" 24 | } 25 | 26 | links 27 | { 28 | "Hazel" 29 | } 30 | 31 | filter "system:windows" 32 | systemversion "latest" 33 | 34 | filter "configurations:Debug" 35 | defines "HZ_DEBUG" 36 | runtime "Debug" 37 | symbols "on" 38 | 39 | postbuildcommands 40 | { 41 | "{COPYDIR} \"%{LibraryDir.VulkanSDK_DebugDLL}\" \"%{cfg.targetdir}\"" 42 | } 43 | 44 | filter "configurations:Release" 45 | defines "HZ_RELEASE" 46 | runtime "Release" 47 | optimize "on" 48 | 49 | filter "configurations:Dist" 50 | defines "HZ_DIST" 51 | runtime "Release" 52 | optimize "on" 53 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/OrthographicCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace Hazel { 6 | 7 | class OrthographicCamera 8 | { 9 | public: 10 | OrthographicCamera(float left, float right, float bottom, float top); 11 | 12 | void SetProjection(float left, float right, float bottom, float top); 13 | 14 | const glm::vec3& GetPosition() const { return m_Position; } 15 | void SetPosition(const glm::vec3& position) { m_Position = position; RecalculateViewMatrix(); } 16 | 17 | float GetRotation() const { return m_Rotation; } 18 | void SetRotation(float rotation) { m_Rotation = rotation; RecalculateViewMatrix(); } 19 | 20 | const glm::mat4& GetProjectionMatrix() const { return m_ProjectionMatrix; } 21 | const glm::mat4& GetViewMatrix() const { return m_ViewMatrix; } 22 | const glm::mat4& GetViewProjectionMatrix() const { return m_ViewProjectionMatrix; } 23 | private: 24 | void RecalculateViewMatrix(); 25 | private: 26 | glm::mat4 m_ProjectionMatrix; 27 | glm::mat4 m_ViewMatrix; 28 | glm::mat4 m_ViewProjectionMatrix; 29 | 30 | glm::vec3 m_Position = { 0.0f, 0.0f, 0.0f }; 31 | float m_Rotation = 0.0f; 32 | }; 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Hazel/vendor/entt/LICENSE.txt: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017-2020 Michele Caini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copy of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copy or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/OrthographicCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/OrthographicCamera.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | OrthographicCamera::OrthographicCamera(float left, float right, float bottom, float top) 9 | : m_ProjectionMatrix(glm::ortho(left, right, bottom, top, -1.0f, 1.0f)), m_ViewMatrix(1.0f) 10 | { 11 | HZ_PROFILE_FUNCTION(); 12 | 13 | m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; 14 | } 15 | 16 | void OrthographicCamera::SetProjection(float left, float right, float bottom, float top) 17 | { 18 | HZ_PROFILE_FUNCTION(); 19 | 20 | m_ProjectionMatrix = glm::ortho(left, right, bottom, top, -1.0f, 1.0f); 21 | m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; 22 | } 23 | 24 | void OrthographicCamera::RecalculateViewMatrix() 25 | { 26 | HZ_PROFILE_FUNCTION(); 27 | 28 | glm::mat4 transform = glm::translate(glm::mat4(1.0f), m_Position) * 29 | glm::rotate(glm::mat4(1.0f), glm::radians(m_Rotation), glm::vec3(0, 0, 1)); 30 | 31 | m_ViewMatrix = glm::inverse(transform); 32 | m_ViewProjectionMatrix = m_ProjectionMatrix * m_ViewMatrix; 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/LayerStack.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | #include "Hazel/Core/Layer.h" 5 | 6 | #include 7 | 8 | namespace Hazel { 9 | 10 | class LayerStack 11 | { 12 | public: 13 | LayerStack() = default; 14 | ~LayerStack(); 15 | 16 | void PushLayer(Layer* layer); 17 | void PushOverlay(Layer* overlay); 18 | void PopLayer(Layer* layer); 19 | void PopOverlay(Layer* overlay); 20 | 21 | std::vector::iterator begin() { return m_Layers.begin(); } 22 | std::vector::iterator end() { return m_Layers.end(); } 23 | std::vector::reverse_iterator rbegin() { return m_Layers.rbegin(); } 24 | std::vector::reverse_iterator rend() { return m_Layers.rend(); } 25 | 26 | std::vector::const_iterator begin() const { return m_Layers.begin(); } 27 | std::vector::const_iterator end() const { return m_Layers.end(); } 28 | std::vector::const_reverse_iterator rbegin() const { return m_Layers.rbegin(); } 29 | std::vector::const_reverse_iterator rend() const { return m_Layers.rend(); } 30 | private: 31 | std::vector m_Layers; 32 | unsigned int m_LayerInsertIndex = 0; 33 | }; 34 | 35 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Window.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Core/Base.h" 6 | #include "Hazel/Events/Event.h" 7 | 8 | namespace Hazel { 9 | 10 | struct WindowProps 11 | { 12 | std::string Title; 13 | uint32_t Width; 14 | uint32_t Height; 15 | 16 | WindowProps(const std::string& title = "Hazel Engine", 17 | uint32_t width = 1600, 18 | uint32_t height = 900) 19 | : Title(title), Width(width), Height(height) 20 | { 21 | } 22 | }; 23 | 24 | // Interface representing a desktop system based Window 25 | class Window 26 | { 27 | public: 28 | using EventCallbackFn = std::function; 29 | 30 | virtual ~Window() = default; 31 | 32 | virtual void OnUpdate() = 0; 33 | 34 | virtual uint32_t GetWidth() const = 0; 35 | virtual uint32_t GetHeight() const = 0; 36 | 37 | // Window attributes 38 | virtual void SetEventCallback(const EventCallbackFn& callback) = 0; 39 | virtual void SetVSync(bool enabled) = 0; 40 | virtual bool IsVSync() const = 0; 41 | 42 | virtual void* GetNativeWindow() const = 0; 43 | 44 | static Scope Create(const WindowProps& props = WindowProps()); 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Log.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/Log.h" 3 | 4 | #include 5 | #include 6 | 7 | namespace Hazel { 8 | 9 | Ref Log::s_CoreLogger; 10 | Ref Log::s_ClientLogger; 11 | 12 | void Log::Init() 13 | { 14 | std::vector logSinks; 15 | logSinks.emplace_back(std::make_shared()); 16 | logSinks.emplace_back(std::make_shared("Hazel.log", true)); 17 | 18 | logSinks[0]->set_pattern("%^[%T] %n: %v%$"); 19 | logSinks[1]->set_pattern("[%T] [%l] %n: %v"); 20 | 21 | s_CoreLogger = std::make_shared("HAZEL", begin(logSinks), end(logSinks)); 22 | spdlog::register_logger(s_CoreLogger); 23 | s_CoreLogger->set_level(spdlog::level::trace); 24 | s_CoreLogger->flush_on(spdlog::level::trace); 25 | 26 | s_ClientLogger = std::make_shared("APP", begin(logSinks), end(logSinks)); 27 | spdlog::register_logger(s_ClientLogger); 28 | s_ClientLogger->set_level(spdlog::level::trace); 29 | s_ClientLogger->flush_on(spdlog::level::trace); 30 | } 31 | 32 | } 33 | 34 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Renderer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/Renderer.h" 3 | #include "Hazel/Renderer/Renderer2D.h" 4 | 5 | namespace Hazel { 6 | 7 | Scope Renderer::s_SceneData = CreateScope(); 8 | 9 | void Renderer::Init() 10 | { 11 | HZ_PROFILE_FUNCTION(); 12 | 13 | RenderCommand::Init(); 14 | Renderer2D::Init(); 15 | } 16 | 17 | void Renderer::Shutdown() 18 | { 19 | Renderer2D::Shutdown(); 20 | } 21 | 22 | void Renderer::OnWindowResize(uint32_t width, uint32_t height) 23 | { 24 | RenderCommand::SetViewport(0, 0, width, height); 25 | } 26 | 27 | void Renderer::BeginScene(OrthographicCamera& camera) 28 | { 29 | s_SceneData->ViewProjectionMatrix = camera.GetViewProjectionMatrix(); 30 | } 31 | 32 | void Renderer::EndScene() 33 | { 34 | } 35 | 36 | void Renderer::Submit(const Ref& shader, const Ref& vertexArray, const glm::mat4& transform) 37 | { 38 | shader->Bind(); 39 | shader->SetMat4("u_ViewProjection", s_SceneData->ViewProjectionMatrix); 40 | shader->SetMat4("u_Transform", transform); 41 | 42 | vertexArray->Bind(); 43 | RenderCommand::DrawIndexed(vertexArray); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Hazel/src/Platform/Windows/WindowsWindow.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Window.h" 4 | #include "Hazel/Renderer/GraphicsContext.h" 5 | 6 | #include 7 | 8 | namespace Hazel { 9 | 10 | class WindowsWindow : public Window 11 | { 12 | public: 13 | WindowsWindow(const WindowProps& props); 14 | virtual ~WindowsWindow(); 15 | 16 | void OnUpdate() override; 17 | 18 | unsigned int GetWidth() const override { return m_Data.Width; } 19 | unsigned int GetHeight() const override { return m_Data.Height; } 20 | 21 | // Window attributes 22 | void SetEventCallback(const EventCallbackFn& callback) override { m_Data.EventCallback = callback; } 23 | void SetVSync(bool enabled) override; 24 | bool IsVSync() const override; 25 | 26 | virtual void* GetNativeWindow() const { return m_Window; } 27 | private: 28 | virtual void Init(const WindowProps& props); 29 | virtual void Shutdown(); 30 | private: 31 | GLFWwindow* m_Window; 32 | Scope m_Context; 33 | 34 | struct WindowData 35 | { 36 | std::string Title; 37 | unsigned int Width, Height; 38 | bool VSync; 39 | 40 | EventCallbackFn EventCallback; 41 | }; 42 | 43 | WindowData m_Data; 44 | }; 45 | 46 | } -------------------------------------------------------------------------------- /Hazel/src/Platform/Windows/WindowsInput.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/Input.h" 3 | 4 | #include "Hazel/Core/Application.h" 5 | #include 6 | 7 | namespace Hazel { 8 | 9 | bool Input::IsKeyPressed(const KeyCode key) 10 | { 11 | auto* window = static_cast(Application::Get().GetWindow().GetNativeWindow()); 12 | auto state = glfwGetKey(window, static_cast(key)); 13 | return state == GLFW_PRESS || state == GLFW_REPEAT; 14 | } 15 | 16 | bool Input::IsMouseButtonPressed(const MouseCode button) 17 | { 18 | auto* window = static_cast(Application::Get().GetWindow().GetNativeWindow()); 19 | auto state = glfwGetMouseButton(window, static_cast(button)); 20 | return state == GLFW_PRESS; 21 | } 22 | 23 | glm::vec2 Input::GetMousePosition() 24 | { 25 | auto* window = static_cast(Application::Get().GetWindow().GetNativeWindow()); 26 | double xpos, ypos; 27 | glfwGetCursorPos(window, &xpos, &ypos); 28 | 29 | return { (float)xpos, (float)ypos }; 30 | } 31 | 32 | float Input::GetMouseX() 33 | { 34 | return GetMousePosition().x; 35 | } 36 | 37 | float Input::GetMouseY() 38 | { 39 | return GetMousePosition().y; 40 | } 41 | 42 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/OrthographicCameraController.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/OrthographicCamera.h" 4 | #include "Hazel/Core/Timestep.h" 5 | 6 | #include "Hazel/Events/ApplicationEvent.h" 7 | #include "Hazel/Events/MouseEvent.h" 8 | 9 | namespace Hazel { 10 | 11 | class OrthographicCameraController 12 | { 13 | public: 14 | OrthographicCameraController(float aspectRatio, bool rotation = false); 15 | 16 | void OnUpdate(Timestep ts); 17 | void OnEvent(Event& e); 18 | 19 | void OnResize(float width, float height); 20 | 21 | OrthographicCamera& GetCamera() { return m_Camera; } 22 | const OrthographicCamera& GetCamera() const { return m_Camera; } 23 | 24 | float GetZoomLevel() const { return m_ZoomLevel; } 25 | void SetZoomLevel(float level) { m_ZoomLevel = level; } 26 | private: 27 | bool OnMouseScrolled(MouseScrolledEvent& e); 28 | bool OnWindowResized(WindowResizeEvent& e); 29 | private: 30 | float m_AspectRatio; 31 | float m_ZoomLevel = 1.0f; 32 | OrthographicCamera m_Camera; 33 | 34 | bool m_Rotation; 35 | 36 | glm::vec3 m_CameraPosition = { 0.0f, 0.0f, 0.0f }; 37 | float m_CameraRotation = 0.0f; //In degrees, in the anti-clockwise direction 38 | float m_CameraTranslationSpeed = 5.0f, m_CameraRotationSpeed = 180.0f; 39 | }; 40 | 41 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Base.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "Hazel/Core/PlatformDetection.h" 6 | 7 | #ifdef HZ_DEBUG 8 | #if defined(HZ_PLATFORM_WINDOWS) 9 | #define HZ_DEBUGBREAK() __debugbreak() 10 | #elif defined(HZ_PLATFORM_LINUX) 11 | #include 12 | #define HZ_DEBUGBREAK() raise(SIGTRAP) 13 | #else 14 | #error "Platform doesn't support debugbreak yet!" 15 | #endif 16 | #define HZ_ENABLE_ASSERTS 17 | #else 18 | #define HZ_DEBUGBREAK() 19 | #endif 20 | 21 | #define HZ_EXPAND_MACRO(x) x 22 | #define HZ_STRINGIFY_MACRO(x) #x 23 | 24 | #define BIT(x) (1 << x) 25 | 26 | #define HZ_BIND_EVENT_FN(fn) [this](auto&&... args) -> decltype(auto) { return this->fn(std::forward(args)...); } 27 | 28 | namespace Hazel { 29 | 30 | template 31 | using Scope = std::unique_ptr; 32 | template 33 | constexpr Scope CreateScope(Args&& ... args) 34 | { 35 | return std::make_unique(std::forward(args)...); 36 | } 37 | 38 | template 39 | using Ref = std::shared_ptr; 40 | template 41 | constexpr Ref CreateRef(Args&& ... args) 42 | { 43 | return std::make_shared(std::forward(args)...); 44 | } 45 | 46 | } 47 | 48 | #include "Hazel/Core/Log.h" 49 | #include "Hazel/Core/Assert.h" 50 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLFramebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/Framebuffer.h" 4 | 5 | namespace Hazel { 6 | 7 | class OpenGLFramebuffer : public Framebuffer 8 | { 9 | public: 10 | OpenGLFramebuffer(const FramebufferSpecification& spec); 11 | virtual ~OpenGLFramebuffer(); 12 | 13 | void Invalidate(); 14 | 15 | virtual void Bind() override; 16 | virtual void Unbind() override; 17 | 18 | virtual void Resize(uint32_t width, uint32_t height) override; 19 | virtual int ReadPixel(uint32_t attachmentIndex, int x, int y) override; 20 | 21 | virtual void ClearAttachment(uint32_t attachmentIndex, int value) override; 22 | 23 | virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const override { HZ_CORE_ASSERT(index < m_ColorAttachments.size()); return m_ColorAttachments[index]; } 24 | 25 | virtual const FramebufferSpecification& GetSpecification() const override { return m_Specification; } 26 | private: 27 | uint32_t m_RendererID = 0; 28 | FramebufferSpecification m_Specification; 29 | 30 | std::vector m_ColorAttachmentSpecifications; 31 | FramebufferTextureSpecification m_DepthAttachmentSpecification = FramebufferTextureFormat::None; 32 | 33 | std::vector m_ColorAttachments; 34 | uint32_t m_DepthAttachment = 0; 35 | }; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/PlatformDetection.h: -------------------------------------------------------------------------------- 1 | // Platform detection using predefined macros 2 | #ifdef _WIN32 3 | /* Windows x64/x86 */ 4 | #ifdef _WIN64 5 | /* Windows x64 */ 6 | #define HZ_PLATFORM_WINDOWS 7 | #else 8 | /* Windows x86 */ 9 | #error "x86 Builds are not supported!" 10 | #endif 11 | #elif defined(__APPLE__) || defined(__MACH__) 12 | #include 13 | /* TARGET_OS_MAC exists on all the platforms 14 | * so we must check all of them (in this order) 15 | * to ensure that we're running on MAC 16 | * and not some other Apple platform */ 17 | #if TARGET_IPHONE_SIMULATOR == 1 18 | #error "IOS simulator is not supported!" 19 | #elif TARGET_OS_IPHONE == 1 20 | #define HZ_PLATFORM_IOS 21 | #error "IOS is not supported!" 22 | #elif TARGET_OS_MAC == 1 23 | #define HZ_PLATFORM_MACOS 24 | #error "MacOS is not supported!" 25 | #else 26 | #error "Unknown Apple platform!" 27 | #endif 28 | /* We also have to check __ANDROID__ before __linux__ 29 | * since android is based on the linux kernel 30 | * it has __linux__ defined */ 31 | #elif defined(__ANDROID__) 32 | #define HZ_PLATFORM_ANDROID 33 | #error "Android is not supported!" 34 | #elif defined(__linux__) 35 | #define HZ_PLATFORM_LINUX 36 | #error "Linux is not supported!" 37 | #else 38 | /* Unknown compiler/platform */ 39 | #error "Unknown platform!" 40 | #endif // End of platform detection 41 | -------------------------------------------------------------------------------- /Hazelnut/assets/scenes/PinkCube.hazel: -------------------------------------------------------------------------------- 1 | Scene: Untitled 2 | Entities: 3 | - Entity: 12837192831273 4 | TagComponent: 5 | Tag: Top 6 | TransformComponent: 7 | Translation: [0, 0.5, 0] 8 | Rotation: [1.57079637, 0.785398185, 0] 9 | Scale: [1, 1, 1] 10 | SpriteRendererComponent: 11 | Color: [0.876447856, 0, 0.834712803, 1] 12 | - Entity: 12837192831273 13 | TagComponent: 14 | Tag: Camera 15 | TransformComponent: 16 | Translation: [0, 1.70000005, 4] 17 | Rotation: [-0.404916406, 0, 0] 18 | Scale: [1, 1, 1] 19 | CameraComponent: 20 | Camera: 21 | ProjectionType: 0 22 | PerspectiveFOV: 0.52359879 23 | PerspectiveNear: 0.00999999978 24 | PerspectiveFar: 1000 25 | OrthographicSize: 10 26 | OrthographicNear: -1 27 | OrthographicFar: 1 28 | Primary: true 29 | FixedAspectRatio: false 30 | - Entity: 12837192831273 31 | TagComponent: 32 | Tag: Right 33 | TransformComponent: 34 | Translation: [0.351999998, 0, 0.349999994] 35 | Rotation: [0, 0.785398185, 0] 36 | Scale: [1, 1, 1] 37 | SpriteRendererComponent: 38 | Color: [0.54842025, 0, 0.586872578, 1] 39 | - Entity: 12837192831273 40 | TagComponent: 41 | Tag: Left 42 | TransformComponent: 43 | Translation: [-0.354999989, 0, 0.349999994] 44 | Rotation: [0, -0.785398185, 0] 45 | Scale: [1, 1, 1] 46 | SpriteRendererComponent: 47 | Color: [1, 0, 0.949807167, 1] -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Buffer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/Buffer.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | 6 | #include "Platform/OpenGL/OpenGLBuffer.h" 7 | 8 | namespace Hazel { 9 | 10 | Ref VertexBuffer::Create(uint32_t size) 11 | { 12 | switch (Renderer::GetAPI()) 13 | { 14 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 15 | case RendererAPI::API::OpenGL: return CreateRef(size); 16 | } 17 | 18 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 19 | return nullptr; 20 | } 21 | 22 | Ref VertexBuffer::Create(float* vertices, uint32_t size) 23 | { 24 | switch (Renderer::GetAPI()) 25 | { 26 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 27 | case RendererAPI::API::OpenGL: return CreateRef(vertices, size); 28 | } 29 | 30 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 31 | return nullptr; 32 | } 33 | 34 | Ref IndexBuffer::Create(uint32_t* indices, uint32_t size) 35 | { 36 | switch (Renderer::GetAPI()) 37 | { 38 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 39 | case RendererAPI::API::OpenGL: return CreateRef(indices, size); 40 | } 41 | 42 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 43 | return nullptr; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Assert.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | #include "Hazel/Core/Log.h" 5 | #include 6 | 7 | #ifdef HZ_ENABLE_ASSERTS 8 | 9 | // Alteratively we could use the same "default" message for both "WITH_MSG" and "NO_MSG" and 10 | // provide support for custom formatting by concatenating the formatting string instead of having the format inside the default message 11 | #define HZ_INTERNAL_ASSERT_IMPL(type, check, msg, ...) { if(!(check)) { HZ##type##ERROR(msg, __VA_ARGS__); HZ_DEBUGBREAK(); } } 12 | #define HZ_INTERNAL_ASSERT_WITH_MSG(type, check, ...) HZ_INTERNAL_ASSERT_IMPL(type, check, "Assertion failed: {0}", __VA_ARGS__) 13 | #define HZ_INTERNAL_ASSERT_NO_MSG(type, check) HZ_INTERNAL_ASSERT_IMPL(type, check, "Assertion '{0}' failed at {1}:{2}", HZ_STRINGIFY_MACRO(check), std::filesystem::path(__FILE__).filename().string(), __LINE__) 14 | 15 | #define HZ_INTERNAL_ASSERT_GET_MACRO_NAME(arg1, arg2, macro, ...) macro 16 | #define HZ_INTERNAL_ASSERT_GET_MACRO(...) HZ_EXPAND_MACRO( HZ_INTERNAL_ASSERT_GET_MACRO_NAME(__VA_ARGS__, HZ_INTERNAL_ASSERT_WITH_MSG, HZ_INTERNAL_ASSERT_NO_MSG) ) 17 | 18 | // Currently accepts at least the condition and one additional parameter (the message) being optional 19 | #define HZ_ASSERT(...) HZ_EXPAND_MACRO( HZ_INTERNAL_ASSERT_GET_MACRO(__VA_ARGS__)(_, __VA_ARGS__) ) 20 | #define HZ_CORE_ASSERT(...) HZ_EXPAND_MACRO( HZ_INTERNAL_ASSERT_GET_MACRO(__VA_ARGS__)(_CORE_, __VA_ARGS__) ) 21 | #else 22 | #define HZ_ASSERT(...) 23 | #define HZ_CORE_ASSERT(...) 24 | #endif 25 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Events/ApplicationEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Events/Event.h" 4 | 5 | namespace Hazel { 6 | 7 | class WindowResizeEvent : public Event 8 | { 9 | public: 10 | WindowResizeEvent(unsigned int width, unsigned int height) 11 | : m_Width(width), m_Height(height) {} 12 | 13 | unsigned int GetWidth() const { return m_Width; } 14 | unsigned int GetHeight() const { return m_Height; } 15 | 16 | std::string ToString() const override 17 | { 18 | std::stringstream ss; 19 | ss << "WindowResizeEvent: " << m_Width << ", " << m_Height; 20 | return ss.str(); 21 | } 22 | 23 | EVENT_CLASS_TYPE(WindowResize) 24 | EVENT_CLASS_CATEGORY(EventCategoryApplication) 25 | private: 26 | unsigned int m_Width, m_Height; 27 | }; 28 | 29 | class WindowCloseEvent : public Event 30 | { 31 | public: 32 | WindowCloseEvent() = default; 33 | 34 | EVENT_CLASS_TYPE(WindowClose) 35 | EVENT_CLASS_CATEGORY(EventCategoryApplication) 36 | }; 37 | 38 | class AppTickEvent : public Event 39 | { 40 | public: 41 | AppTickEvent() = default; 42 | 43 | EVENT_CLASS_TYPE(AppTick) 44 | EVENT_CLASS_CATEGORY(EventCategoryApplication) 45 | }; 46 | 47 | class AppUpdateEvent : public Event 48 | { 49 | public: 50 | AppUpdateEvent() = default; 51 | 52 | EVENT_CLASS_TYPE(AppUpdate) 53 | EVENT_CLASS_CATEGORY(EventCategoryApplication) 54 | }; 55 | 56 | class AppRenderEvent : public Event 57 | { 58 | public: 59 | AppRenderEvent() = default; 60 | 61 | EVENT_CLASS_TYPE(AppRender) 62 | EVENT_CLASS_CATEGORY(EventCategoryApplication) 63 | }; 64 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Shader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace Hazel { 9 | 10 | class Shader 11 | { 12 | public: 13 | virtual ~Shader() = default; 14 | 15 | virtual void Bind() const = 0; 16 | virtual void Unbind() const = 0; 17 | 18 | virtual void SetInt(const std::string& name, int value) = 0; 19 | virtual void SetIntArray(const std::string& name, int* values, uint32_t count) = 0; 20 | virtual void SetFloat(const std::string& name, float value) = 0; 21 | virtual void SetFloat2(const std::string& name, const glm::vec2& value) = 0; 22 | virtual void SetFloat3(const std::string& name, const glm::vec3& value) = 0; 23 | virtual void SetFloat4(const std::string& name, const glm::vec4& value) = 0; 24 | virtual void SetMat4(const std::string& name, const glm::mat4& value) = 0; 25 | 26 | virtual const std::string& GetName() const = 0; 27 | 28 | static Ref Create(const std::string& filepath); 29 | static Ref Create(const std::string& name, const std::string& vertexSrc, const std::string& fragmentSrc); 30 | }; 31 | 32 | class ShaderLibrary 33 | { 34 | public: 35 | void Add(const std::string& name, const Ref& shader); 36 | void Add(const Ref& shader); 37 | Ref Load(const std::string& filepath); 38 | Ref Load(const std::string& name, const std::string& filepath); 39 | 40 | Ref Get(const std::string& name); 41 | 42 | bool Exists(const std::string& name) const; 43 | private: 44 | std::unordered_map> m_Shaders; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /Hazelnut/assets/scenes/Example.hazel: -------------------------------------------------------------------------------- 1 | Scene: Untitled 2 | Entities: 3 | - Entity: 12837192831273 4 | TagComponent: 5 | Tag: Camera B 6 | TransformComponent: 7 | Translation: [0, 0, 0] 8 | Rotation: [0, 0, 0] 9 | Scale: [1, 1, 1] 10 | CameraComponent: 11 | Camera: 12 | ProjectionType: 1 13 | PerspectiveFOV: 0.785398185 14 | PerspectiveNear: 0.00999999978 15 | PerspectiveFar: 1000 16 | OrthographicSize: 10 17 | OrthographicNear: -1 18 | OrthographicFar: 1 19 | Primary: false 20 | FixedAspectRatio: false 21 | - Entity: 12837192831273 22 | TagComponent: 23 | Tag: Camera A 24 | TransformComponent: 25 | Translation: [0, 0, 0] 26 | Rotation: [0, 0, 0] 27 | Scale: [1, 1, 1] 28 | CameraComponent: 29 | Camera: 30 | ProjectionType: 1 31 | PerspectiveFOV: 0.785398185 32 | PerspectiveNear: 0.00999999978 33 | PerspectiveFar: 1000 34 | OrthographicSize: 10 35 | OrthographicNear: -1 36 | OrthographicFar: 1 37 | Primary: true 38 | FixedAspectRatio: false 39 | - Entity: 12837192831273 40 | TagComponent: 41 | Tag: Red Square 42 | TransformComponent: 43 | Translation: [0, 1.10000002, 0] 44 | Rotation: [0, 0, 0] 45 | Scale: [1, 1, 1] 46 | SpriteRendererComponent: 47 | Color: [1, 0, 0, 1] 48 | - Entity: 12837192831273 49 | TagComponent: 50 | Tag: Green Square 51 | TransformComponent: 52 | Translation: [2.4000001, 0, 0] 53 | Rotation: [0, 0, 0] 54 | Scale: [1, 1, 1] 55 | SpriteRendererComponent: 56 | Color: [0, 1, 0, 1] -------------------------------------------------------------------------------- /Hazelnut/assets/scenes/3DExample.hazel: -------------------------------------------------------------------------------- 1 | Scene: Untitled 2 | Entities: 3 | - Entity: 12837192831273 4 | TagComponent: 5 | Tag: Green Square 6 | TransformComponent: 7 | Translation: [2.4000001, 0, -4.80000019] 8 | Rotation: [0, 0, 0] 9 | Scale: [1, 1, 1] 10 | SpriteRendererComponent: 11 | Color: [0, 1, 0, 1] 12 | - Entity: 12837192831273 13 | TagComponent: 14 | Tag: Red Square 15 | TransformComponent: 16 | Translation: [0, 1.10000002, 0] 17 | Rotation: [0, 0, 0] 18 | Scale: [1, 1, 1] 19 | SpriteRendererComponent: 20 | Color: [1, 0, 0, 1] 21 | - Entity: 12837192831273 22 | TagComponent: 23 | Tag: Camera A 24 | TransformComponent: 25 | Translation: [0, 0, 0] 26 | Rotation: [0, 0, 0] 27 | Scale: [1, 1, 1] 28 | CameraComponent: 29 | Camera: 30 | ProjectionType: 1 31 | PerspectiveFOV: 0.785398185 32 | PerspectiveNear: 0.00999999978 33 | PerspectiveFar: 1000 34 | OrthographicSize: 10 35 | OrthographicNear: -1 36 | OrthographicFar: 1 37 | Primary: false 38 | FixedAspectRatio: false 39 | - Entity: 12837192831273 40 | TagComponent: 41 | Tag: Camera B 42 | TransformComponent: 43 | Translation: [0.899999976, 0, 6] 44 | Rotation: [0, 0, 0] 45 | Scale: [1, 1, 1] 46 | CameraComponent: 47 | Camera: 48 | ProjectionType: 0 49 | PerspectiveFOV: 0.785398185 50 | PerspectiveNear: 0.00999999978 51 | PerspectiveFar: 1000 52 | OrthographicSize: 10 53 | OrthographicNear: -1 54 | OrthographicFar: 1 55 | Primary: true 56 | FixedAspectRatio: false -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/SceneCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "SceneCamera.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | SceneCamera::SceneCamera() 9 | { 10 | RecalculateProjection(); 11 | } 12 | 13 | void SceneCamera::SetPerspective(float verticalFOV, float nearClip, float farClip) 14 | { 15 | m_ProjectionType = ProjectionType::Perspective; 16 | m_PerspectiveFOV = verticalFOV; 17 | m_PerspectiveNear = nearClip; 18 | m_PerspectiveFar = farClip; 19 | RecalculateProjection(); 20 | } 21 | 22 | void SceneCamera::SetOrthographic(float size, float nearClip, float farClip) 23 | { 24 | m_ProjectionType = ProjectionType::Orthographic; 25 | m_OrthographicSize = size; 26 | m_OrthographicNear = nearClip; 27 | m_OrthographicFar = farClip; 28 | RecalculateProjection(); 29 | } 30 | 31 | void SceneCamera::SetViewportSize(uint32_t width, uint32_t height) 32 | { 33 | HZ_CORE_ASSERT(width > 0 && height > 0); 34 | m_AspectRatio = (float)width / (float)height; 35 | RecalculateProjection(); 36 | } 37 | 38 | void SceneCamera::RecalculateProjection() 39 | { 40 | if (m_ProjectionType == ProjectionType::Perspective) 41 | { 42 | m_Projection = glm::perspective(m_PerspectiveFOV, m_AspectRatio, m_PerspectiveNear, m_PerspectiveFar); 43 | } 44 | else 45 | { 46 | float orthoLeft = -m_OrthographicSize * m_AspectRatio * 0.5f; 47 | float orthoRight = m_OrthographicSize * m_AspectRatio * 0.5f; 48 | float orthoBottom = -m_OrthographicSize * 0.5f; 49 | float orthoTop = m_OrthographicSize * 0.5f; 50 | 51 | m_Projection = glm::ortho(orthoLeft, orthoRight, 52 | orthoBottom, orthoTop, m_OrthographicNear, m_OrthographicFar); 53 | } 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Events/KeyEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Events/Event.h" 4 | #include "Hazel/Core/KeyCodes.h" 5 | 6 | namespace Hazel { 7 | 8 | class KeyEvent : public Event 9 | { 10 | public: 11 | KeyCode GetKeyCode() const { return m_KeyCode; } 12 | 13 | EVENT_CLASS_CATEGORY(EventCategoryKeyboard | EventCategoryInput) 14 | protected: 15 | KeyEvent(const KeyCode keycode) 16 | : m_KeyCode(keycode) {} 17 | 18 | KeyCode m_KeyCode; 19 | }; 20 | 21 | class KeyPressedEvent : public KeyEvent 22 | { 23 | public: 24 | KeyPressedEvent(const KeyCode keycode, const uint16_t repeatCount) 25 | : KeyEvent(keycode), m_RepeatCount(repeatCount) {} 26 | 27 | uint16_t GetRepeatCount() const { return m_RepeatCount; } 28 | 29 | std::string ToString() const override 30 | { 31 | std::stringstream ss; 32 | ss << "KeyPressedEvent: " << m_KeyCode << " (" << m_RepeatCount << " repeats)"; 33 | return ss.str(); 34 | } 35 | 36 | EVENT_CLASS_TYPE(KeyPressed) 37 | private: 38 | uint16_t m_RepeatCount; 39 | }; 40 | 41 | class KeyReleasedEvent : public KeyEvent 42 | { 43 | public: 44 | KeyReleasedEvent(const KeyCode keycode) 45 | : KeyEvent(keycode) {} 46 | 47 | std::string ToString() const override 48 | { 49 | std::stringstream ss; 50 | ss << "KeyReleasedEvent: " << m_KeyCode; 51 | return ss.str(); 52 | } 53 | 54 | EVENT_CLASS_TYPE(KeyReleased) 55 | }; 56 | 57 | class KeyTypedEvent : public KeyEvent 58 | { 59 | public: 60 | KeyTypedEvent(const KeyCode keycode) 61 | : KeyEvent(keycode) {} 62 | 63 | std::string ToString() const override 64 | { 65 | std::stringstream ss; 66 | ss << "KeyTypedEvent: " << m_KeyCode; 67 | return ss.str(); 68 | } 69 | 70 | EVENT_CLASS_TYPE(KeyTyped) 71 | }; 72 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/Entity.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Scene.h" 4 | 5 | #include "entt.hpp" 6 | 7 | namespace Hazel { 8 | 9 | class Entity 10 | { 11 | public: 12 | Entity() = default; 13 | Entity(entt::entity handle, Scene* scene); 14 | Entity(const Entity& other) = default; 15 | 16 | template 17 | T& AddComponent(Args&&... args) 18 | { 19 | HZ_CORE_ASSERT(!HasComponent(), "Entity already has component!"); 20 | T& component = m_Scene->m_Registry.emplace(m_EntityHandle, std::forward(args)...); 21 | m_Scene->OnComponentAdded(*this, component); 22 | return component; 23 | } 24 | 25 | template 26 | T& GetComponent() 27 | { 28 | HZ_CORE_ASSERT(HasComponent(), "Entity does not have component!"); 29 | return m_Scene->m_Registry.get(m_EntityHandle); 30 | } 31 | 32 | template 33 | bool HasComponent() 34 | { 35 | return m_Scene->m_Registry.has(m_EntityHandle); 36 | } 37 | 38 | template 39 | void RemoveComponent() 40 | { 41 | HZ_CORE_ASSERT(HasComponent(), "Entity does not have component!"); 42 | m_Scene->m_Registry.remove(m_EntityHandle); 43 | } 44 | 45 | operator bool() const { return m_EntityHandle != entt::null; } 46 | operator entt::entity() const { return m_EntityHandle; } 47 | operator uint32_t() const { return (uint32_t)m_EntityHandle; } 48 | 49 | bool operator==(const Entity& other) const 50 | { 51 | return m_EntityHandle == other.m_EntityHandle && m_Scene == other.m_Scene; 52 | } 53 | 54 | bool operator!=(const Entity& other) const 55 | { 56 | return !(*this == other); 57 | } 58 | private: 59 | entt::entity m_EntityHandle{ entt::null }; 60 | Scene* m_Scene = nullptr; 61 | }; 62 | 63 | } 64 | -------------------------------------------------------------------------------- /Dependencies.lua: -------------------------------------------------------------------------------- 1 | 2 | -- Hazel Dependencies 3 | 4 | VULKAN_SDK = os.getenv("VULKAN_SDK") 5 | 6 | IncludeDir = {} 7 | IncludeDir["stb_image"] = "%{wks.location}/Hazel/vendor/stb_image" 8 | IncludeDir["yaml_cpp"] = "%{wks.location}/Hazel/vendor/yaml-cpp/include" 9 | IncludeDir["GLFW"] = "%{wks.location}/Hazel/vendor/GLFW/include" 10 | IncludeDir["Glad"] = "%{wks.location}/Hazel/vendor/Glad/include" 11 | IncludeDir["ImGui"] = "%{wks.location}/Hazel/vendor/ImGui" 12 | IncludeDir["ImGuizmo"] = "%{wks.location}/Hazel/vendor/ImGuizmo" 13 | IncludeDir["glm"] = "%{wks.location}/Hazel/vendor/glm" 14 | IncludeDir["entt"] = "%{wks.location}/Hazel/vendor/entt/include" 15 | IncludeDir["shaderc"] = "%{wks.location}/Hazel/vendor/shaderc/include" 16 | IncludeDir["SPIRV_Cross"] = "%{wks.location}/Hazel/vendor/SPIRV-Cross" 17 | IncludeDir["VulkanSDK"] = "%{VULKAN_SDK}/Include" 18 | 19 | LibraryDir = {} 20 | 21 | LibraryDir["VulkanSDK"] = "%{VULKAN_SDK}/Lib" 22 | LibraryDir["VulkanSDK_Debug"] = "%{wks.location}/Hazel/vendor/VulkanSDK/Lib" 23 | LibraryDir["VulkanSDK_DebugDLL"] = "%{wks.location}/Hazel/vendor/VulkanSDK/Bin" 24 | 25 | Library = {} 26 | Library["Vulkan"] = "%{LibraryDir.VulkanSDK}/vulkan-1.lib" 27 | Library["VulkanUtils"] = "%{LibraryDir.VulkanSDK}/VkLayer_utils.lib" 28 | 29 | Library["ShaderC_Debug"] = "%{LibraryDir.VulkanSDK_Debug}/shaderc_sharedd.lib" 30 | Library["SPIRV_Cross_Debug"] = "%{LibraryDir.VulkanSDK_Debug}/spirv-cross-cored.lib" 31 | Library["SPIRV_Cross_GLSL_Debug"] = "%{LibraryDir.VulkanSDK_Debug}/spirv-cross-glsld.lib" 32 | Library["SPIRV_Tools_Debug"] = "%{LibraryDir.VulkanSDK_Debug}/SPIRV-Toolsd.lib" 33 | 34 | Library["ShaderC_Release"] = "%{LibraryDir.VulkanSDK}/shaderc_shared.lib" 35 | Library["SPIRV_Cross_Release"] = "%{LibraryDir.VulkanSDK}/spirv-cross-core.lib" 36 | Library["SPIRV_Cross_GLSL_Release"] = "%{LibraryDir.VulkanSDK}/spirv-cross-glsl.lib" 37 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Application.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | 5 | #include "Hazel/Core/Window.h" 6 | #include "Hazel/Core/LayerStack.h" 7 | #include "Hazel/Events/Event.h" 8 | #include "Hazel/Events/ApplicationEvent.h" 9 | 10 | #include "Hazel/Core/Timestep.h" 11 | 12 | #include "Hazel/ImGui/ImGuiLayer.h" 13 | 14 | int main(int argc, char** argv); 15 | 16 | namespace Hazel { 17 | 18 | struct ApplicationCommandLineArgs 19 | { 20 | int Count = 0; 21 | char** Args = nullptr; 22 | 23 | const char* operator[](int index) const 24 | { 25 | HZ_CORE_ASSERT(index < Count); 26 | return Args[index]; 27 | } 28 | }; 29 | 30 | class Application 31 | { 32 | public: 33 | Application(const std::string& name = "Hazel App", ApplicationCommandLineArgs args = ApplicationCommandLineArgs()); 34 | virtual ~Application(); 35 | 36 | void OnEvent(Event& e); 37 | 38 | void PushLayer(Layer* layer); 39 | void PushOverlay(Layer* layer); 40 | 41 | Window& GetWindow() { return *m_Window; } 42 | 43 | void Close(); 44 | 45 | ImGuiLayer* GetImGuiLayer() { return m_ImGuiLayer; } 46 | 47 | static Application& Get() { return *s_Instance; } 48 | 49 | ApplicationCommandLineArgs GetCommandLineArgs() const { return m_CommandLineArgs; } 50 | private: 51 | void Run(); 52 | bool OnWindowClose(WindowCloseEvent& e); 53 | bool OnWindowResize(WindowResizeEvent& e); 54 | private: 55 | ApplicationCommandLineArgs m_CommandLineArgs; 56 | Scope m_Window; 57 | ImGuiLayer* m_ImGuiLayer; 58 | bool m_Running = true; 59 | bool m_Minimized = false; 60 | LayerStack m_LayerStack; 61 | float m_LastFrameTime = 0.0f; 62 | private: 63 | static Application* s_Instance; 64 | friend int ::main(int argc, char** argv); 65 | }; 66 | 67 | // To be defined in CLIENT 68 | Application* CreateApplication(ApplicationCommandLineArgs args); 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Framebuffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | 5 | namespace Hazel { 6 | 7 | enum class FramebufferTextureFormat 8 | { 9 | None = 0, 10 | 11 | // Color 12 | RGBA8, 13 | RED_INTEGER, 14 | 15 | // Depth/stencil 16 | DEPTH24STENCIL8, 17 | 18 | // Defaults 19 | Depth = DEPTH24STENCIL8 20 | }; 21 | 22 | struct FramebufferTextureSpecification 23 | { 24 | FramebufferTextureSpecification() = default; 25 | FramebufferTextureSpecification(FramebufferTextureFormat format) 26 | : TextureFormat(format) {} 27 | 28 | FramebufferTextureFormat TextureFormat = FramebufferTextureFormat::None; 29 | // TODO: filtering/wrap 30 | }; 31 | 32 | struct FramebufferAttachmentSpecification 33 | { 34 | FramebufferAttachmentSpecification() = default; 35 | FramebufferAttachmentSpecification(std::initializer_list attachments) 36 | : Attachments(attachments) {} 37 | 38 | std::vector Attachments; 39 | }; 40 | 41 | struct FramebufferSpecification 42 | { 43 | uint32_t Width = 0, Height = 0; 44 | FramebufferAttachmentSpecification Attachments; 45 | uint32_t Samples = 1; 46 | 47 | bool SwapChainTarget = false; 48 | }; 49 | 50 | class Framebuffer 51 | { 52 | public: 53 | virtual ~Framebuffer() = default; 54 | 55 | virtual void Bind() = 0; 56 | virtual void Unbind() = 0; 57 | 58 | virtual void Resize(uint32_t width, uint32_t height) = 0; 59 | virtual int ReadPixel(uint32_t attachmentIndex, int x, int y) = 0; 60 | 61 | virtual void ClearAttachment(uint32_t attachmentIndex, int value) = 0; 62 | 63 | virtual uint32_t GetColorAttachmentRendererID(uint32_t index = 0) const = 0; 64 | 65 | virtual const FramebufferSpecification& GetSpecification() const = 0; 66 | 67 | static Ref Create(const FramebufferSpecification& spec); 68 | }; 69 | 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Hazel/src/Platform/Windows/WindowsPlatformUtils.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Utils/PlatformUtils.h" 3 | 4 | #include 5 | #include 6 | #define GLFW_EXPOSE_NATIVE_WIN32 7 | #include 8 | 9 | #include "Hazel/Core/Application.h" 10 | 11 | namespace Hazel { 12 | 13 | std::string FileDialogs::OpenFile(const char* filter) 14 | { 15 | OPENFILENAMEA ofn; 16 | CHAR szFile[260] = { 0 }; 17 | CHAR currentDir[256] = { 0 }; 18 | ZeroMemory(&ofn, sizeof(OPENFILENAME)); 19 | ofn.lStructSize = sizeof(OPENFILENAME); 20 | ofn.hwndOwner = glfwGetWin32Window((GLFWwindow*)Application::Get().GetWindow().GetNativeWindow()); 21 | ofn.lpstrFile = szFile; 22 | ofn.nMaxFile = sizeof(szFile); 23 | if (GetCurrentDirectoryA(256, currentDir)) 24 | ofn.lpstrInitialDir = currentDir; 25 | ofn.lpstrFilter = filter; 26 | ofn.nFilterIndex = 1; 27 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR; 28 | 29 | if (GetOpenFileNameA(&ofn) == TRUE) 30 | return ofn.lpstrFile; 31 | 32 | return std::string(); 33 | 34 | } 35 | 36 | std::string FileDialogs::SaveFile(const char* filter) 37 | { 38 | OPENFILENAMEA ofn; 39 | CHAR szFile[260] = { 0 }; 40 | CHAR currentDir[256] = { 0 }; 41 | ZeroMemory(&ofn, sizeof(OPENFILENAME)); 42 | ofn.lStructSize = sizeof(OPENFILENAME); 43 | ofn.hwndOwner = glfwGetWin32Window((GLFWwindow*)Application::Get().GetWindow().GetNativeWindow()); 44 | ofn.lpstrFile = szFile; 45 | ofn.nMaxFile = sizeof(szFile); 46 | if (GetCurrentDirectoryA(256, currentDir)) 47 | ofn.lpstrInitialDir = currentDir; 48 | ofn.lpstrFilter = filter; 49 | ofn.nFilterIndex = 1; 50 | ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR; 51 | 52 | // Sets the default extension by extracting it from the filter 53 | ofn.lpstrDefExt = strchr(filter, '\0') + 1; 54 | 55 | if (GetSaveFileNameA(&ofn) == TRUE) 56 | return ofn.lpstrFile; 57 | 58 | return std::string(); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /scripts/SetupPython.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import subprocess 3 | import importlib.util as importlib_util 4 | 5 | class PythonConfiguration: 6 | @classmethod 7 | def Validate(cls): 8 | if not cls.__ValidatePython(): 9 | return # cannot validate further 10 | 11 | for packageName in ["requests"]: 12 | if not cls.__ValidatePackage(packageName): 13 | return # cannot validate further 14 | 15 | @classmethod 16 | def __ValidatePython(cls, versionMajor = 3, versionMinor = 3): 17 | if sys.version is not None: 18 | print("Python version {0:d}.{1:d}.{2:d} detected.".format( \ 19 | sys.version_info.major, sys.version_info.minor, sys.version_info.micro)) 20 | if sys.version_info.major < versionMajor or (sys.version_info.major == versionMajor and sys.version_info.minor < versionMinor): 21 | print("Python version too low, expected version {0:d}.{1:d} or higher.".format( \ 22 | versionMajor, versionMinor)) 23 | return False 24 | return True 25 | 26 | @classmethod 27 | def __ValidatePackage(cls, packageName): 28 | if importlib_util.find_spec(packageName) is None: 29 | return cls.__InstallPackage(packageName) 30 | return True 31 | 32 | @classmethod 33 | def __InstallPackage(cls, packageName): 34 | permissionGranted = False 35 | while not permissionGranted: 36 | reply = str(input("Would you like to install Python package '{0:s}'? [Y/N]: ".format(packageName))).lower().strip()[:1] 37 | if reply == 'n': 38 | return False 39 | permissionGranted = (reply == 'y') 40 | 41 | print(f"Installing {packageName} module...") 42 | subprocess.check_call(['python', '-m', 'pip', 'install', packageName]) 43 | 44 | return cls.__ValidatePackage(packageName) 45 | 46 | if __name__ == "__main__": 47 | PythonConfiguration.Validate() 48 | -------------------------------------------------------------------------------- /Hazelnut/src/EditorLayer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel.h" 4 | #include "Panels/SceneHierarchyPanel.h" 5 | #include "Panels/ContentBrowserPanel.h" 6 | 7 | #include "Hazel/Renderer/EditorCamera.h" 8 | 9 | namespace Hazel { 10 | 11 | class EditorLayer : public Layer 12 | { 13 | public: 14 | EditorLayer(); 15 | virtual ~EditorLayer() = default; 16 | 17 | virtual void OnAttach() override; 18 | virtual void OnDetach() override; 19 | 20 | void OnUpdate(Timestep ts) override; 21 | virtual void OnImGuiRender() override; 22 | void OnEvent(Event& e) override; 23 | private: 24 | bool OnKeyPressed(KeyPressedEvent& e); 25 | bool OnMouseButtonPressed(MouseButtonPressedEvent& e); 26 | 27 | void NewScene(); 28 | void OpenScene(); 29 | void OpenScene(const std::filesystem::path& path); 30 | void SaveSceneAs(); 31 | 32 | void OnScenePlay(); 33 | void OnSceneStop(); 34 | 35 | // UI Panels 36 | void UI_Toolbar(); 37 | private: 38 | Hazel::OrthographicCameraController m_CameraController; 39 | 40 | // Temp 41 | Ref m_SquareVA; 42 | Ref m_FlatColorShader; 43 | Ref m_Framebuffer; 44 | 45 | Ref m_ActiveScene; 46 | Entity m_SquareEntity; 47 | Entity m_CameraEntity; 48 | Entity m_SecondCamera; 49 | 50 | Entity m_HoveredEntity; 51 | 52 | bool m_PrimaryCamera = true; 53 | 54 | EditorCamera m_EditorCamera; 55 | 56 | Ref m_CheckerboardTexture; 57 | 58 | bool m_ViewportFocused = false, m_ViewportHovered = false; 59 | glm::vec2 m_ViewportSize = { 0.0f, 0.0f }; 60 | glm::vec2 m_ViewportBounds[2]; 61 | 62 | glm::vec4 m_SquareColor = { 0.2f, 0.3f, 0.8f, 1.0f }; 63 | 64 | int m_GizmoType = -1; 65 | 66 | enum class SceneState 67 | { 68 | Edit = 0, Play = 1 69 | }; 70 | SceneState m_SceneState = SceneState::Edit; 71 | 72 | // Panels 73 | SceneHierarchyPanel m_SceneHierarchyPanel; 74 | ContentBrowserPanel m_ContentBrowserPanel; 75 | 76 | // Editor resources 77 | Ref m_IconPlay, m_IconStop; 78 | }; 79 | 80 | } 81 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLRendererAPI.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/OpenGL/OpenGLRendererAPI.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | void OpenGLMessageCallback( 9 | unsigned source, 10 | unsigned type, 11 | unsigned id, 12 | unsigned severity, 13 | int length, 14 | const char* message, 15 | const void* userParam) 16 | { 17 | switch (severity) 18 | { 19 | case GL_DEBUG_SEVERITY_HIGH: HZ_CORE_CRITICAL(message); return; 20 | case GL_DEBUG_SEVERITY_MEDIUM: HZ_CORE_ERROR(message); return; 21 | case GL_DEBUG_SEVERITY_LOW: HZ_CORE_WARN(message); return; 22 | case GL_DEBUG_SEVERITY_NOTIFICATION: HZ_CORE_TRACE(message); return; 23 | } 24 | 25 | HZ_CORE_ASSERT(false, "Unknown severity level!"); 26 | } 27 | 28 | void OpenGLRendererAPI::Init() 29 | { 30 | HZ_PROFILE_FUNCTION(); 31 | 32 | #ifdef HZ_DEBUG 33 | glEnable(GL_DEBUG_OUTPUT); 34 | glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); 35 | glDebugMessageCallback(OpenGLMessageCallback, nullptr); 36 | 37 | glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DEBUG_SEVERITY_NOTIFICATION, 0, NULL, GL_FALSE); 38 | #endif 39 | 40 | glEnable(GL_BLEND); 41 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 42 | 43 | glEnable(GL_DEPTH_TEST); 44 | } 45 | 46 | void OpenGLRendererAPI::SetViewport(uint32_t x, uint32_t y, uint32_t width, uint32_t height) 47 | { 48 | glViewport(x, y, width, height); 49 | } 50 | 51 | void OpenGLRendererAPI::SetClearColor(const glm::vec4& color) 52 | { 53 | glClearColor(color.r, color.g, color.b, color.a); 54 | } 55 | 56 | void OpenGLRendererAPI::Clear() 57 | { 58 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 59 | } 60 | 61 | void OpenGLRendererAPI::DrawIndexed(const Ref& vertexArray, uint32_t indexCount) 62 | { 63 | uint32_t count = indexCount ? indexCount : vertexArray->GetIndexBuffer()->GetCount(); 64 | glDrawElements(GL_TRIANGLES, count, GL_UNSIGNED_INT, nullptr); 65 | glBindTexture(GL_TEXTURE_2D, 0); 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Shader.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/Shader.h" 3 | 4 | #include "Hazel/Renderer/Renderer.h" 5 | #include "Platform/OpenGL/OpenGLShader.h" 6 | 7 | namespace Hazel { 8 | 9 | Ref Shader::Create(const std::string& filepath) 10 | { 11 | switch (Renderer::GetAPI()) 12 | { 13 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 14 | case RendererAPI::API::OpenGL: return CreateRef(filepath); 15 | } 16 | 17 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 18 | return nullptr; 19 | } 20 | 21 | Ref Shader::Create(const std::string& name, const std::string& vertexSrc, const std::string& fragmentSrc) 22 | { 23 | switch (Renderer::GetAPI()) 24 | { 25 | case RendererAPI::API::None: HZ_CORE_ASSERT(false, "RendererAPI::None is currently not supported!"); return nullptr; 26 | case RendererAPI::API::OpenGL: return CreateRef(name, vertexSrc, fragmentSrc); 27 | } 28 | 29 | HZ_CORE_ASSERT(false, "Unknown RendererAPI!"); 30 | return nullptr; 31 | } 32 | 33 | void ShaderLibrary::Add(const std::string& name, const Ref& shader) 34 | { 35 | HZ_CORE_ASSERT(!Exists(name), "Shader already exists!"); 36 | m_Shaders[name] = shader; 37 | } 38 | 39 | void ShaderLibrary::Add(const Ref& shader) 40 | { 41 | auto& name = shader->GetName(); 42 | Add(name, shader); 43 | } 44 | 45 | Ref ShaderLibrary::Load(const std::string& filepath) 46 | { 47 | auto shader = Shader::Create(filepath); 48 | Add(shader); 49 | return shader; 50 | } 51 | 52 | Ref ShaderLibrary::Load(const std::string& name, const std::string& filepath) 53 | { 54 | auto shader = Shader::Create(filepath); 55 | Add(name, shader); 56 | return shader; 57 | } 58 | 59 | Ref ShaderLibrary::Get(const std::string& name) 60 | { 61 | HZ_CORE_ASSERT(Exists(name), "Shader not found!"); 62 | return m_Shaders[name]; 63 | } 64 | 65 | bool ShaderLibrary::Exists(const std::string& name) const 66 | { 67 | return m_Shaders.find(name) != m_Shaders.end(); 68 | } 69 | 70 | } -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/EditorCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Camera.h" 4 | #include "Hazel/Core/Timestep.h" 5 | #include "Hazel/Events/Event.h" 6 | #include "Hazel/Events/MouseEvent.h" 7 | 8 | #include 9 | 10 | namespace Hazel { 11 | 12 | class EditorCamera : public Camera 13 | { 14 | public: 15 | EditorCamera() = default; 16 | EditorCamera(float fov, float aspectRatio, float nearClip, float farClip); 17 | 18 | void OnUpdate(Timestep ts); 19 | void OnEvent(Event& e); 20 | 21 | inline float GetDistance() const { return m_Distance; } 22 | inline void SetDistance(float distance) { m_Distance = distance; } 23 | 24 | inline void SetViewportSize(float width, float height) { m_ViewportWidth = width; m_ViewportHeight = height; UpdateProjection(); } 25 | 26 | const glm::mat4& GetViewMatrix() const { return m_ViewMatrix; } 27 | glm::mat4 GetViewProjection() const { return m_Projection * m_ViewMatrix; } 28 | 29 | glm::vec3 GetUpDirection() const; 30 | glm::vec3 GetRightDirection() const; 31 | glm::vec3 GetForwardDirection() const; 32 | const glm::vec3& GetPosition() const { return m_Position; } 33 | glm::quat GetOrientation() const; 34 | 35 | float GetPitch() const { return m_Pitch; } 36 | float GetYaw() const { return m_Yaw; } 37 | private: 38 | void UpdateProjection(); 39 | void UpdateView(); 40 | 41 | bool OnMouseScroll(MouseScrolledEvent& e); 42 | 43 | void MousePan(const glm::vec2& delta); 44 | void MouseRotate(const glm::vec2& delta); 45 | void MouseZoom(float delta); 46 | 47 | glm::vec3 CalculatePosition() const; 48 | 49 | std::pair PanSpeed() const; 50 | float RotationSpeed() const; 51 | float ZoomSpeed() const; 52 | private: 53 | float m_FOV = 45.0f, m_AspectRatio = 1.778f, m_NearClip = 0.1f, m_FarClip = 1000.0f; 54 | 55 | glm::mat4 m_ViewMatrix; 56 | glm::vec3 m_Position = { 0.0f, 0.0f, 0.0f }; 57 | glm::vec3 m_FocalPoint = { 0.0f, 0.0f, 0.0f }; 58 | 59 | glm::vec2 m_InitialMousePosition = { 0.0f, 0.0f }; 60 | 61 | float m_Distance = 10.0f; 62 | float m_Pitch = 0.0f, m_Yaw = 0.0f; 63 | 64 | float m_ViewportWidth = 1280, m_ViewportHeight = 720; 65 | }; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/SceneCamera.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/Camera.h" 4 | 5 | namespace Hazel { 6 | 7 | class SceneCamera : public Camera 8 | { 9 | public: 10 | enum class ProjectionType { Perspective = 0, Orthographic = 1 }; 11 | public: 12 | SceneCamera(); 13 | virtual ~SceneCamera() = default; 14 | 15 | void SetPerspective(float verticalFOV, float nearClip, float farClip); 16 | void SetOrthographic(float size, float nearClip, float farClip); 17 | 18 | void SetViewportSize(uint32_t width, uint32_t height); 19 | 20 | float GetPerspectiveVerticalFOV() const { return m_PerspectiveFOV; } 21 | void SetPerspectiveVerticalFOV(float verticalFov) { m_PerspectiveFOV = verticalFov; RecalculateProjection(); } 22 | float GetPerspectiveNearClip() const { return m_PerspectiveNear; } 23 | void SetPerspectiveNearClip(float nearClip) { m_PerspectiveNear = nearClip; RecalculateProjection(); } 24 | float GetPerspectiveFarClip() const { return m_PerspectiveFar; } 25 | void SetPerspectiveFarClip(float farClip) { m_PerspectiveFar = farClip; RecalculateProjection(); } 26 | 27 | float GetOrthographicSize() const { return m_OrthographicSize; } 28 | void SetOrthographicSize(float size) { m_OrthographicSize = size; RecalculateProjection(); } 29 | float GetOrthographicNearClip() const { return m_OrthographicNear; } 30 | void SetOrthographicNearClip(float nearClip) { m_OrthographicNear = nearClip; RecalculateProjection(); } 31 | float GetOrthographicFarClip() const { return m_OrthographicFar; } 32 | void SetOrthographicFarClip(float farClip) { m_OrthographicFar = farClip; RecalculateProjection(); } 33 | 34 | ProjectionType GetProjectionType() const { return m_ProjectionType; } 35 | void SetProjectionType(ProjectionType type) { m_ProjectionType = type; RecalculateProjection(); } 36 | private: 37 | void RecalculateProjection(); 38 | private: 39 | ProjectionType m_ProjectionType = ProjectionType::Orthographic; 40 | 41 | float m_PerspectiveFOV = glm::radians(45.0f); 42 | float m_PerspectiveNear = 0.01f, m_PerspectiveFar = 1000.0f; 43 | 44 | float m_OrthographicSize = 10.0f; 45 | float m_OrthographicNear = -1.0f, m_OrthographicFar = 1.0f; 46 | 47 | float m_AspectRatio = 0.0f; 48 | }; 49 | 50 | } 51 | -------------------------------------------------------------------------------- /scripts/SetupPremake.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | from pathlib import Path 4 | 5 | import Utils 6 | 7 | class PremakeConfiguration: 8 | premakeVersion = "5.0.0-alpha16" 9 | premakeZipUrls = f"https://github.com/premake/premake-core/releases/download/v{premakeVersion}/premake-{premakeVersion}-windows.zip" 10 | premakeLicenseUrl = "https://raw.githubusercontent.com/premake/premake-core/master/LICENSE.txt" 11 | premakeDirectory = "./vendor/premake/bin" 12 | 13 | @classmethod 14 | def Validate(cls): 15 | if (not cls.CheckIfPremakeInstalled()): 16 | print("Premake is not installed.") 17 | return False 18 | 19 | print(f"Correct Premake located at {os.path.abspath(cls.premakeDirectory)}") 20 | return True 21 | 22 | @classmethod 23 | def CheckIfPremakeInstalled(cls): 24 | premakeExe = Path(f"{cls.premakeDirectory}/premake5.exe"); 25 | if (not premakeExe.exists()): 26 | return cls.InstallPremake() 27 | 28 | return True 29 | 30 | @classmethod 31 | def InstallPremake(cls): 32 | permissionGranted = False 33 | while not permissionGranted: 34 | reply = str(input("Premake not found. Would you like to download Premake {0:s}? [Y/N]: ".format(cls.premakeVersion))).lower().strip()[:1] 35 | if reply == 'n': 36 | return False 37 | permissionGranted = (reply == 'y') 38 | 39 | premakePath = f"{cls.premakeDirectory}/premake-{cls.premakeVersion}-windows.zip" 40 | print("Downloading {0:s} to {1:s}".format(cls.premakeZipUrls, premakePath)) 41 | Utils.DownloadFile(cls.premakeZipUrls, premakePath) 42 | print("Extracting", premakePath) 43 | Utils.UnzipFile(premakePath, deleteZipFile=True) 44 | print(f"Premake {cls.premakeVersion} has been downloaded to '{cls.premakeDirectory}'") 45 | 46 | premakeLicensePath = f"{cls.premakeDirectory}/LICENSE.txt" 47 | print("Downloading {0:s} to {1:s}".format(cls.premakeLicenseUrl, premakeLicensePath)) 48 | Utils.DownloadFile(cls.premakeLicenseUrl, premakeLicensePath) 49 | print(f"Premake License file has been downloaded to '{cls.premakeDirectory}'") 50 | 51 | return True 52 | -------------------------------------------------------------------------------- /Hazel/premake5.lua: -------------------------------------------------------------------------------- 1 | project "Hazel" 2 | kind "StaticLib" 3 | language "C++" 4 | cppdialect "C++17" 5 | staticruntime "off" 6 | 7 | targetdir ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}") 8 | objdir ("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}") 9 | 10 | pchheader "hzpch.h" 11 | pchsource "src/hzpch.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 | "vendor/ImGuizmo/ImGuizmo.h", 23 | "vendor/ImGuizmo/ImGuizmo.cpp" 24 | } 25 | 26 | defines 27 | { 28 | "_CRT_SECURE_NO_WARNINGS", 29 | "GLFW_INCLUDE_NONE" 30 | } 31 | 32 | includedirs 33 | { 34 | "src", 35 | "vendor/spdlog/include", 36 | "%{IncludeDir.GLFW}", 37 | "%{IncludeDir.Glad}", 38 | "%{IncludeDir.ImGui}", 39 | "%{IncludeDir.glm}", 40 | "%{IncludeDir.stb_image}", 41 | "%{IncludeDir.entt}", 42 | "%{IncludeDir.yaml_cpp}", 43 | "%{IncludeDir.ImGuizmo}", 44 | "%{IncludeDir.VulkanSDK}" 45 | } 46 | 47 | links 48 | { 49 | "GLFW", 50 | "Glad", 51 | "ImGui", 52 | "yaml-cpp", 53 | "opengl32.lib" 54 | } 55 | 56 | filter "files:vendor/ImGuizmo/**.cpp" 57 | flags { "NoPCH" } 58 | 59 | filter "system:windows" 60 | systemversion "latest" 61 | 62 | defines 63 | { 64 | } 65 | 66 | filter "configurations:Debug" 67 | defines "HZ_DEBUG" 68 | runtime "Debug" 69 | symbols "on" 70 | 71 | links 72 | { 73 | "%{Library.ShaderC_Debug}", 74 | "%{Library.SPIRV_Cross_Debug}", 75 | "%{Library.SPIRV_Cross_GLSL_Debug}" 76 | } 77 | 78 | filter "configurations:Release" 79 | defines "HZ_RELEASE" 80 | runtime "Release" 81 | optimize "on" 82 | 83 | links 84 | { 85 | "%{Library.ShaderC_Release}", 86 | "%{Library.SPIRV_Cross_Release}", 87 | "%{Library.SPIRV_Cross_GLSL_Release}" 88 | } 89 | 90 | filter "configurations:Dist" 91 | defines "HZ_DIST" 92 | runtime "Release" 93 | optimize "on" 94 | 95 | links 96 | { 97 | "%{Library.ShaderC_Release}", 98 | "%{Library.SPIRV_Cross_Release}", 99 | "%{Library.SPIRV_Cross_GLSL_Release}" 100 | } 101 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Core/Base.h" 4 | 5 | #define GLM_ENABLE_EXPERIMENTAL 6 | #include "glm/gtx/string_cast.hpp" 7 | 8 | // This ignores all warnings raised inside External headers 9 | #pragma warning(push, 0) 10 | #include 11 | #include 12 | #pragma warning(pop) 13 | 14 | namespace Hazel { 15 | 16 | class Log 17 | { 18 | public: 19 | static void Init(); 20 | 21 | static Ref& GetCoreLogger() { return s_CoreLogger; } 22 | static Ref& GetClientLogger() { return s_ClientLogger; } 23 | private: 24 | static Ref s_CoreLogger; 25 | static Ref s_ClientLogger; 26 | }; 27 | 28 | } 29 | 30 | template 31 | inline OStream& operator<<(OStream& os, const glm::vec& vector) 32 | { 33 | return os << glm::to_string(vector); 34 | } 35 | 36 | template 37 | inline OStream& operator<<(OStream& os, const glm::mat& matrix) 38 | { 39 | return os << glm::to_string(matrix); 40 | } 41 | 42 | template 43 | inline OStream& operator<<(OStream& os, glm::qua quaternion) 44 | { 45 | return os << glm::to_string(quaternion); 46 | } 47 | 48 | // Core log macros 49 | #define HZ_CORE_TRACE(...) ::Hazel::Log::GetCoreLogger()->trace(__VA_ARGS__) 50 | #define HZ_CORE_INFO(...) ::Hazel::Log::GetCoreLogger()->info(__VA_ARGS__) 51 | #define HZ_CORE_WARN(...) ::Hazel::Log::GetCoreLogger()->warn(__VA_ARGS__) 52 | #define HZ_CORE_ERROR(...) ::Hazel::Log::GetCoreLogger()->error(__VA_ARGS__) 53 | #define HZ_CORE_CRITICAL(...) ::Hazel::Log::GetCoreLogger()->critical(__VA_ARGS__) 54 | 55 | // Client log macros 56 | #define HZ_TRACE(...) ::Hazel::Log::GetClientLogger()->trace(__VA_ARGS__) 57 | #define HZ_INFO(...) ::Hazel::Log::GetClientLogger()->info(__VA_ARGS__) 58 | #define HZ_WARN(...) ::Hazel::Log::GetClientLogger()->warn(__VA_ARGS__) 59 | #define HZ_ERROR(...) ::Hazel::Log::GetClientLogger()->error(__VA_ARGS__) 60 | #define HZ_CRITICAL(...) ::Hazel::Log::GetClientLogger()->critical(__VA_ARGS__) 61 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/Components.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #define GLM_ENABLE_EXPERIMENTAL 7 | #include 8 | 9 | #include "SceneCamera.h" 10 | #include "ScriptableEntity.h" 11 | #include "Hazel/Renderer/Texture.h" 12 | 13 | namespace Hazel { 14 | 15 | struct TagComponent 16 | { 17 | std::string Tag; 18 | 19 | TagComponent() = default; 20 | TagComponent(const TagComponent&) = default; 21 | TagComponent(const std::string& tag) 22 | : Tag(tag) {} 23 | }; 24 | 25 | struct TransformComponent 26 | { 27 | glm::vec3 Translation = { 0.0f, 0.0f, 0.0f }; 28 | glm::vec3 Rotation = { 0.0f, 0.0f, 0.0f }; 29 | glm::vec3 Scale = { 1.0f, 1.0f, 1.0f }; 30 | 31 | TransformComponent() = default; 32 | TransformComponent(const TransformComponent&) = default; 33 | TransformComponent(const glm::vec3& translation) 34 | : Translation(translation) {} 35 | 36 | glm::mat4 GetTransform() const 37 | { 38 | glm::mat4 rotation = glm::toMat4(glm::quat(Rotation)); 39 | 40 | return glm::translate(glm::mat4(1.0f), Translation) 41 | * rotation 42 | * glm::scale(glm::mat4(1.0f), Scale); 43 | } 44 | }; 45 | 46 | struct SpriteRendererComponent 47 | { 48 | glm::vec4 Color{ 1.0f, 1.0f, 1.0f, 1.0f }; 49 | Ref Texture; 50 | float TilingFactor = 1.0f; 51 | 52 | SpriteRendererComponent() = default; 53 | SpriteRendererComponent(const SpriteRendererComponent&) = default; 54 | SpriteRendererComponent(const glm::vec4& color) 55 | : Color(color) {} 56 | }; 57 | 58 | struct CameraComponent 59 | { 60 | SceneCamera Camera; 61 | bool Primary = true; // TODO: think about moving to Scene 62 | bool FixedAspectRatio = false; 63 | 64 | CameraComponent() = default; 65 | CameraComponent(const CameraComponent&) = default; 66 | }; 67 | 68 | struct NativeScriptComponent 69 | { 70 | ScriptableEntity* Instance = nullptr; 71 | 72 | ScriptableEntity*(*InstantiateScript)(); 73 | void (*DestroyScript)(NativeScriptComponent*); 74 | 75 | template 76 | void Bind() 77 | { 78 | InstantiateScript = []() { return static_cast(new T()); }; 79 | DestroyScript = [](NativeScriptComponent* nsc) { delete nsc->Instance; nsc->Instance = nullptr; }; 80 | } 81 | }; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Hazelnut/imgui.ini: -------------------------------------------------------------------------------- 1 | [Window][DockSpace Demo] 2 | Pos=0,0 3 | Size=1600,900 4 | Collapsed=0 5 | 6 | [Window][Debug##Default] 7 | ViewportPos=1180,1184 8 | ViewportId=0x9F5F46A1 9 | Size=400,400 10 | Collapsed=0 11 | 12 | [Window][Settings] 13 | Pos=874,19 14 | Size=406,701 15 | Collapsed=0 16 | DockId=0x00000004,0 17 | 18 | [Window][Viewport] 19 | Pos=372,71 20 | Size=856,524 21 | Collapsed=0 22 | DockId=0x0000000C,0 23 | 24 | [Window][Scene Hierarchy] 25 | Pos=0,24 26 | Size=370,435 27 | Collapsed=0 28 | DockId=0x00000005,0 29 | 30 | [Window][Dear ImGui Demo] 31 | ViewportPos=336,212 32 | ViewportId=0xE927CF2F 33 | Size=1421,1027 34 | Collapsed=0 35 | 36 | [Window][Properties] 37 | Pos=0,461 38 | Size=370,439 39 | Collapsed=0 40 | DockId=0x00000006,0 41 | 42 | [Window][Stats] 43 | Pos=1230,24 44 | Size=370,876 45 | Collapsed=0 46 | DockId=0x00000007,0 47 | 48 | [Window][Content Browser] 49 | Pos=372,597 50 | Size=856,303 51 | Collapsed=0 52 | DockId=0x0000000A,0 53 | 54 | [Window][##toolbar] 55 | Pos=372,24 56 | Size=856,45 57 | Collapsed=0 58 | DockId=0x0000000B,0 59 | 60 | [Docking][Data] 61 | DockSpace ID=0x3BC79352 Window=0x4647B76E Pos=294,341 Size=1600,876 Split=X Selected=0x995B0CF8 62 | DockNode ID=0x00000008 Parent=0x3BC79352 SizeRef=1228,876 Split=X 63 | DockNode ID=0x00000001 Parent=0x00000008 SizeRef=370,696 Split=Y Selected=0xC89E3217 64 | DockNode ID=0x00000005 Parent=0x00000001 SizeRef=370,435 Selected=0x9A68760C 65 | DockNode ID=0x00000006 Parent=0x00000001 SizeRef=370,439 Selected=0xC89E3217 66 | DockNode ID=0x00000002 Parent=0x00000008 SizeRef=856,696 Split=X 67 | DockNode ID=0x00000003 Parent=0x00000002 SizeRef=958,701 Split=Y Selected=0x995B0CF8 68 | DockNode ID=0x00000009 Parent=0x00000003 SizeRef=856,571 Split=Y Selected=0x995B0CF8 69 | DockNode ID=0x0000000B Parent=0x00000009 SizeRef=856,45 HiddenTabBar=1 Selected=0x28257B55 70 | DockNode ID=0x0000000C Parent=0x00000009 SizeRef=856,524 CentralNode=1 HiddenTabBar=1 Selected=0x995B0CF8 71 | DockNode ID=0x0000000A Parent=0x00000003 SizeRef=856,303 Selected=0x371352B7 72 | DockNode ID=0x00000004 Parent=0x00000002 SizeRef=272,701 Selected=0x1C33C293 73 | DockNode ID=0x00000007 Parent=0x3BC79352 SizeRef=370,876 Selected=0x968648AE 74 | 75 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Events/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | #include "Hazel/Debug/Instrumentor.h" 5 | #include "Hazel/Core/Base.h" 6 | 7 | namespace Hazel { 8 | 9 | // Events in Hazel are currently blocking, meaning when an event occurs it 10 | // immediately gets dispatched and must be dealt with right then an there. 11 | // For the future, a better strategy might be to buffer events in an event 12 | // bus and process them during the "event" part of the update stage. 13 | 14 | enum class EventType 15 | { 16 | None = 0, 17 | WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved, 18 | AppTick, AppUpdate, AppRender, 19 | KeyPressed, KeyReleased, KeyTyped, 20 | MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled 21 | }; 22 | 23 | enum EventCategory 24 | { 25 | None = 0, 26 | EventCategoryApplication = BIT(0), 27 | EventCategoryInput = BIT(1), 28 | EventCategoryKeyboard = BIT(2), 29 | EventCategoryMouse = BIT(3), 30 | EventCategoryMouseButton = BIT(4) 31 | }; 32 | 33 | #define EVENT_CLASS_TYPE(type) static EventType GetStaticType() { return EventType::type; }\ 34 | virtual EventType GetEventType() const override { return GetStaticType(); }\ 35 | virtual const char* GetName() const override { return #type; } 36 | 37 | #define EVENT_CLASS_CATEGORY(category) virtual int GetCategoryFlags() const override { return category; } 38 | 39 | class Event 40 | { 41 | public: 42 | virtual ~Event() = default; 43 | 44 | bool Handled = false; 45 | 46 | virtual EventType GetEventType() const = 0; 47 | virtual const char* GetName() const = 0; 48 | virtual int GetCategoryFlags() const = 0; 49 | virtual std::string ToString() const { return GetName(); } 50 | 51 | bool IsInCategory(EventCategory category) 52 | { 53 | return GetCategoryFlags() & category; 54 | } 55 | }; 56 | 57 | class EventDispatcher 58 | { 59 | public: 60 | EventDispatcher(Event& event) 61 | : m_Event(event) 62 | { 63 | } 64 | 65 | // F will be deduced by the compiler 66 | template 67 | bool Dispatch(const F& func) 68 | { 69 | if (m_Event.GetEventType() == T::GetStaticType()) 70 | { 71 | m_Event.Handled |= func(static_cast(m_Event)); 72 | return true; 73 | } 74 | return false; 75 | } 76 | private: 77 | Event& m_Event; 78 | }; 79 | 80 | inline std::ostream& operator<<(std::ostream& os, const Event& e) 81 | { 82 | return os << e.ToString(); 83 | } 84 | 85 | } 86 | 87 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Math/Math.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Math.h" 3 | 4 | #define GLM_ENABLE_EXPERIMENTAL 5 | #include 6 | 7 | namespace Hazel::Math { 8 | 9 | bool DecomposeTransform(const glm::mat4& transform, glm::vec3& translation, glm::vec3& rotation, glm::vec3& scale) 10 | { 11 | // From glm::decompose in matrix_decompose.inl 12 | 13 | using namespace glm; 14 | using T = float; 15 | 16 | mat4 LocalMatrix(transform); 17 | 18 | // Normalize the matrix. 19 | if (epsilonEqual(LocalMatrix[3][3], static_cast(0), epsilon())) 20 | return false; 21 | 22 | // First, isolate perspective. This is the messiest. 23 | if ( 24 | epsilonNotEqual(LocalMatrix[0][3], static_cast(0), epsilon()) || 25 | epsilonNotEqual(LocalMatrix[1][3], static_cast(0), epsilon()) || 26 | epsilonNotEqual(LocalMatrix[2][3], static_cast(0), epsilon())) 27 | { 28 | // Clear the perspective partition 29 | LocalMatrix[0][3] = LocalMatrix[1][3] = LocalMatrix[2][3] = static_cast(0); 30 | LocalMatrix[3][3] = static_cast(1); 31 | } 32 | 33 | // Next take care of translation (easy). 34 | translation = vec3(LocalMatrix[3]); 35 | LocalMatrix[3] = vec4(0, 0, 0, LocalMatrix[3].w); 36 | 37 | vec3 Row[3], Pdum3; 38 | 39 | // Now get scale and shear. 40 | for (length_t i = 0; i < 3; ++i) 41 | for (length_t j = 0; j < 3; ++j) 42 | Row[i][j] = LocalMatrix[i][j]; 43 | 44 | // Compute X scale factor and normalize first row. 45 | scale.x = length(Row[0]); 46 | Row[0] = detail::scale(Row[0], static_cast(1)); 47 | scale.y = length(Row[1]); 48 | Row[1] = detail::scale(Row[1], static_cast(1)); 49 | scale.z = length(Row[2]); 50 | Row[2] = detail::scale(Row[2], static_cast(1)); 51 | 52 | // At this point, the matrix (in rows[]) is orthonormal. 53 | // Check for a coordinate system flip. If the determinant 54 | // is -1, then negate the matrix and the scaling factors. 55 | #if 0 56 | Pdum3 = cross(Row[1], Row[2]); // v3Cross(row[1], row[2], Pdum3); 57 | if (dot(Row[0], Pdum3) < 0) 58 | { 59 | for (length_t i = 0; i < 3; i++) 60 | { 61 | scale[i] *= static_cast(-1); 62 | Row[i] *= static_cast(-1); 63 | } 64 | } 65 | #endif 66 | 67 | rotation.y = asin(-Row[0][2]); 68 | if (cos(rotation.y) != 0) { 69 | rotation.x = atan2(Row[1][2], Row[2][2]); 70 | rotation.z = atan2(Row[0][1], Row[0][0]); 71 | } 72 | else { 73 | rotation.x = atan2(-Row[2][0], Row[1][1]); 74 | rotation.z = 0; 75 | } 76 | 77 | 78 | return true; 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLShader.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/Shader.h" 4 | #include 5 | 6 | // TODO: REMOVE! 7 | typedef unsigned int GLenum; 8 | 9 | namespace Hazel { 10 | 11 | class OpenGLShader : public Shader 12 | { 13 | public: 14 | OpenGLShader(const std::string& filepath); 15 | OpenGLShader(const std::string& name, const std::string& vertexSrc, const std::string& fragmentSrc); 16 | virtual ~OpenGLShader(); 17 | 18 | virtual void Bind() const override; 19 | virtual void Unbind() const override; 20 | 21 | virtual void SetInt(const std::string& name, int value) override; 22 | virtual void SetIntArray(const std::string& name, int* values, uint32_t count) override; 23 | virtual void SetFloat(const std::string& name, float value) override; 24 | virtual void SetFloat2(const std::string& name, const glm::vec2& value) override; 25 | virtual void SetFloat3(const std::string& name, const glm::vec3& value) override; 26 | virtual void SetFloat4(const std::string& name, const glm::vec4& value) override; 27 | virtual void SetMat4(const std::string& name, const glm::mat4& value) override; 28 | 29 | virtual const std::string& GetName() const override { return m_Name; } 30 | 31 | void UploadUniformInt(const std::string& name, int value); 32 | void UploadUniformIntArray(const std::string& name, int* values, uint32_t count); 33 | 34 | void UploadUniformFloat(const std::string& name, float value); 35 | void UploadUniformFloat2(const std::string& name, const glm::vec2& value); 36 | void UploadUniformFloat3(const std::string& name, const glm::vec3& value); 37 | void UploadUniformFloat4(const std::string& name, const glm::vec4& value); 38 | 39 | void UploadUniformMat3(const std::string& name, const glm::mat3& matrix); 40 | void UploadUniformMat4(const std::string& name, const glm::mat4& matrix); 41 | private: 42 | std::string ReadFile(const std::string& filepath); 43 | std::unordered_map PreProcess(const std::string& source); 44 | 45 | void CompileOrGetVulkanBinaries(const std::unordered_map& shaderSources); 46 | void CompileOrGetOpenGLBinaries(); 47 | void CreateProgram(); 48 | void Reflect(GLenum stage, const std::vector& shaderData); 49 | private: 50 | uint32_t m_RendererID; 51 | std::string m_FilePath; 52 | std::string m_Name; 53 | 54 | std::unordered_map> m_VulkanSPIRV; 55 | std::unordered_map> m_OpenGLSPIRV; 56 | 57 | std::unordered_map m_OpenGLSourceCode; 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Events/MouseEvent.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Events/Event.h" 4 | #include "Hazel/Core/MouseCodes.h" 5 | 6 | namespace Hazel { 7 | 8 | class MouseMovedEvent : public Event 9 | { 10 | public: 11 | MouseMovedEvent(const float x, const float y) 12 | : m_MouseX(x), m_MouseY(y) {} 13 | 14 | float GetX() const { return m_MouseX; } 15 | float GetY() const { return m_MouseY; } 16 | 17 | std::string ToString() const override 18 | { 19 | std::stringstream ss; 20 | ss << "MouseMovedEvent: " << m_MouseX << ", " << m_MouseY; 21 | return ss.str(); 22 | } 23 | 24 | EVENT_CLASS_TYPE(MouseMoved) 25 | EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput) 26 | private: 27 | float m_MouseX, m_MouseY; 28 | }; 29 | 30 | class MouseScrolledEvent : public Event 31 | { 32 | public: 33 | MouseScrolledEvent(const float xOffset, const float yOffset) 34 | : m_XOffset(xOffset), m_YOffset(yOffset) {} 35 | 36 | float GetXOffset() const { return m_XOffset; } 37 | float GetYOffset() const { return m_YOffset; } 38 | 39 | std::string ToString() const override 40 | { 41 | std::stringstream ss; 42 | ss << "MouseScrolledEvent: " << GetXOffset() << ", " << GetYOffset(); 43 | return ss.str(); 44 | } 45 | 46 | EVENT_CLASS_TYPE(MouseScrolled) 47 | EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput) 48 | private: 49 | float m_XOffset, m_YOffset; 50 | }; 51 | 52 | class MouseButtonEvent : public Event 53 | { 54 | public: 55 | MouseCode GetMouseButton() const { return m_Button; } 56 | 57 | EVENT_CLASS_CATEGORY(EventCategoryMouse | EventCategoryInput | EventCategoryMouseButton) 58 | protected: 59 | MouseButtonEvent(const MouseCode button) 60 | : m_Button(button) {} 61 | 62 | MouseCode m_Button; 63 | }; 64 | 65 | class MouseButtonPressedEvent : public MouseButtonEvent 66 | { 67 | public: 68 | MouseButtonPressedEvent(const MouseCode button) 69 | : MouseButtonEvent(button) {} 70 | 71 | std::string ToString() const override 72 | { 73 | std::stringstream ss; 74 | ss << "MouseButtonPressedEvent: " << m_Button; 75 | return ss.str(); 76 | } 77 | 78 | EVENT_CLASS_TYPE(MouseButtonPressed) 79 | }; 80 | 81 | class MouseButtonReleasedEvent : public MouseButtonEvent 82 | { 83 | public: 84 | MouseButtonReleasedEvent(const MouseCode button) 85 | : MouseButtonEvent(button) {} 86 | 87 | std::string ToString() const override 88 | { 89 | std::stringstream ss; 90 | ss << "MouseButtonReleasedEvent: " << m_Button; 91 | return ss.str(); 92 | } 93 | 94 | EVENT_CLASS_TYPE(MouseButtonReleased) 95 | }; 96 | 97 | } 98 | -------------------------------------------------------------------------------- /Hazelnut/src/Panels/ContentBrowserPanel.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "ContentBrowserPanel.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | // Once we have projects, change this 9 | extern const std::filesystem::path g_AssetPath = "assets"; 10 | 11 | ContentBrowserPanel::ContentBrowserPanel() 12 | : m_CurrentDirectory(g_AssetPath) 13 | { 14 | m_DirectoryIcon = Texture2D::Create("Resources/Icons/ContentBrowser/DirectoryIcon.png"); 15 | m_FileIcon = Texture2D::Create("Resources/Icons/ContentBrowser/FileIcon.png"); 16 | } 17 | 18 | void ContentBrowserPanel::OnImGuiRender() 19 | { 20 | ImGui::Begin("Content Browser"); 21 | 22 | if (m_CurrentDirectory != std::filesystem::path(g_AssetPath)) 23 | { 24 | if (ImGui::Button("<-")) 25 | { 26 | m_CurrentDirectory = m_CurrentDirectory.parent_path(); 27 | } 28 | } 29 | 30 | static float padding = 16.0f; 31 | static float thumbnailSize = 128.0f; 32 | float cellSize = thumbnailSize + padding; 33 | 34 | float panelWidth = ImGui::GetContentRegionAvail().x; 35 | int columnCount = (int)(panelWidth / cellSize); 36 | if (columnCount < 1) 37 | columnCount = 1; 38 | 39 | ImGui::Columns(columnCount, 0, false); 40 | 41 | for (auto& directoryEntry : std::filesystem::directory_iterator(m_CurrentDirectory)) 42 | { 43 | const auto& path = directoryEntry.path(); 44 | auto relativePath = std::filesystem::relative(path, g_AssetPath); 45 | std::string filenameString = relativePath.filename().string(); 46 | 47 | ImGui::PushID(filenameString.c_str()); 48 | Ref icon = directoryEntry.is_directory() ? m_DirectoryIcon : m_FileIcon; 49 | ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0)); 50 | ImGui::ImageButton((ImTextureID)icon->GetRendererID(), { thumbnailSize, thumbnailSize }, { 0, 1 }, { 1, 0 }); 51 | 52 | if (ImGui::BeginDragDropSource()) 53 | { 54 | const wchar_t* itemPath = relativePath.c_str(); 55 | ImGui::SetDragDropPayload("CONTENT_BROWSER_ITEM", itemPath, (wcslen(itemPath) + 1) * sizeof(wchar_t)); 56 | ImGui::EndDragDropSource(); 57 | } 58 | 59 | ImGui::PopStyleColor(); 60 | if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) 61 | { 62 | if (directoryEntry.is_directory()) 63 | m_CurrentDirectory /= path.filename(); 64 | 65 | } 66 | ImGui::TextWrapped(filenameString.c_str()); 67 | 68 | ImGui::NextColumn(); 69 | 70 | ImGui::PopID(); 71 | } 72 | 73 | ImGui::Columns(1); 74 | 75 | ImGui::SliderFloat("Thumbnail Size", &thumbnailSize, 16, 512); 76 | ImGui::SliderFloat("Padding", &padding, 0, 32); 77 | 78 | // TODO: status bar 79 | ImGui::End(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /Sandbox/src/Sandbox2D.cpp: -------------------------------------------------------------------------------- 1 | #include "Sandbox2D.h" 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | Sandbox2D::Sandbox2D() 8 | : Layer("Sandbox2D"), m_CameraController(1280.0f / 720.0f), m_SquareColor({ 0.2f, 0.3f, 0.8f, 1.0f }) 9 | { 10 | } 11 | 12 | void Sandbox2D::OnAttach() 13 | { 14 | HZ_PROFILE_FUNCTION(); 15 | 16 | m_CheckerboardTexture = Hazel::Texture2D::Create("assets/textures/Checkerboard.png"); 17 | } 18 | 19 | void Sandbox2D::OnDetach() 20 | { 21 | HZ_PROFILE_FUNCTION(); 22 | } 23 | 24 | void Sandbox2D::OnUpdate(Hazel::Timestep ts) 25 | { 26 | HZ_PROFILE_FUNCTION(); 27 | 28 | // Update 29 | m_CameraController.OnUpdate(ts); 30 | 31 | // Render 32 | Hazel::Renderer2D::ResetStats(); 33 | { 34 | HZ_PROFILE_SCOPE("Renderer Prep"); 35 | Hazel::RenderCommand::SetClearColor({ 0.1f, 0.1f, 0.1f, 1 }); 36 | Hazel::RenderCommand::Clear(); 37 | } 38 | 39 | { 40 | static float rotation = 0.0f; 41 | rotation += ts * 50.0f; 42 | 43 | HZ_PROFILE_SCOPE("Renderer Draw"); 44 | Hazel::Renderer2D::BeginScene(m_CameraController.GetCamera()); 45 | Hazel::Renderer2D::DrawRotatedQuad({ 1.0f, 0.0f }, { 0.8f, 0.8f }, -45.0f, { 0.8f, 0.2f, 0.3f, 1.0f }); 46 | Hazel::Renderer2D::DrawQuad({ -1.0f, 0.0f }, { 0.8f, 0.8f }, { 0.8f, 0.2f, 0.3f, 1.0f }); 47 | Hazel::Renderer2D::DrawQuad({ 0.5f, -0.5f }, { 0.5f, 0.75f }, m_SquareColor); 48 | Hazel::Renderer2D::DrawQuad({ 0.0f, 0.0f, -0.1f }, { 20.0f, 20.0f }, m_CheckerboardTexture, 10.0f); 49 | Hazel::Renderer2D::DrawRotatedQuad({ -2.0f, 0.0f, 0.0f }, { 1.0f, 1.0f }, rotation, m_CheckerboardTexture, 20.0f); 50 | Hazel::Renderer2D::EndScene(); 51 | 52 | Hazel::Renderer2D::BeginScene(m_CameraController.GetCamera()); 53 | for (float y = -5.0f; y < 5.0f; y += 0.5f) 54 | { 55 | for (float x = -5.0f; x < 5.0f; x += 0.5f) 56 | { 57 | glm::vec4 color = { (x + 5.0f) / 10.0f, 0.4f, (y + 5.0f) / 10.0f, 0.7f }; 58 | Hazel::Renderer2D::DrawQuad({ x, y }, { 0.45f, 0.45f }, color); 59 | } 60 | } 61 | Hazel::Renderer2D::EndScene(); 62 | } 63 | } 64 | 65 | void Sandbox2D::OnImGuiRender() 66 | { 67 | HZ_PROFILE_FUNCTION(); 68 | 69 | ImGui::Begin("Settings"); 70 | 71 | auto stats = Hazel::Renderer2D::GetStats(); 72 | ImGui::Text("Renderer2D Stats:"); 73 | ImGui::Text("Draw Calls: %d", stats.DrawCalls); 74 | ImGui::Text("Quads: %d", stats.QuadCount); 75 | ImGui::Text("Vertices: %d", stats.GetTotalVertexCount()); 76 | ImGui::Text("Indices: %d", stats.GetTotalIndexCount()); 77 | 78 | ImGui::ColorEdit4("Square Color", glm::value_ptr(m_SquareColor)); 79 | ImGui::End(); 80 | } 81 | 82 | void Sandbox2D::OnEvent(Hazel::Event& e) 83 | { 84 | m_CameraController.OnEvent(e); 85 | } 86 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Renderer2D.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Hazel/Renderer/OrthographicCamera.h" 4 | 5 | #include "Hazel/Renderer/Texture.h" 6 | 7 | #include "Hazel/Renderer/Camera.h" 8 | #include "Hazel/Renderer/EditorCamera.h" 9 | 10 | #include "Hazel/Scene/Components.h" 11 | 12 | namespace Hazel { 13 | 14 | class Renderer2D 15 | { 16 | public: 17 | static void Init(); 18 | static void Shutdown(); 19 | 20 | static void BeginScene(const Camera& camera, const glm::mat4& transform); 21 | static void BeginScene(const EditorCamera& camera); 22 | static void BeginScene(const OrthographicCamera& camera); // TODO: Remove 23 | static void EndScene(); 24 | static void Flush(); 25 | 26 | // Primitives 27 | static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const glm::vec4& color); 28 | static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const glm::vec4& color); 29 | static void DrawQuad(const glm::vec2& position, const glm::vec2& size, const Ref& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f)); 30 | static void DrawQuad(const glm::vec3& position, const glm::vec2& size, const Ref& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f)); 31 | 32 | static void DrawQuad(const glm::mat4& transform, const glm::vec4& color, int entityID = -1); 33 | static void DrawQuad(const glm::mat4& transform, const Ref& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f), int entityID = -1); 34 | 35 | static void DrawRotatedQuad(const glm::vec2& position, const glm::vec2& size, float rotation, const glm::vec4& color); 36 | static void DrawRotatedQuad(const glm::vec3& position, const glm::vec2& size, float rotation, const glm::vec4& color); 37 | static void DrawRotatedQuad(const glm::vec2& position, const glm::vec2& size, float rotation, const Ref& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f)); 38 | static void DrawRotatedQuad(const glm::vec3& position, const glm::vec2& size, float rotation, const Ref& texture, float tilingFactor = 1.0f, const glm::vec4& tintColor = glm::vec4(1.0f)); 39 | 40 | static void DrawSprite(const glm::mat4& transform, SpriteRendererComponent& src, int entityID); 41 | 42 | // Stats 43 | struct Statistics 44 | { 45 | uint32_t DrawCalls = 0; 46 | uint32_t QuadCount = 0; 47 | 48 | uint32_t GetTotalVertexCount() const { return QuadCount * 4; } 49 | uint32_t GetTotalIndexCount() const { return QuadCount * 6; } 50 | }; 51 | static void ResetStats(); 52 | static Statistics GetStats(); 53 | 54 | private: 55 | static void StartBatch(); 56 | static void NextBatch(); 57 | }; 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLBuffer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/OpenGL/OpenGLBuffer.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | ///////////////////////////////////////////////////////////////////////////// 9 | // VertexBuffer ///////////////////////////////////////////////////////////// 10 | ///////////////////////////////////////////////////////////////////////////// 11 | 12 | OpenGLVertexBuffer::OpenGLVertexBuffer(uint32_t size) 13 | { 14 | HZ_PROFILE_FUNCTION(); 15 | 16 | glCreateBuffers(1, &m_RendererID); 17 | glBindBuffer(GL_ARRAY_BUFFER, m_RendererID); 18 | glBufferData(GL_ARRAY_BUFFER, size, nullptr, GL_DYNAMIC_DRAW); 19 | } 20 | 21 | OpenGLVertexBuffer::OpenGLVertexBuffer(float* vertices, uint32_t size) 22 | { 23 | HZ_PROFILE_FUNCTION(); 24 | 25 | glCreateBuffers(1, &m_RendererID); 26 | glBindBuffer(GL_ARRAY_BUFFER, m_RendererID); 27 | glBufferData(GL_ARRAY_BUFFER, size, vertices, GL_STATIC_DRAW); 28 | } 29 | 30 | OpenGLVertexBuffer::~OpenGLVertexBuffer() 31 | { 32 | HZ_PROFILE_FUNCTION(); 33 | 34 | glDeleteBuffers(1, &m_RendererID); 35 | } 36 | 37 | void OpenGLVertexBuffer::Bind() const 38 | { 39 | HZ_PROFILE_FUNCTION(); 40 | 41 | glBindBuffer(GL_ARRAY_BUFFER, m_RendererID); 42 | } 43 | 44 | void OpenGLVertexBuffer::Unbind() const 45 | { 46 | HZ_PROFILE_FUNCTION(); 47 | 48 | glBindBuffer(GL_ARRAY_BUFFER, 0); 49 | } 50 | 51 | void OpenGLVertexBuffer::SetData(const void* data, uint32_t size) 52 | { 53 | glBindBuffer(GL_ARRAY_BUFFER, m_RendererID); 54 | glBufferSubData(GL_ARRAY_BUFFER, 0, size, data); 55 | } 56 | 57 | ///////////////////////////////////////////////////////////////////////////// 58 | // IndexBuffer ////////////////////////////////////////////////////////////// 59 | ///////////////////////////////////////////////////////////////////////////// 60 | 61 | OpenGLIndexBuffer::OpenGLIndexBuffer(uint32_t* indices, uint32_t count) 62 | : m_Count(count) 63 | { 64 | HZ_PROFILE_FUNCTION(); 65 | 66 | glCreateBuffers(1, &m_RendererID); 67 | 68 | // GL_ELEMENT_ARRAY_BUFFER is not valid without an actively bound VAO 69 | // Binding with GL_ARRAY_BUFFER allows the data to be loaded regardless of VAO state. 70 | glBindBuffer(GL_ARRAY_BUFFER, m_RendererID); 71 | glBufferData(GL_ARRAY_BUFFER, count * sizeof(uint32_t), indices, GL_STATIC_DRAW); 72 | } 73 | 74 | OpenGLIndexBuffer::~OpenGLIndexBuffer() 75 | { 76 | HZ_PROFILE_FUNCTION(); 77 | 78 | glDeleteBuffers(1, &m_RendererID); 79 | } 80 | 81 | void OpenGLIndexBuffer::Bind() const 82 | { 83 | HZ_PROFILE_FUNCTION(); 84 | 85 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_RendererID); 86 | } 87 | 88 | void OpenGLIndexBuffer::Unbind() const 89 | { 90 | HZ_PROFILE_FUNCTION(); 91 | 92 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLTexture.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/OpenGL/OpenGLTexture.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | OpenGLTexture2D::OpenGLTexture2D(uint32_t width, uint32_t height) 9 | : m_Width(width), m_Height(height) 10 | { 11 | HZ_PROFILE_FUNCTION(); 12 | 13 | m_InternalFormat = GL_RGBA8; 14 | m_DataFormat = GL_RGBA; 15 | 16 | glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID); 17 | glTextureStorage2D(m_RendererID, 1, m_InternalFormat, m_Width, m_Height); 18 | 19 | glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 20 | glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 21 | 22 | glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT); 23 | glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT); 24 | } 25 | 26 | OpenGLTexture2D::OpenGLTexture2D(const std::string& path) 27 | : m_Path(path) 28 | { 29 | HZ_PROFILE_FUNCTION(); 30 | 31 | int width, height, channels; 32 | stbi_set_flip_vertically_on_load(1); 33 | stbi_uc* data = nullptr; 34 | { 35 | HZ_PROFILE_SCOPE("stbi_load - OpenGLTexture2D::OpenGLTexture2D(const std::string&)"); 36 | data = stbi_load(path.c_str(), &width, &height, &channels, 0); 37 | } 38 | 39 | if (data) 40 | { 41 | m_IsLoaded = true; 42 | 43 | m_Width = width; 44 | m_Height = height; 45 | 46 | GLenum internalFormat = 0, dataFormat = 0; 47 | if (channels == 4) 48 | { 49 | internalFormat = GL_RGBA8; 50 | dataFormat = GL_RGBA; 51 | } 52 | else if (channels == 3) 53 | { 54 | internalFormat = GL_RGB8; 55 | dataFormat = GL_RGB; 56 | } 57 | 58 | m_InternalFormat = internalFormat; 59 | m_DataFormat = dataFormat; 60 | 61 | HZ_CORE_ASSERT(internalFormat & dataFormat, "Format not supported!"); 62 | 63 | glCreateTextures(GL_TEXTURE_2D, 1, &m_RendererID); 64 | glTextureStorage2D(m_RendererID, 1, internalFormat, m_Width, m_Height); 65 | 66 | glTextureParameteri(m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 67 | glTextureParameteri(m_RendererID, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 68 | 69 | glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_S, GL_REPEAT); 70 | glTextureParameteri(m_RendererID, GL_TEXTURE_WRAP_T, GL_REPEAT); 71 | 72 | glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, dataFormat, GL_UNSIGNED_BYTE, data); 73 | 74 | stbi_image_free(data); 75 | } 76 | } 77 | 78 | OpenGLTexture2D::~OpenGLTexture2D() 79 | { 80 | HZ_PROFILE_FUNCTION(); 81 | 82 | glDeleteTextures(1, &m_RendererID); 83 | } 84 | 85 | void OpenGLTexture2D::SetData(void* data, uint32_t size) 86 | { 87 | HZ_PROFILE_FUNCTION(); 88 | 89 | uint32_t bpp = m_DataFormat == GL_RGBA ? 4 : 3; 90 | HZ_CORE_ASSERT(size == m_Width * m_Height * bpp, "Data must be entire texture!"); 91 | glTextureSubImage2D(m_RendererID, 0, 0, 0, m_Width, m_Height, m_DataFormat, GL_UNSIGNED_BYTE, data); 92 | } 93 | 94 | void OpenGLTexture2D::Bind(uint32_t slot) const 95 | { 96 | HZ_PROFILE_FUNCTION(); 97 | 98 | glBindTextureUnit(slot, m_RendererID); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/Application.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Core/Application.h" 3 | 4 | #include "Hazel/Core/Log.h" 5 | 6 | #include "Hazel/Renderer/Renderer.h" 7 | 8 | #include "Hazel/Core/Input.h" 9 | 10 | #include 11 | 12 | namespace Hazel { 13 | 14 | Application* Application::s_Instance = nullptr; 15 | 16 | Application::Application(const std::string& name, ApplicationCommandLineArgs args) 17 | : m_CommandLineArgs(args) 18 | { 19 | HZ_PROFILE_FUNCTION(); 20 | 21 | HZ_CORE_ASSERT(!s_Instance, "Application already exists!"); 22 | s_Instance = this; 23 | m_Window = Window::Create(WindowProps(name)); 24 | m_Window->SetEventCallback(HZ_BIND_EVENT_FN(Application::OnEvent)); 25 | 26 | Renderer::Init(); 27 | 28 | m_ImGuiLayer = new ImGuiLayer(); 29 | PushOverlay(m_ImGuiLayer); 30 | } 31 | 32 | Application::~Application() 33 | { 34 | HZ_PROFILE_FUNCTION(); 35 | 36 | Renderer::Shutdown(); 37 | } 38 | 39 | void Application::PushLayer(Layer* layer) 40 | { 41 | HZ_PROFILE_FUNCTION(); 42 | 43 | m_LayerStack.PushLayer(layer); 44 | layer->OnAttach(); 45 | } 46 | 47 | void Application::PushOverlay(Layer* layer) 48 | { 49 | HZ_PROFILE_FUNCTION(); 50 | 51 | m_LayerStack.PushOverlay(layer); 52 | layer->OnAttach(); 53 | } 54 | 55 | void Application::Close() 56 | { 57 | m_Running = false; 58 | } 59 | 60 | void Application::OnEvent(Event& e) 61 | { 62 | HZ_PROFILE_FUNCTION(); 63 | 64 | EventDispatcher dispatcher(e); 65 | dispatcher.Dispatch(HZ_BIND_EVENT_FN(Application::OnWindowClose)); 66 | dispatcher.Dispatch(HZ_BIND_EVENT_FN(Application::OnWindowResize)); 67 | 68 | for (auto it = m_LayerStack.rbegin(); it != m_LayerStack.rend(); ++it) 69 | { 70 | if (e.Handled) 71 | break; 72 | (*it)->OnEvent(e); 73 | } 74 | } 75 | 76 | void Application::Run() 77 | { 78 | HZ_PROFILE_FUNCTION(); 79 | 80 | while (m_Running) 81 | { 82 | HZ_PROFILE_SCOPE("RunLoop"); 83 | 84 | float time = (float)glfwGetTime(); 85 | Timestep timestep = time - m_LastFrameTime; 86 | m_LastFrameTime = time; 87 | 88 | if (!m_Minimized) 89 | { 90 | { 91 | HZ_PROFILE_SCOPE("LayerStack OnUpdate"); 92 | 93 | for (Layer* layer : m_LayerStack) 94 | layer->OnUpdate(timestep); 95 | } 96 | 97 | m_ImGuiLayer->Begin(); 98 | { 99 | HZ_PROFILE_SCOPE("LayerStack OnImGuiRender"); 100 | 101 | for (Layer* layer : m_LayerStack) 102 | layer->OnImGuiRender(); 103 | } 104 | m_ImGuiLayer->End(); 105 | } 106 | 107 | m_Window->OnUpdate(); 108 | } 109 | } 110 | 111 | bool Application::OnWindowClose(WindowCloseEvent& e) 112 | { 113 | m_Running = false; 114 | return true; 115 | } 116 | 117 | bool Application::OnWindowResize(WindowResizeEvent& e) 118 | { 119 | HZ_PROFILE_FUNCTION(); 120 | 121 | if (e.GetWidth() == 0 || e.GetHeight() == 0) 122 | { 123 | m_Minimized = true; 124 | return false; 125 | } 126 | 127 | m_Minimized = false; 128 | Renderer::OnWindowResize(e.GetWidth(), e.GetHeight()); 129 | 130 | return false; 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/OrthographicCameraController.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/Renderer/OrthographicCameraController.h" 3 | 4 | #include "Hazel/Core/Input.h" 5 | #include "Hazel/Core/KeyCodes.h" 6 | 7 | namespace Hazel { 8 | 9 | OrthographicCameraController::OrthographicCameraController(float aspectRatio, bool rotation) 10 | : m_AspectRatio(aspectRatio), m_Camera(-m_AspectRatio * m_ZoomLevel, m_AspectRatio * m_ZoomLevel, -m_ZoomLevel, m_ZoomLevel), m_Rotation(rotation) 11 | { 12 | } 13 | 14 | void OrthographicCameraController::OnUpdate(Timestep ts) 15 | { 16 | HZ_PROFILE_FUNCTION(); 17 | 18 | if (Input::IsKeyPressed(Key::A)) 19 | { 20 | m_CameraPosition.x -= cos(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 21 | m_CameraPosition.y -= sin(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 22 | } 23 | else if (Input::IsKeyPressed(Key::D)) 24 | { 25 | m_CameraPosition.x += cos(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 26 | m_CameraPosition.y += sin(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 27 | } 28 | 29 | if (Input::IsKeyPressed(Key::W)) 30 | { 31 | m_CameraPosition.x += -sin(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 32 | m_CameraPosition.y += cos(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 33 | } 34 | else if (Input::IsKeyPressed(Key::S)) 35 | { 36 | m_CameraPosition.x -= -sin(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 37 | m_CameraPosition.y -= cos(glm::radians(m_CameraRotation)) * m_CameraTranslationSpeed * ts; 38 | } 39 | 40 | if (m_Rotation) 41 | { 42 | if (Input::IsKeyPressed(Key::Q)) 43 | m_CameraRotation += m_CameraRotationSpeed * ts; 44 | if (Input::IsKeyPressed(Key::E)) 45 | m_CameraRotation -= m_CameraRotationSpeed * ts; 46 | 47 | if (m_CameraRotation > 180.0f) 48 | m_CameraRotation -= 360.0f; 49 | else if (m_CameraRotation <= -180.0f) 50 | m_CameraRotation += 360.0f; 51 | 52 | m_Camera.SetRotation(m_CameraRotation); 53 | } 54 | 55 | m_Camera.SetPosition(m_CameraPosition); 56 | 57 | m_CameraTranslationSpeed = m_ZoomLevel; 58 | } 59 | 60 | void OrthographicCameraController::OnEvent(Event& e) 61 | { 62 | HZ_PROFILE_FUNCTION(); 63 | 64 | EventDispatcher dispatcher(e); 65 | dispatcher.Dispatch(HZ_BIND_EVENT_FN(OrthographicCameraController::OnMouseScrolled)); 66 | dispatcher.Dispatch(HZ_BIND_EVENT_FN(OrthographicCameraController::OnWindowResized)); 67 | } 68 | 69 | void OrthographicCameraController::OnResize(float width, float height) 70 | { 71 | m_AspectRatio = width / height; 72 | m_Camera.SetProjection(-m_AspectRatio * m_ZoomLevel, m_AspectRatio * m_ZoomLevel, -m_ZoomLevel, m_ZoomLevel); 73 | } 74 | 75 | bool OrthographicCameraController::OnMouseScrolled(MouseScrolledEvent& e) 76 | { 77 | HZ_PROFILE_FUNCTION(); 78 | 79 | m_ZoomLevel -= e.GetYOffset() * 0.25f; 80 | m_ZoomLevel = std::max(m_ZoomLevel, 0.25f); 81 | m_Camera.SetProjection(-m_AspectRatio * m_ZoomLevel, m_AspectRatio * m_ZoomLevel, -m_ZoomLevel, m_ZoomLevel); 82 | return false; 83 | } 84 | 85 | bool OrthographicCameraController::OnWindowResized(WindowResizeEvent& e) 86 | { 87 | HZ_PROFILE_FUNCTION(); 88 | 89 | OnResize((float)e.GetWidth(), (float)e.GetHeight()); 90 | return false; 91 | } 92 | 93 | } -------------------------------------------------------------------------------- /scripts/SetupVulkan.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import subprocess 4 | from pathlib import Path 5 | 6 | import Utils 7 | 8 | from io import BytesIO 9 | from urllib.request import urlopen 10 | 11 | class VulkanConfiguration: 12 | requiredVulkanVersion = "1.2.170.0" 13 | vulkanDirectory = "./Hazel/vendor/VulkanSDK" 14 | 15 | @classmethod 16 | def Validate(cls): 17 | if (not cls.CheckVulkanSDK()): 18 | print("Vulkan SDK not installed correctly.") 19 | return 20 | 21 | if (not cls.CheckVulkanSDKDebugLibs()): 22 | print("Vulkan SDK debug libs not found.") 23 | 24 | @classmethod 25 | def CheckVulkanSDK(cls): 26 | vulkanSDK = os.environ.get("VULKAN_SDK") 27 | if (vulkanSDK is None): 28 | print("\nYou don't have the Vulkan SDK installed!") 29 | cls.__InstallVulkanSDK() 30 | return False 31 | else: 32 | print(f"\nLocated Vulkan SDK at {vulkanSDK}") 33 | 34 | if (cls.requiredVulkanVersion not in vulkanSDK): 35 | print(f"You don't have the correct Vulkan SDK version! (Engine requires {cls.requiredVulkanVersion})") 36 | cls.__InstallVulkanSDK() 37 | return False 38 | 39 | print(f"Correct Vulkan SDK located at {vulkanSDK}") 40 | return True 41 | 42 | @classmethod 43 | def __InstallVulkanSDK(cls): 44 | permissionGranted = False 45 | while not permissionGranted: 46 | reply = str(input("Would you like to install VulkanSDK {0:s}? [Y/N]: ".format(cls.requiredVulkanVersion))).lower().strip()[:1] 47 | if reply == 'n': 48 | return 49 | permissionGranted = (reply == 'y') 50 | 51 | vulkanInstallURL = f"https://sdk.lunarg.com/sdk/download/{cls.requiredVulkanVersion}/windows/VulkanSDK-{cls.requiredVulkanVersion}-Installer.exe" 52 | vulkanPath = f"{cls.vulkanDirectory}/VulkanSDK-{cls.requiredVulkanVersion}-Installer.exe" 53 | print("Downloading {0:s} to {1:s}".format(vulkanInstallURL, vulkanPath)) 54 | Utils.DownloadFile(vulkanInstallURL, vulkanPath) 55 | print("Running Vulkan SDK installer...") 56 | os.startfile(os.path.abspath(vulkanPath)) 57 | print("Re-run this script after installation!") 58 | quit() 59 | 60 | @classmethod 61 | def CheckVulkanSDKDebugLibs(cls): 62 | shadercdLib = Path(f"{cls.vulkanDirectory}/Lib/shaderc_sharedd.lib") 63 | 64 | VulkanSDKDebugLibsURLlist = [ 65 | f"https://sdk.lunarg.com/sdk/download/{cls.requiredVulkanVersion}/windows/VulkanSDK-{cls.requiredVulkanVersion}-DebugLibs.zip", 66 | f"https://files.lunarg.com/SDK-{cls.requiredVulkanVersion}/VulkanSDK-{cls.requiredVulkanVersion}-DebugLibs.zip" 67 | ] 68 | 69 | if not shadercdLib.exists(): 70 | print(f"\nNo Vulkan SDK debug libs found. (Checked {shadercdLib})") 71 | vulkanPath = f"{cls.vulkanDirectory}/VulkanSDK-{cls.requiredVulkanVersion}-DebugLibs.zip" 72 | Utils.DownloadFile(VulkanSDKDebugLibsURLlist, vulkanPath) 73 | print("Extracting", vulkanPath) 74 | Utils.UnzipFile(vulkanPath, deleteZipFile=False) 75 | print(f"Vulkan SDK debug libs installed at {os.path.abspath(cls.vulkanDirectory)}") 76 | else: 77 | print(f"\nVulkan SDK debug libs located at {os.path.abspath(cls.vulkanDirectory)}") 78 | return True 79 | 80 | if __name__ == "__main__": 81 | VulkanConfiguration.Validate() 82 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/Buffer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Hazel { 4 | 5 | enum class ShaderDataType 6 | { 7 | None = 0, Float, Float2, Float3, Float4, Mat3, Mat4, Int, Int2, Int3, Int4, Bool 8 | }; 9 | 10 | static uint32_t ShaderDataTypeSize(ShaderDataType type) 11 | { 12 | switch (type) 13 | { 14 | case ShaderDataType::Float: return 4; 15 | case ShaderDataType::Float2: return 4 * 2; 16 | case ShaderDataType::Float3: return 4 * 3; 17 | case ShaderDataType::Float4: return 4 * 4; 18 | case ShaderDataType::Mat3: return 4 * 3 * 3; 19 | case ShaderDataType::Mat4: return 4 * 4 * 4; 20 | case ShaderDataType::Int: return 4; 21 | case ShaderDataType::Int2: return 4 * 2; 22 | case ShaderDataType::Int3: return 4 * 3; 23 | case ShaderDataType::Int4: return 4 * 4; 24 | case ShaderDataType::Bool: return 1; 25 | } 26 | 27 | HZ_CORE_ASSERT(false, "Unknown ShaderDataType!"); 28 | return 0; 29 | } 30 | 31 | struct BufferElement 32 | { 33 | std::string Name; 34 | ShaderDataType Type; 35 | uint32_t Size; 36 | size_t Offset; 37 | bool Normalized; 38 | 39 | BufferElement() = default; 40 | 41 | BufferElement(ShaderDataType type, const std::string& name, bool normalized = false) 42 | : Name(name), Type(type), Size(ShaderDataTypeSize(type)), Offset(0), Normalized(normalized) 43 | { 44 | } 45 | 46 | uint32_t GetComponentCount() const 47 | { 48 | switch (Type) 49 | { 50 | case ShaderDataType::Float: return 1; 51 | case ShaderDataType::Float2: return 2; 52 | case ShaderDataType::Float3: return 3; 53 | case ShaderDataType::Float4: return 4; 54 | case ShaderDataType::Mat3: return 3; // 3* float3 55 | case ShaderDataType::Mat4: return 4; // 4* float4 56 | case ShaderDataType::Int: return 1; 57 | case ShaderDataType::Int2: return 2; 58 | case ShaderDataType::Int3: return 3; 59 | case ShaderDataType::Int4: return 4; 60 | case ShaderDataType::Bool: return 1; 61 | } 62 | 63 | HZ_CORE_ASSERT(false, "Unknown ShaderDataType!"); 64 | return 0; 65 | } 66 | }; 67 | 68 | class BufferLayout 69 | { 70 | public: 71 | BufferLayout() {} 72 | 73 | BufferLayout(std::initializer_list elements) 74 | : m_Elements(elements) 75 | { 76 | CalculateOffsetsAndStride(); 77 | } 78 | 79 | uint32_t GetStride() const { return m_Stride; } 80 | const std::vector& GetElements() const { return m_Elements; } 81 | 82 | std::vector::iterator begin() { return m_Elements.begin(); } 83 | std::vector::iterator end() { return m_Elements.end(); } 84 | std::vector::const_iterator begin() const { return m_Elements.begin(); } 85 | std::vector::const_iterator end() const { return m_Elements.end(); } 86 | private: 87 | void CalculateOffsetsAndStride() 88 | { 89 | size_t offset = 0; 90 | m_Stride = 0; 91 | for (auto& element : m_Elements) 92 | { 93 | element.Offset = offset; 94 | offset += element.Size; 95 | m_Stride += element.Size; 96 | } 97 | } 98 | private: 99 | std::vector m_Elements; 100 | uint32_t m_Stride = 0; 101 | }; 102 | 103 | class VertexBuffer 104 | { 105 | public: 106 | virtual ~VertexBuffer() = default; 107 | 108 | virtual void Bind() const = 0; 109 | virtual void Unbind() const = 0; 110 | 111 | virtual void SetData(const void* data, uint32_t size) = 0; 112 | 113 | virtual const BufferLayout& GetLayout() const = 0; 114 | virtual void SetLayout(const BufferLayout& layout) = 0; 115 | 116 | static Ref Create(uint32_t size); 117 | static Ref Create(float* vertices, uint32_t size); 118 | }; 119 | 120 | // Currently Hazel only supports 32-bit index buffers 121 | class IndexBuffer 122 | { 123 | public: 124 | virtual ~IndexBuffer() = default; 125 | 126 | virtual void Bind() const = 0; 127 | virtual void Unbind() const = 0; 128 | 129 | virtual uint32_t GetCount() const = 0; 130 | 131 | static Ref Create(uint32_t* indices, uint32_t count); 132 | }; 133 | 134 | } 135 | -------------------------------------------------------------------------------- /Hazel/src/Platform/OpenGL/OpenGLVertexArray.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/OpenGL/OpenGLVertexArray.h" 3 | 4 | #include 5 | 6 | namespace Hazel { 7 | 8 | static GLenum ShaderDataTypeToOpenGLBaseType(ShaderDataType type) 9 | { 10 | switch (type) 11 | { 12 | case ShaderDataType::Float: return GL_FLOAT; 13 | case ShaderDataType::Float2: return GL_FLOAT; 14 | case ShaderDataType::Float3: return GL_FLOAT; 15 | case ShaderDataType::Float4: return GL_FLOAT; 16 | case ShaderDataType::Mat3: return GL_FLOAT; 17 | case ShaderDataType::Mat4: return GL_FLOAT; 18 | case ShaderDataType::Int: return GL_INT; 19 | case ShaderDataType::Int2: return GL_INT; 20 | case ShaderDataType::Int3: return GL_INT; 21 | case ShaderDataType::Int4: return GL_INT; 22 | case ShaderDataType::Bool: return GL_BOOL; 23 | } 24 | 25 | HZ_CORE_ASSERT(false, "Unknown ShaderDataType!"); 26 | return 0; 27 | } 28 | 29 | OpenGLVertexArray::OpenGLVertexArray() 30 | { 31 | HZ_PROFILE_FUNCTION(); 32 | 33 | glCreateVertexArrays(1, &m_RendererID); 34 | } 35 | 36 | OpenGLVertexArray::~OpenGLVertexArray() 37 | { 38 | HZ_PROFILE_FUNCTION(); 39 | 40 | glDeleteVertexArrays(1, &m_RendererID); 41 | } 42 | 43 | void OpenGLVertexArray::Bind() const 44 | { 45 | HZ_PROFILE_FUNCTION(); 46 | 47 | glBindVertexArray(m_RendererID); 48 | } 49 | 50 | void OpenGLVertexArray::Unbind() const 51 | { 52 | HZ_PROFILE_FUNCTION(); 53 | 54 | glBindVertexArray(0); 55 | } 56 | 57 | void OpenGLVertexArray::AddVertexBuffer(const Ref& vertexBuffer) 58 | { 59 | HZ_PROFILE_FUNCTION(); 60 | 61 | HZ_CORE_ASSERT(vertexBuffer->GetLayout().GetElements().size(), "Vertex Buffer has no layout!"); 62 | 63 | glBindVertexArray(m_RendererID); 64 | vertexBuffer->Bind(); 65 | 66 | const auto& layout = vertexBuffer->GetLayout(); 67 | for (const auto& element : layout) 68 | { 69 | switch (element.Type) 70 | { 71 | case ShaderDataType::Float: 72 | case ShaderDataType::Float2: 73 | case ShaderDataType::Float3: 74 | case ShaderDataType::Float4: 75 | { 76 | glEnableVertexAttribArray(m_VertexBufferIndex); 77 | glVertexAttribPointer(m_VertexBufferIndex, 78 | element.GetComponentCount(), 79 | ShaderDataTypeToOpenGLBaseType(element.Type), 80 | element.Normalized ? GL_TRUE : GL_FALSE, 81 | layout.GetStride(), 82 | (const void*)element.Offset); 83 | m_VertexBufferIndex++; 84 | break; 85 | } 86 | case ShaderDataType::Int: 87 | case ShaderDataType::Int2: 88 | case ShaderDataType::Int3: 89 | case ShaderDataType::Int4: 90 | case ShaderDataType::Bool: 91 | { 92 | glEnableVertexAttribArray(m_VertexBufferIndex); 93 | glVertexAttribIPointer(m_VertexBufferIndex, 94 | element.GetComponentCount(), 95 | ShaderDataTypeToOpenGLBaseType(element.Type), 96 | layout.GetStride(), 97 | (const void*)element.Offset); 98 | m_VertexBufferIndex++; 99 | break; 100 | } 101 | case ShaderDataType::Mat3: 102 | case ShaderDataType::Mat4: 103 | { 104 | uint8_t count = element.GetComponentCount(); 105 | for (uint8_t i = 0; i < count; i++) 106 | { 107 | glEnableVertexAttribArray(m_VertexBufferIndex); 108 | glVertexAttribPointer(m_VertexBufferIndex, 109 | count, 110 | ShaderDataTypeToOpenGLBaseType(element.Type), 111 | element.Normalized ? GL_TRUE : GL_FALSE, 112 | layout.GetStride(), 113 | (const void*)(element.Offset + sizeof(float) * count * i)); 114 | glVertexAttribDivisor(m_VertexBufferIndex, 1); 115 | m_VertexBufferIndex++; 116 | } 117 | break; 118 | } 119 | default: 120 | HZ_CORE_ASSERT(false, "Unknown ShaderDataType!"); 121 | } 122 | } 123 | 124 | m_VertexBuffers.push_back(vertexBuffer); 125 | } 126 | 127 | void OpenGLVertexArray::SetIndexBuffer(const Ref& indexBuffer) 128 | { 129 | HZ_PROFILE_FUNCTION(); 130 | 131 | glBindVertexArray(m_RendererID); 132 | indexBuffer->Bind(); 133 | 134 | m_IndexBuffer = indexBuffer; 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Renderer/EditorCamera.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "EditorCamera.h" 3 | 4 | #include "Hazel/Core/Input.h" 5 | #include "Hazel/Core/KeyCodes.h" 6 | #include "Hazel/Core/MouseCodes.h" 7 | 8 | #include 9 | 10 | #define GLM_ENABLE_EXPERIMENTAL 11 | #include 12 | 13 | namespace Hazel { 14 | 15 | EditorCamera::EditorCamera(float fov, float aspectRatio, float nearClip, float farClip) 16 | : m_FOV(fov), m_AspectRatio(aspectRatio), m_NearClip(nearClip), m_FarClip(farClip), Camera(glm::perspective(glm::radians(fov), aspectRatio, nearClip, farClip)) 17 | { 18 | UpdateView(); 19 | } 20 | 21 | void EditorCamera::UpdateProjection() 22 | { 23 | m_AspectRatio = m_ViewportWidth / m_ViewportHeight; 24 | m_Projection = glm::perspective(glm::radians(m_FOV), m_AspectRatio, m_NearClip, m_FarClip); 25 | } 26 | 27 | void EditorCamera::UpdateView() 28 | { 29 | // m_Yaw = m_Pitch = 0.0f; // Lock the camera's rotation 30 | m_Position = CalculatePosition(); 31 | 32 | glm::quat orientation = GetOrientation(); 33 | m_ViewMatrix = glm::translate(glm::mat4(1.0f), m_Position) * glm::toMat4(orientation); 34 | m_ViewMatrix = glm::inverse(m_ViewMatrix); 35 | } 36 | 37 | std::pair EditorCamera::PanSpeed() const 38 | { 39 | float x = std::min(m_ViewportWidth / 1000.0f, 2.4f); // max = 2.4f 40 | float xFactor = 0.0366f * (x * x) - 0.1778f * x + 0.3021f; 41 | 42 | float y = std::min(m_ViewportHeight / 1000.0f, 2.4f); // max = 2.4f 43 | float yFactor = 0.0366f * (y * y) - 0.1778f * y + 0.3021f; 44 | 45 | return { xFactor, yFactor }; 46 | } 47 | 48 | float EditorCamera::RotationSpeed() const 49 | { 50 | return 0.8f; 51 | } 52 | 53 | float EditorCamera::ZoomSpeed() const 54 | { 55 | float distance = m_Distance * 0.2f; 56 | distance = std::max(distance, 0.0f); 57 | float speed = distance * distance; 58 | speed = std::min(speed, 100.0f); // max speed = 100 59 | return speed; 60 | } 61 | 62 | void EditorCamera::OnUpdate(Timestep ts) 63 | { 64 | if (Input::IsKeyPressed(Key::LeftAlt)) 65 | { 66 | const glm::vec2& mouse{ Input::GetMouseX(), Input::GetMouseY() }; 67 | glm::vec2 delta = (mouse - m_InitialMousePosition) * 0.003f; 68 | m_InitialMousePosition = mouse; 69 | 70 | if (Input::IsMouseButtonPressed(Mouse::ButtonMiddle)) 71 | MousePan(delta); 72 | else if (Input::IsMouseButtonPressed(Mouse::ButtonLeft)) 73 | MouseRotate(delta); 74 | else if (Input::IsMouseButtonPressed(Mouse::ButtonRight)) 75 | MouseZoom(delta.y); 76 | } 77 | 78 | UpdateView(); 79 | } 80 | 81 | void EditorCamera::OnEvent(Event& e) 82 | { 83 | EventDispatcher dispatcher(e); 84 | dispatcher.Dispatch(HZ_BIND_EVENT_FN(EditorCamera::OnMouseScroll)); 85 | } 86 | 87 | bool EditorCamera::OnMouseScroll(MouseScrolledEvent& e) 88 | { 89 | float delta = e.GetYOffset() * 0.1f; 90 | MouseZoom(delta); 91 | UpdateView(); 92 | return false; 93 | } 94 | 95 | void EditorCamera::MousePan(const glm::vec2& delta) 96 | { 97 | auto [xSpeed, ySpeed] = PanSpeed(); 98 | m_FocalPoint += -GetRightDirection() * delta.x * xSpeed * m_Distance; 99 | m_FocalPoint += GetUpDirection() * delta.y * ySpeed * m_Distance; 100 | } 101 | 102 | void EditorCamera::MouseRotate(const glm::vec2& delta) 103 | { 104 | float yawSign = GetUpDirection().y < 0 ? -1.0f : 1.0f; 105 | m_Yaw += yawSign * delta.x * RotationSpeed(); 106 | m_Pitch += delta.y * RotationSpeed(); 107 | } 108 | 109 | void EditorCamera::MouseZoom(float delta) 110 | { 111 | m_Distance -= delta * ZoomSpeed(); 112 | if (m_Distance < 1.0f) 113 | { 114 | m_FocalPoint += GetForwardDirection(); 115 | m_Distance = 1.0f; 116 | } 117 | } 118 | 119 | glm::vec3 EditorCamera::GetUpDirection() const 120 | { 121 | return glm::rotate(GetOrientation(), glm::vec3(0.0f, 1.0f, 0.0f)); 122 | } 123 | 124 | glm::vec3 EditorCamera::GetRightDirection() const 125 | { 126 | return glm::rotate(GetOrientation(), glm::vec3(1.0f, 0.0f, 0.0f)); 127 | } 128 | 129 | glm::vec3 EditorCamera::GetForwardDirection() const 130 | { 131 | return glm::rotate(GetOrientation(), glm::vec3(0.0f, 0.0f, -1.0f)); 132 | } 133 | 134 | glm::vec3 EditorCamera::CalculatePosition() const 135 | { 136 | return m_FocalPoint - GetForwardDirection() * m_Distance; 137 | } 138 | 139 | glm::quat EditorCamera::GetOrientation() const 140 | { 141 | return glm::quat(glm::vec3(-m_Pitch, -m_Yaw, 0.0f)); 142 | } 143 | 144 | } 145 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Scene/Scene.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Scene.h" 3 | 4 | #include "Components.h" 5 | #include "Hazel/Renderer/Renderer2D.h" 6 | 7 | #include 8 | 9 | #include "Entity.h" 10 | 11 | namespace Hazel { 12 | 13 | Scene::Scene() 14 | { 15 | } 16 | 17 | Scene::~Scene() 18 | { 19 | } 20 | 21 | Entity Scene::CreateEntity(const std::string& name) 22 | { 23 | Entity entity = { m_Registry.create(), this }; 24 | entity.AddComponent(); 25 | auto& tag = entity.AddComponent(); 26 | tag.Tag = name.empty() ? "Entity" : name; 27 | return entity; 28 | } 29 | 30 | void Scene::DestroyEntity(Entity entity) 31 | { 32 | m_Registry.destroy(entity); 33 | } 34 | 35 | void Scene::OnUpdateRuntime(Timestep ts) 36 | { 37 | // Update scripts 38 | { 39 | m_Registry.view().each([=](auto entity, auto& nsc) 40 | { 41 | // TODO: Move to Scene::OnScenePlay 42 | if (!nsc.Instance) 43 | { 44 | nsc.Instance = nsc.InstantiateScript(); 45 | nsc.Instance->m_Entity = Entity{ entity, this }; 46 | nsc.Instance->OnCreate(); 47 | } 48 | 49 | nsc.Instance->OnUpdate(ts); 50 | }); 51 | } 52 | 53 | // Render 2D 54 | Camera* mainCamera = nullptr; 55 | glm::mat4 cameraTransform; 56 | { 57 | auto view = m_Registry.view(); 58 | for (auto entity : view) 59 | { 60 | auto [transform, camera] = view.get(entity); 61 | 62 | if (camera.Primary) 63 | { 64 | mainCamera = &camera.Camera; 65 | cameraTransform = transform.GetTransform(); 66 | break; 67 | } 68 | } 69 | } 70 | 71 | if (mainCamera) 72 | { 73 | Renderer2D::BeginScene(*mainCamera, cameraTransform); 74 | 75 | auto group = m_Registry.group(entt::get); 76 | for (auto entity : group) 77 | { 78 | auto [transform, sprite] = group.get(entity); 79 | 80 | Renderer2D::DrawSprite(transform.GetTransform(), sprite, (int)entity); 81 | } 82 | 83 | Renderer2D::EndScene(); 84 | } 85 | 86 | } 87 | 88 | void Scene::OnUpdateEditor(Timestep ts, EditorCamera& camera) 89 | { 90 | Renderer2D::BeginScene(camera); 91 | 92 | auto group = m_Registry.group(entt::get); 93 | for (auto entity : group) 94 | { 95 | auto [transform, sprite] = group.get(entity); 96 | 97 | Renderer2D::DrawSprite(transform.GetTransform(), sprite, (int)entity); 98 | } 99 | 100 | Renderer2D::EndScene(); 101 | } 102 | 103 | void Scene::OnViewportResize(uint32_t width, uint32_t height) 104 | { 105 | m_ViewportWidth = width; 106 | m_ViewportHeight = height; 107 | 108 | // Resize our non-FixedAspectRatio cameras 109 | auto view = m_Registry.view(); 110 | for (auto entity : view) 111 | { 112 | auto& cameraComponent = view.get(entity); 113 | if (!cameraComponent.FixedAspectRatio) 114 | cameraComponent.Camera.SetViewportSize(width, height); 115 | } 116 | 117 | } 118 | 119 | Entity Scene::GetPrimaryCameraEntity() 120 | { 121 | auto view = m_Registry.view(); 122 | for (auto entity : view) 123 | { 124 | const auto& camera = view.get(entity); 125 | if (camera.Primary) 126 | return Entity{entity, this}; 127 | } 128 | return {}; 129 | } 130 | 131 | template 132 | void Scene::OnComponentAdded(Entity entity, T& component) 133 | { 134 | static_assert(false); 135 | } 136 | 137 | template<> 138 | void Scene::OnComponentAdded(Entity entity, TransformComponent& component) 139 | { 140 | } 141 | 142 | template<> 143 | void Scene::OnComponentAdded(Entity entity, CameraComponent& component) 144 | { 145 | if (m_ViewportWidth > 0 && m_ViewportHeight > 0) 146 | component.Camera.SetViewportSize(m_ViewportWidth, m_ViewportHeight); 147 | } 148 | 149 | template<> 150 | void Scene::OnComponentAdded(Entity entity, SpriteRendererComponent& component) 151 | { 152 | } 153 | 154 | template<> 155 | void Scene::OnComponentAdded(Entity entity, TagComponent& component) 156 | { 157 | } 158 | 159 | template<> 160 | void Scene::OnComponentAdded(Entity entity, NativeScriptComponent& component) 161 | { 162 | } 163 | 164 | 165 | } 166 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/Core/KeyCodes.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace Hazel 4 | { 5 | using KeyCode = uint16_t; 6 | 7 | namespace Key 8 | { 9 | enum : KeyCode 10 | { 11 | // From glfw3.h 12 | Space = 32, 13 | Apostrophe = 39, /* ' */ 14 | Comma = 44, /* , */ 15 | Minus = 45, /* - */ 16 | Period = 46, /* . */ 17 | Slash = 47, /* / */ 18 | 19 | D0 = 48, /* 0 */ 20 | D1 = 49, /* 1 */ 21 | D2 = 50, /* 2 */ 22 | D3 = 51, /* 3 */ 23 | D4 = 52, /* 4 */ 24 | D5 = 53, /* 5 */ 25 | D6 = 54, /* 6 */ 26 | D7 = 55, /* 7 */ 27 | D8 = 56, /* 8 */ 28 | D9 = 57, /* 9 */ 29 | 30 | Semicolon = 59, /* ; */ 31 | Equal = 61, /* = */ 32 | 33 | A = 65, 34 | B = 66, 35 | C = 67, 36 | D = 68, 37 | E = 69, 38 | F = 70, 39 | G = 71, 40 | H = 72, 41 | I = 73, 42 | J = 74, 43 | K = 75, 44 | L = 76, 45 | M = 77, 46 | N = 78, 47 | O = 79, 48 | P = 80, 49 | Q = 81, 50 | R = 82, 51 | S = 83, 52 | T = 84, 53 | U = 85, 54 | V = 86, 55 | W = 87, 56 | X = 88, 57 | Y = 89, 58 | Z = 90, 59 | 60 | LeftBracket = 91, /* [ */ 61 | Backslash = 92, /* \ */ 62 | RightBracket = 93, /* ] */ 63 | GraveAccent = 96, /* ` */ 64 | 65 | World1 = 161, /* non-US #1 */ 66 | World2 = 162, /* non-US #2 */ 67 | 68 | /* Function keys */ 69 | Escape = 256, 70 | Enter = 257, 71 | Tab = 258, 72 | Backspace = 259, 73 | Insert = 260, 74 | Delete = 261, 75 | Right = 262, 76 | Left = 263, 77 | Down = 264, 78 | Up = 265, 79 | PageUp = 266, 80 | PageDown = 267, 81 | Home = 268, 82 | End = 269, 83 | CapsLock = 280, 84 | ScrollLock = 281, 85 | NumLock = 282, 86 | PrintScreen = 283, 87 | Pause = 284, 88 | F1 = 290, 89 | F2 = 291, 90 | F3 = 292, 91 | F4 = 293, 92 | F5 = 294, 93 | F6 = 295, 94 | F7 = 296, 95 | F8 = 297, 96 | F9 = 298, 97 | F10 = 299, 98 | F11 = 300, 99 | F12 = 301, 100 | F13 = 302, 101 | F14 = 303, 102 | F15 = 304, 103 | F16 = 305, 104 | F17 = 306, 105 | F18 = 307, 106 | F19 = 308, 107 | F20 = 309, 108 | F21 = 310, 109 | F22 = 311, 110 | F23 = 312, 111 | F24 = 313, 112 | F25 = 314, 113 | 114 | /* Keypad */ 115 | KP0 = 320, 116 | KP1 = 321, 117 | KP2 = 322, 118 | KP3 = 323, 119 | KP4 = 324, 120 | KP5 = 325, 121 | KP6 = 326, 122 | KP7 = 327, 123 | KP8 = 328, 124 | KP9 = 329, 125 | KPDecimal = 330, 126 | KPDivide = 331, 127 | KPMultiply = 332, 128 | KPSubtract = 333, 129 | KPAdd = 334, 130 | KPEnter = 335, 131 | KPEqual = 336, 132 | 133 | LeftShift = 340, 134 | LeftControl = 341, 135 | LeftAlt = 342, 136 | LeftSuper = 343, 137 | RightShift = 344, 138 | RightControl = 345, 139 | RightAlt = 346, 140 | RightSuper = 347, 141 | Menu = 348 142 | }; 143 | } 144 | } -------------------------------------------------------------------------------- /Sandbox/assets/shaders/Texture.glsl: -------------------------------------------------------------------------------- 1 | // Basic Texture Shader 2 | 3 | #type vertex 4 | #version 450 core 5 | 6 | layout(location = 0) in vec3 a_Position; 7 | layout(location = 1) in vec4 a_Color; 8 | layout(location = 2) in vec2 a_TexCoord; 9 | layout(location = 3) in float a_TexIndex; 10 | layout(location = 4) in float a_TilingFactor; 11 | layout(location = 5) in int a_EntityID; 12 | 13 | layout(std140, binding = 0) uniform Camera 14 | { 15 | mat4 u_ViewProjection; 16 | }; 17 | 18 | struct VertexOutput 19 | { 20 | vec4 Color; 21 | vec2 TexCoord; 22 | float TexIndex; 23 | float TilingFactor; 24 | }; 25 | 26 | layout (location = 0) out VertexOutput Output; 27 | layout (location = 4) out flat int v_EntityID; 28 | 29 | void main() 30 | { 31 | Output.Color = a_Color; 32 | Output.TexCoord = a_TexCoord; 33 | Output.TexIndex = a_TexIndex; 34 | Output.TilingFactor = a_TilingFactor; 35 | v_EntityID = a_EntityID; 36 | 37 | gl_Position = u_ViewProjection * vec4(a_Position, 1.0); 38 | } 39 | 40 | #type fragment 41 | #version 450 core 42 | 43 | layout(location = 0) out vec4 color; 44 | layout(location = 1) out int color2; 45 | 46 | struct VertexOutput 47 | { 48 | vec4 Color; 49 | vec2 TexCoord; 50 | float TexIndex; 51 | float TilingFactor; 52 | }; 53 | 54 | layout (location = 0) in VertexOutput Input; 55 | layout (location = 4) in flat int v_EntityID; 56 | 57 | layout (binding = 0) uniform sampler2D u_Textures[32]; 58 | 59 | void main() 60 | { 61 | vec4 texColor = Input.Color; 62 | 63 | switch(int(Input.TexIndex)) 64 | { 65 | case 0: texColor *= texture(u_Textures[ 0], Input.TexCoord * Input.TilingFactor); break; 66 | case 1: texColor *= texture(u_Textures[ 1], Input.TexCoord * Input.TilingFactor); break; 67 | case 2: texColor *= texture(u_Textures[ 2], Input.TexCoord * Input.TilingFactor); break; 68 | case 3: texColor *= texture(u_Textures[ 3], Input.TexCoord * Input.TilingFactor); break; 69 | case 4: texColor *= texture(u_Textures[ 4], Input.TexCoord * Input.TilingFactor); break; 70 | case 5: texColor *= texture(u_Textures[ 5], Input.TexCoord * Input.TilingFactor); break; 71 | case 6: texColor *= texture(u_Textures[ 6], Input.TexCoord * Input.TilingFactor); break; 72 | case 7: texColor *= texture(u_Textures[ 7], Input.TexCoord * Input.TilingFactor); break; 73 | case 8: texColor *= texture(u_Textures[ 8], Input.TexCoord * Input.TilingFactor); break; 74 | case 9: texColor *= texture(u_Textures[ 9], Input.TexCoord * Input.TilingFactor); break; 75 | case 10: texColor *= texture(u_Textures[10], Input.TexCoord * Input.TilingFactor); break; 76 | case 11: texColor *= texture(u_Textures[11], Input.TexCoord * Input.TilingFactor); break; 77 | case 12: texColor *= texture(u_Textures[12], Input.TexCoord * Input.TilingFactor); break; 78 | case 13: texColor *= texture(u_Textures[13], Input.TexCoord * Input.TilingFactor); break; 79 | case 14: texColor *= texture(u_Textures[14], Input.TexCoord * Input.TilingFactor); break; 80 | case 15: texColor *= texture(u_Textures[15], Input.TexCoord * Input.TilingFactor); break; 81 | case 16: texColor *= texture(u_Textures[16], Input.TexCoord * Input.TilingFactor); break; 82 | case 17: texColor *= texture(u_Textures[17], Input.TexCoord * Input.TilingFactor); break; 83 | case 18: texColor *= texture(u_Textures[18], Input.TexCoord * Input.TilingFactor); break; 84 | case 19: texColor *= texture(u_Textures[19], Input.TexCoord * Input.TilingFactor); break; 85 | case 20: texColor *= texture(u_Textures[20], Input.TexCoord * Input.TilingFactor); break; 86 | case 21: texColor *= texture(u_Textures[21], Input.TexCoord * Input.TilingFactor); break; 87 | case 22: texColor *= texture(u_Textures[22], Input.TexCoord * Input.TilingFactor); break; 88 | case 23: texColor *= texture(u_Textures[23], Input.TexCoord * Input.TilingFactor); break; 89 | case 24: texColor *= texture(u_Textures[24], Input.TexCoord * Input.TilingFactor); break; 90 | case 25: texColor *= texture(u_Textures[25], Input.TexCoord * Input.TilingFactor); break; 91 | case 26: texColor *= texture(u_Textures[26], Input.TexCoord * Input.TilingFactor); break; 92 | case 27: texColor *= texture(u_Textures[27], Input.TexCoord * Input.TilingFactor); break; 93 | case 28: texColor *= texture(u_Textures[28], Input.TexCoord * Input.TilingFactor); break; 94 | case 29: texColor *= texture(u_Textures[29], Input.TexCoord * Input.TilingFactor); break; 95 | case 30: texColor *= texture(u_Textures[30], Input.TexCoord * Input.TilingFactor); break; 96 | case 31: texColor *= texture(u_Textures[31], Input.TexCoord * Input.TilingFactor); break; 97 | } 98 | color = texColor; 99 | 100 | color2 = v_EntityID; 101 | } 102 | -------------------------------------------------------------------------------- /Hazelnut/assets/shaders/Texture.glsl: -------------------------------------------------------------------------------- 1 | // Basic Texture Shader 2 | 3 | #type vertex 4 | #version 450 core 5 | 6 | layout(location = 0) in vec3 a_Position; 7 | layout(location = 1) in vec4 a_Color; 8 | layout(location = 2) in vec2 a_TexCoord; 9 | layout(location = 3) in float a_TexIndex; 10 | layout(location = 4) in float a_TilingFactor; 11 | layout(location = 5) in int a_EntityID; 12 | 13 | layout(std140, binding = 0) uniform Camera 14 | { 15 | mat4 u_ViewProjection; 16 | }; 17 | 18 | struct VertexOutput 19 | { 20 | vec4 Color; 21 | vec2 TexCoord; 22 | float TilingFactor; 23 | }; 24 | 25 | layout (location = 0) out VertexOutput Output; 26 | layout (location = 3) out flat float v_TexIndex; 27 | layout (location = 4) out flat int v_EntityID; 28 | 29 | void main() 30 | { 31 | Output.Color = a_Color; 32 | Output.TexCoord = a_TexCoord; 33 | Output.TilingFactor = a_TilingFactor; 34 | v_TexIndex = a_TexIndex; 35 | v_EntityID = a_EntityID; 36 | 37 | gl_Position = u_ViewProjection * vec4(a_Position, 1.0); 38 | } 39 | 40 | #type fragment 41 | #version 450 core 42 | 43 | layout(location = 0) out vec4 color; 44 | layout(location = 1) out int color2; 45 | 46 | struct VertexOutput 47 | { 48 | vec4 Color; 49 | vec2 TexCoord; 50 | float TilingFactor; 51 | }; 52 | 53 | layout (location = 0) in VertexOutput Input; 54 | layout (location = 3) in flat float v_TexIndex; 55 | layout (location = 4) in flat int v_EntityID; 56 | 57 | layout (binding = 0) uniform sampler2D u_Textures[32]; 58 | 59 | void main() 60 | { 61 | vec4 texColor = Input.Color; 62 | 63 | switch(int(v_TexIndex)) 64 | { 65 | case 0: texColor *= texture(u_Textures[ 0], Input.TexCoord * Input.TilingFactor); break; 66 | case 1: texColor *= texture(u_Textures[ 1], Input.TexCoord * Input.TilingFactor); break; 67 | case 2: texColor *= texture(u_Textures[ 2], Input.TexCoord * Input.TilingFactor); break; 68 | case 3: texColor *= texture(u_Textures[ 3], Input.TexCoord * Input.TilingFactor); break; 69 | case 4: texColor *= texture(u_Textures[ 4], Input.TexCoord * Input.TilingFactor); break; 70 | case 5: texColor *= texture(u_Textures[ 5], Input.TexCoord * Input.TilingFactor); break; 71 | case 6: texColor *= texture(u_Textures[ 6], Input.TexCoord * Input.TilingFactor); break; 72 | case 7: texColor *= texture(u_Textures[ 7], Input.TexCoord * Input.TilingFactor); break; 73 | case 8: texColor *= texture(u_Textures[ 8], Input.TexCoord * Input.TilingFactor); break; 74 | case 9: texColor *= texture(u_Textures[ 9], Input.TexCoord * Input.TilingFactor); break; 75 | case 10: texColor *= texture(u_Textures[10], Input.TexCoord * Input.TilingFactor); break; 76 | case 11: texColor *= texture(u_Textures[11], Input.TexCoord * Input.TilingFactor); break; 77 | case 12: texColor *= texture(u_Textures[12], Input.TexCoord * Input.TilingFactor); break; 78 | case 13: texColor *= texture(u_Textures[13], Input.TexCoord * Input.TilingFactor); break; 79 | case 14: texColor *= texture(u_Textures[14], Input.TexCoord * Input.TilingFactor); break; 80 | case 15: texColor *= texture(u_Textures[15], Input.TexCoord * Input.TilingFactor); break; 81 | case 16: texColor *= texture(u_Textures[16], Input.TexCoord * Input.TilingFactor); break; 82 | case 17: texColor *= texture(u_Textures[17], Input.TexCoord * Input.TilingFactor); break; 83 | case 18: texColor *= texture(u_Textures[18], Input.TexCoord * Input.TilingFactor); break; 84 | case 19: texColor *= texture(u_Textures[19], Input.TexCoord * Input.TilingFactor); break; 85 | case 20: texColor *= texture(u_Textures[20], Input.TexCoord * Input.TilingFactor); break; 86 | case 21: texColor *= texture(u_Textures[21], Input.TexCoord * Input.TilingFactor); break; 87 | case 22: texColor *= texture(u_Textures[22], Input.TexCoord * Input.TilingFactor); break; 88 | case 23: texColor *= texture(u_Textures[23], Input.TexCoord * Input.TilingFactor); break; 89 | case 24: texColor *= texture(u_Textures[24], Input.TexCoord * Input.TilingFactor); break; 90 | case 25: texColor *= texture(u_Textures[25], Input.TexCoord * Input.TilingFactor); break; 91 | case 26: texColor *= texture(u_Textures[26], Input.TexCoord * Input.TilingFactor); break; 92 | case 27: texColor *= texture(u_Textures[27], Input.TexCoord * Input.TilingFactor); break; 93 | case 28: texColor *= texture(u_Textures[28], Input.TexCoord * Input.TilingFactor); break; 94 | case 29: texColor *= texture(u_Textures[29], Input.TexCoord * Input.TilingFactor); break; 95 | case 30: texColor *= texture(u_Textures[30], Input.TexCoord * Input.TilingFactor); break; 96 | case 31: texColor *= texture(u_Textures[31], Input.TexCoord * Input.TilingFactor); break; 97 | } 98 | color = texColor; 99 | 100 | color2 = v_EntityID; 101 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hazel [![License](https://img.shields.io/github/license/TheCherno/Hazel.svg)](https://github.com/TheCherno/Hazel/blob/master/LICENSE) 2 | 3 | ![Hazel](/Resources/Branding/Hazel_Logo_Text_Light_Square.png?raw=true "Hazel") 4 | 5 | Hazel is primarily an early-stage interactive application and rendering engine for Windows. Currently not much is implemented, however (almost) everything inside this repository is being created within YouTube videos, found at [thecherno.com/engine](https://thecherno.com/engine). 6 | 7 | *** 8 | 9 | ## Getting Started 10 | Visual Studio 2017 or 2019 is recommended, Hazel is officially untested on other development environments whilst we focus on a Windows build. 11 | 12 | **1. Downloading the repository:** 13 | 14 | Start by cloning the repository with `git clone --recursive https://github.com/TheCherno/Hazel`. 15 | 16 | If the repository was cloned non-recursively previously, use `git submodule update --init` to clone the necessary submodules. 17 | 18 | **2. Configuring the dependencies:** 19 | 20 | 1. Run the [Setup.bat](https://github.com/TheCherno/Hazel/blob/master/scripts/Setup.bat) file found in `scripts` folder. This will download the required prerequisites for the project if they are not present yet. 21 | 2. One prerequisite is the Vulkan SDK. If it is not installed, the script will execute the `VulkanSDK.exe` file, and will prompt the user to install the SDK. 22 | 3. After installation, run the [Setup.bat](https://github.com/TheCherno/Hazel/blob/master/scripts/Setup.bat) file again. If the Vulkan SDK is installed properly, it will then download the Vulkan SDK Debug libraries. (This may take a longer amount of time) 23 | 4. After downloading and unzipping the files, the [Win-GenProjects.bat](https://github.com/TheCherno/Hazel/blob/master/scripts/Win-GenProjects.bat) script file will get executed automatically, which will then generate a Visual Studio solution file for user's usage. 24 | 25 | If changes are made, or if you want to regenerate project files, rerun the [Win-GenProjects.bat](https://github.com/TheCherno/Hazel/blob/master/scripts/Win-GenProjects.bat) script file found in `scripts` folder. 26 | 27 | *** 28 | 29 | ## The Plan 30 | The plan for Hazel is two-fold: to create a powerful 3D engine, but also to serve as an education tool for teaching game engine design and architecture. Because of this the development inside this repository is rather slow, since everything has to be taught and implemented on-camera. There is a much more advanced version of the engine in a private repository called `Hazel-dev`, accessible to supporters on [Patreon](https://patreon.com/thecherno). The plan for this project is to mostly take already implemented code from the `Hazel-dev` repository and integrate it into this one, done within videos and supported by explanations. 31 | 32 | ### Main features to come: 33 | - Fast 2D rendering (UI, particles, sprites, etc.) 34 | - High-fidelity Physically-Based 3D rendering (this will be expanded later, 2D to come first) 35 | - Support for Mac, Linux, Android and iOS 36 | - Native rendering API support (DirectX, Vulkan, Metal) 37 | - Fully featured viewer and editor applications 38 | - Fully scripted interaction and behavior 39 | - Integrated 3rd party 2D and 3D physics engine 40 | - Procedural terrain and world generation 41 | - Artificial Intelligence 42 | - Audio system 43 | 44 | 45 | ## Short term goals : 46 | *Note: this is subject to change at any time! Follow the roadmap over at [hazelengine.com/roadmap](http://hazelengine.com/roadmap).* 47 | 48 | By the end 2020, we want to make a game using the Hazel game engine. Not like the time I made a game in one hour using the engine, but this time by using the proper tools that would be required to make a game with Hazel. This means we need to add a full 2D workflow: 49 | 50 | - Design the game scene by using Hazelnut, the Hazel editor, 51 | - Test the game inside Hazelnut, including the ability to save/load the created game, 52 | - Load and play the game inside Sandbox. 53 | 54 | We want everyone to be able to play the game on all desktop platforms (Windows, Mac and Linux). When this is implemented, another attempt at the "Creating a game in one hour using Hazel" will be made to see how far the engine has become. 55 | 56 | [![Twitter](https://img.shields.io/badge/%40thecherno--blue.svg?style=social&logo=Twitter)](https://twitter.com/thecherno) 57 | [![Instagram](https://img.shields.io/badge/thecherno--red.svg?style=social&logo=Instagram)](https://www.instagram.com/thecherno) 58 | [![Youtube](https://img.shields.io/badge/TheChernoProject--red.svg?style=social&logo=youtube)](https://www.youtube.com/user/TheChernoProject) 59 | [![Discord](https://img.shields.io/badge/TheCherno%20Server--blue.svg?style=social&logo=Discord)](https://discord.gg/K2eSyQA) 60 | [![Patreon](https://img.shields.io/badge/%40thecherno--green.svg?style=social&logo=Patreon)](https://patreon.com/thecherno) 61 | -------------------------------------------------------------------------------- /Hazel/src/Hazel/ImGui/ImGuiLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Hazel/ImGui/ImGuiLayer.h" 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "Hazel/Core/Application.h" 9 | 10 | // TEMPORARY 11 | #include 12 | #include 13 | 14 | #include "ImGuizmo.h" 15 | 16 | namespace Hazel { 17 | 18 | ImGuiLayer::ImGuiLayer() 19 | : Layer("ImGuiLayer") 20 | { 21 | } 22 | 23 | void ImGuiLayer::OnAttach() 24 | { 25 | HZ_PROFILE_FUNCTION(); 26 | 27 | // Setup Dear ImGui context 28 | IMGUI_CHECKVERSION(); 29 | ImGui::CreateContext(); 30 | ImGuiIO& io = ImGui::GetIO(); (void)io; 31 | io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls 32 | //io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls 33 | io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking 34 | io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport / Platform Windows 35 | //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoTaskBarIcons; 36 | //io.ConfigFlags |= ImGuiConfigFlags_ViewportsNoMerge; 37 | 38 | float fontSize = 18.0f;// *2.0f; 39 | io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Bold.ttf", fontSize); 40 | io.FontDefault = io.Fonts->AddFontFromFileTTF("assets/fonts/opensans/OpenSans-Regular.ttf", fontSize); 41 | 42 | // Setup Dear ImGui style 43 | ImGui::StyleColorsDark(); 44 | //ImGui::StyleColorsClassic(); 45 | 46 | // When viewports are enabled we tweak WindowRounding/WindowBg so platform windows can look identical to regular ones. 47 | ImGuiStyle& style = ImGui::GetStyle(); 48 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 49 | { 50 | style.WindowRounding = 0.0f; 51 | style.Colors[ImGuiCol_WindowBg].w = 1.0f; 52 | } 53 | 54 | SetDarkThemeColors(); 55 | 56 | Application& app = Application::Get(); 57 | GLFWwindow* window = static_cast(app.GetWindow().GetNativeWindow()); 58 | 59 | // Setup Platform/Renderer bindings 60 | ImGui_ImplGlfw_InitForOpenGL(window, true); 61 | ImGui_ImplOpenGL3_Init("#version 410"); 62 | } 63 | 64 | void ImGuiLayer::OnDetach() 65 | { 66 | HZ_PROFILE_FUNCTION(); 67 | 68 | ImGui_ImplOpenGL3_Shutdown(); 69 | ImGui_ImplGlfw_Shutdown(); 70 | ImGui::DestroyContext(); 71 | } 72 | 73 | void ImGuiLayer::OnEvent(Event& e) 74 | { 75 | if (m_BlockEvents) 76 | { 77 | ImGuiIO& io = ImGui::GetIO(); 78 | e.Handled |= e.IsInCategory(EventCategoryMouse) & io.WantCaptureMouse; 79 | e.Handled |= e.IsInCategory(EventCategoryKeyboard) & io.WantCaptureKeyboard; 80 | } 81 | } 82 | 83 | void ImGuiLayer::Begin() 84 | { 85 | HZ_PROFILE_FUNCTION(); 86 | 87 | ImGui_ImplOpenGL3_NewFrame(); 88 | ImGui_ImplGlfw_NewFrame(); 89 | ImGui::NewFrame(); 90 | ImGuizmo::BeginFrame(); 91 | } 92 | 93 | void ImGuiLayer::End() 94 | { 95 | HZ_PROFILE_FUNCTION(); 96 | 97 | ImGuiIO& io = ImGui::GetIO(); 98 | Application& app = Application::Get(); 99 | io.DisplaySize = ImVec2((float)app.GetWindow().GetWidth(), (float)app.GetWindow().GetHeight()); 100 | 101 | // Rendering 102 | ImGui::Render(); 103 | ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData()); 104 | 105 | if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) 106 | { 107 | GLFWwindow* backup_current_context = glfwGetCurrentContext(); 108 | ImGui::UpdatePlatformWindows(); 109 | ImGui::RenderPlatformWindowsDefault(); 110 | glfwMakeContextCurrent(backup_current_context); 111 | } 112 | } 113 | 114 | void ImGuiLayer::SetDarkThemeColors() 115 | { 116 | auto& colors = ImGui::GetStyle().Colors; 117 | colors[ImGuiCol_WindowBg] = ImVec4{ 0.1f, 0.105f, 0.11f, 1.0f }; 118 | 119 | // Headers 120 | colors[ImGuiCol_Header] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; 121 | colors[ImGuiCol_HeaderHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; 122 | colors[ImGuiCol_HeaderActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 123 | 124 | // Buttons 125 | colors[ImGuiCol_Button] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; 126 | colors[ImGuiCol_ButtonHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; 127 | colors[ImGuiCol_ButtonActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 128 | 129 | // Frame BG 130 | colors[ImGuiCol_FrameBg] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; 131 | colors[ImGuiCol_FrameBgHovered] = ImVec4{ 0.3f, 0.305f, 0.31f, 1.0f }; 132 | colors[ImGuiCol_FrameBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 133 | 134 | // Tabs 135 | colors[ImGuiCol_Tab] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 136 | colors[ImGuiCol_TabHovered] = ImVec4{ 0.38f, 0.3805f, 0.381f, 1.0f }; 137 | colors[ImGuiCol_TabActive] = ImVec4{ 0.28f, 0.2805f, 0.281f, 1.0f }; 138 | colors[ImGuiCol_TabUnfocused] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 139 | colors[ImGuiCol_TabUnfocusedActive] = ImVec4{ 0.2f, 0.205f, 0.21f, 1.0f }; 140 | 141 | // Title 142 | colors[ImGuiCol_TitleBg] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 143 | colors[ImGuiCol_TitleBgActive] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 144 | colors[ImGuiCol_TitleBgCollapsed] = ImVec4{ 0.15f, 0.1505f, 0.151f, 1.0f }; 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing to Hazel! 2 | ====================== 3 | 4 | Thanks for your interest in contributing to Hazel! :tada: We love getting [pull requests](https://www.quora.com/GitHub-What-is-a-pull-request) for bugfixes and contributions of our community to keep Hazel growing. 5 | 6 | We want to keep it as easy as possible to contribute changes. These guidelines are intended to help smooth that process, and allow us to review and approve your changes quickly and easily. Improvements are always welcome! Feel free to [open an issue][issue-tracker] or [submit a new pull request][submit-pr]. And finally, these are just guidelines, not rules, so use your best judgement when necessary. 7 | 8 | If you're new to [GitHub][github], you may want to begin with [Getting Started with GitHub](https://help.github.com/en/categories/getting-started-with-github) and Thinkful's [GitHub Pull Request Tutorial](https://www.thinkful.com/learn/github-pull-request-tutorial/). 9 | 10 | ## Language 11 | 12 | As TheCherno creates his videos about Hazel in English, the devs ask to keep the code base, issues and pull requests in English only. 13 | Thanks for your understanding. 14 | 15 | ## Reporting Bugs 16 | 17 | Bugs should be reported on our [GitHub Issue Tracker][issue-tracker] using the bug report template. 18 | 19 | Follow the advice in [How do I ask a good question?][how-to-ask]. While the article is intended for people asking questions on Stack Overflow, it all applies to writing a good bug report too. 20 | 21 | ## Requesting New Features 22 | 23 | Feature requests should also be sent to our [GitHub Issue Tracker][issue-tracker] using the feature request template. 24 | 25 | - Explain the problem that you're having, and anything you've tried to solve it using the currently available features. 26 | 27 | - Explain how this new feature will help. 28 | 29 | - If possible, provide an example, like a code snippet, showing what your new feature might look like in use. 30 | 31 | Also, much of the advice in [How do I ask a good question?][how-to-ask] applies here too. 32 | 33 | ## Contributing a Fix or Feature 34 | 35 | You've created a new fix or feature for Hazel. Awesome! 36 | 37 | 1. If you haven't already, create a fork of the Hazel repository. 38 | 39 | 2. Create a topic branch, and make all of your changes on that branch. 40 | 41 | 3. Submit a pull request, use the implemented issue template if it is based on an issue or the new issue template if it is not linked to any issue. 42 | 43 | 4. Give us a moment. Hazel is maintained by only a few people, all of whom are doing this on their limited free time, so it may take us a bit to review your request. Bug fixes should be merged in directly, while features usually require Cherno's approval with or without it mentioned in one (or more) videos. 44 | 45 | If you're not sure what any of that means, check out Thinkful's [GitHub Pull Request Tutorial][thinkful-pr-tutorial] for a complete walkthrough of the process. 46 | 47 | ### Writing a Good Pull Request 48 | 49 | - Stay focused on a single fix or feature. If you submit multiple changes in a single request, we may like some but spot issues with others. When that happens, we have to reject the whole thing. If you submit each change in its own request it is easier for us to review and approve. 50 | 51 | - Limit your changes to only what is required to implement the fix or feature. In particular, avoid style or formatting tools that may modify the formatting of other areas of the code. 52 | 53 | - Use descriptive commit titles/messages. "Implemented \" or "Fixed \ is better than "Updated \". 54 | 55 | - Make sure the code you submit compiles and runs without issues. When we set up unit tests and continuous integration we also expect that the pull request should pass all tests. 56 | 57 | - Use [closing keywords][github-help-closing-keywords] in the appropriate section of our Pull Request template where applicable. 58 | 59 | - Follow our coding conventions, which we've intentionally kept quite minimal. 60 | 61 | ### Coding Conventions 62 | 63 | - Naming convention: 64 | - For functions we use pascal case: **`FunctionName`**. 65 | - For (scoped) variables and function parameters we use camel case: **`variableName`** and **`parameterName`**. 66 | 67 | - For class names we use pascal case: **`ClassName`**. 68 | 69 | - For class variables we use the Hungarian notation: 70 | - Class member variables get the 'm_' prefix: **`m_ClassMemberVariableName`**. 71 | - Class static variables get the 's_' prefix: **`s_ClassStaticVariableName`**. 72 | 73 | - For macros we use snake case: **`MACRO_NAME`**. 74 | - If it is specifically related to Hazel, we add the 'HZ_' prefix: **`HZ_MACRO_NAME`**. 75 | - If there is a macro for the application and for the engine, we add an additional 'CORE_' prefix to the engine macro: **`HZ_CORE_MACRO_NAME`**. 76 | 77 | - Use tabs for indentation, not spaces. 78 | 79 | - When in doubt, match the code that's already there. 80 | 81 | 82 | 83 | [github]: https://github.com 84 | [how-to-ask]: https://stackoverflow.com/help/how-to-ask 85 | [issue-tracker]: https://github.com/TheCherno/Hazel/issues 86 | [submit-pr]: https://github.com/TheCherno/Hazel/pulls 87 | [thinkful-pr-tutorial]: https://www.thinkful.com/learn/github-pull-request-tutorial/ 88 | [github-help-closing-keywords]: https://help.github.com/en/articles/closing-issues-using-keywords -------------------------------------------------------------------------------- /Hazel/src/Platform/Windows/WindowsWindow.cpp: -------------------------------------------------------------------------------- 1 | #include "hzpch.h" 2 | #include "Platform/Windows/WindowsWindow.h" 3 | 4 | #include "Hazel/Core/Input.h" 5 | 6 | #include "Hazel/Events/ApplicationEvent.h" 7 | #include "Hazel/Events/MouseEvent.h" 8 | #include "Hazel/Events/KeyEvent.h" 9 | 10 | #include "Hazel/Renderer/Renderer.h" 11 | 12 | #include "Platform/OpenGL/OpenGLContext.h" 13 | 14 | namespace Hazel { 15 | 16 | static uint8_t s_GLFWWindowCount = 0; 17 | 18 | static void GLFWErrorCallback(int error, const char* description) 19 | { 20 | HZ_CORE_ERROR("GLFW Error ({0}): {1}", error, description); 21 | } 22 | 23 | WindowsWindow::WindowsWindow(const WindowProps& props) 24 | { 25 | HZ_PROFILE_FUNCTION(); 26 | 27 | Init(props); 28 | } 29 | 30 | WindowsWindow::~WindowsWindow() 31 | { 32 | HZ_PROFILE_FUNCTION(); 33 | 34 | Shutdown(); 35 | } 36 | 37 | void WindowsWindow::Init(const WindowProps& props) 38 | { 39 | HZ_PROFILE_FUNCTION(); 40 | 41 | m_Data.Title = props.Title; 42 | m_Data.Width = props.Width; 43 | m_Data.Height = props.Height; 44 | 45 | HZ_CORE_INFO("Creating window {0} ({1}, {2})", props.Title, props.Width, props.Height); 46 | 47 | if (s_GLFWWindowCount == 0) 48 | { 49 | HZ_PROFILE_SCOPE("glfwInit"); 50 | int success = glfwInit(); 51 | HZ_CORE_ASSERT(success, "Could not initialize GLFW!"); 52 | glfwSetErrorCallback(GLFWErrorCallback); 53 | } 54 | 55 | { 56 | HZ_PROFILE_SCOPE("glfwCreateWindow"); 57 | #if defined(HZ_DEBUG) 58 | if (Renderer::GetAPI() == RendererAPI::API::OpenGL) 59 | glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GLFW_TRUE); 60 | #endif 61 | m_Window = glfwCreateWindow((int)props.Width, (int)props.Height, m_Data.Title.c_str(), nullptr, nullptr); 62 | ++s_GLFWWindowCount; 63 | } 64 | 65 | m_Context = GraphicsContext::Create(m_Window); 66 | m_Context->Init(); 67 | 68 | glfwSetWindowUserPointer(m_Window, &m_Data); 69 | SetVSync(true); 70 | 71 | // Set GLFW callbacks 72 | glfwSetWindowSizeCallback(m_Window, [](GLFWwindow* window, int width, int height) 73 | { 74 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 75 | data.Width = width; 76 | data.Height = height; 77 | 78 | WindowResizeEvent event(width, height); 79 | data.EventCallback(event); 80 | }); 81 | 82 | glfwSetWindowCloseCallback(m_Window, [](GLFWwindow* window) 83 | { 84 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 85 | WindowCloseEvent event; 86 | data.EventCallback(event); 87 | }); 88 | 89 | glfwSetKeyCallback(m_Window, [](GLFWwindow* window, int key, int scancode, int action, int mods) 90 | { 91 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 92 | 93 | switch (action) 94 | { 95 | case GLFW_PRESS: 96 | { 97 | KeyPressedEvent event(key, 0); 98 | data.EventCallback(event); 99 | break; 100 | } 101 | case GLFW_RELEASE: 102 | { 103 | KeyReleasedEvent event(key); 104 | data.EventCallback(event); 105 | break; 106 | } 107 | case GLFW_REPEAT: 108 | { 109 | KeyPressedEvent event(key, 1); 110 | data.EventCallback(event); 111 | break; 112 | } 113 | } 114 | }); 115 | 116 | glfwSetCharCallback(m_Window, [](GLFWwindow* window, unsigned int keycode) 117 | { 118 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 119 | 120 | KeyTypedEvent event(keycode); 121 | data.EventCallback(event); 122 | }); 123 | 124 | glfwSetMouseButtonCallback(m_Window, [](GLFWwindow* window, int button, int action, int mods) 125 | { 126 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 127 | 128 | switch (action) 129 | { 130 | case GLFW_PRESS: 131 | { 132 | MouseButtonPressedEvent event(button); 133 | data.EventCallback(event); 134 | break; 135 | } 136 | case GLFW_RELEASE: 137 | { 138 | MouseButtonReleasedEvent event(button); 139 | data.EventCallback(event); 140 | break; 141 | } 142 | } 143 | }); 144 | 145 | glfwSetScrollCallback(m_Window, [](GLFWwindow* window, double xOffset, double yOffset) 146 | { 147 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 148 | 149 | MouseScrolledEvent event((float)xOffset, (float)yOffset); 150 | data.EventCallback(event); 151 | }); 152 | 153 | glfwSetCursorPosCallback(m_Window, [](GLFWwindow* window, double xPos, double yPos) 154 | { 155 | WindowData& data = *(WindowData*)glfwGetWindowUserPointer(window); 156 | 157 | MouseMovedEvent event((float)xPos, (float)yPos); 158 | data.EventCallback(event); 159 | }); 160 | } 161 | 162 | void WindowsWindow::Shutdown() 163 | { 164 | HZ_PROFILE_FUNCTION(); 165 | 166 | glfwDestroyWindow(m_Window); 167 | --s_GLFWWindowCount; 168 | 169 | if (s_GLFWWindowCount == 0) 170 | { 171 | glfwTerminate(); 172 | } 173 | } 174 | 175 | void WindowsWindow::OnUpdate() 176 | { 177 | HZ_PROFILE_FUNCTION(); 178 | 179 | glfwPollEvents(); 180 | m_Context->SwapBuffers(); 181 | } 182 | 183 | void WindowsWindow::SetVSync(bool enabled) 184 | { 185 | HZ_PROFILE_FUNCTION(); 186 | 187 | if (enabled) 188 | glfwSwapInterval(1); 189 | else 190 | glfwSwapInterval(0); 191 | 192 | m_Data.VSync = enabled; 193 | } 194 | 195 | bool WindowsWindow::IsVSync() const 196 | { 197 | return m_Data.VSync; 198 | } 199 | 200 | } 201 | -------------------------------------------------------------------------------- /Sandbox/src/ExampleLayer.cpp: -------------------------------------------------------------------------------- 1 | #include "ExampleLayer.h" 2 | 3 | #include "imgui/imgui.h" 4 | 5 | #include 6 | #include 7 | 8 | ExampleLayer::ExampleLayer() 9 | : Layer("ExampleLayer"), m_CameraController(1280.0f / 720.0f) 10 | { 11 | m_VertexArray = Hazel::VertexArray::Create(); 12 | 13 | float vertices[3 * 7] = { 14 | -0.5f, -0.5f, 0.0f, 0.8f, 0.2f, 0.8f, 1.0f, 15 | 0.5f, -0.5f, 0.0f, 0.2f, 0.3f, 0.8f, 1.0f, 16 | 0.0f, 0.5f, 0.0f, 0.8f, 0.8f, 0.2f, 1.0f 17 | }; 18 | 19 | Hazel::Ref vertexBuffer = Hazel::VertexBuffer::Create(vertices, sizeof(vertices)); 20 | Hazel::BufferLayout layout = { 21 | { Hazel::ShaderDataType::Float3, "a_Position" }, 22 | { Hazel::ShaderDataType::Float4, "a_Color" } 23 | }; 24 | vertexBuffer->SetLayout(layout); 25 | m_VertexArray->AddVertexBuffer(vertexBuffer); 26 | 27 | uint32_t indices[3] = { 0, 1, 2 }; 28 | Hazel::Ref indexBuffer = Hazel::IndexBuffer::Create(indices, sizeof(indices) / sizeof(uint32_t)); 29 | m_VertexArray->SetIndexBuffer(indexBuffer); 30 | 31 | m_SquareVA = Hazel::VertexArray::Create(); 32 | 33 | float squareVertices[5 * 4] = { 34 | -0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 35 | 0.5f, -0.5f, 0.0f, 1.0f, 0.0f, 36 | 0.5f, 0.5f, 0.0f, 1.0f, 1.0f, 37 | -0.5f, 0.5f, 0.0f, 0.0f, 1.0f 38 | }; 39 | 40 | Hazel::Ref squareVB = Hazel::VertexBuffer::Create(squareVertices, sizeof(squareVertices)); 41 | squareVB->SetLayout({ 42 | { Hazel::ShaderDataType::Float3, "a_Position" }, 43 | { Hazel::ShaderDataType::Float2, "a_TexCoord" } 44 | }); 45 | m_SquareVA->AddVertexBuffer(squareVB); 46 | 47 | uint32_t squareIndices[6] = { 0, 1, 2, 2, 3, 0 }; 48 | Hazel::Ref squareIB = Hazel::IndexBuffer::Create(squareIndices, sizeof(squareIndices) / sizeof(uint32_t)); 49 | m_SquareVA->SetIndexBuffer(squareIB); 50 | 51 | std::string vertexSrc = R"( 52 | #version 330 core 53 | 54 | layout(location = 0) in vec3 a_Position; 55 | layout(location = 1) in vec4 a_Color; 56 | 57 | uniform mat4 u_ViewProjection; 58 | uniform mat4 u_Transform; 59 | 60 | out vec3 v_Position; 61 | out vec4 v_Color; 62 | 63 | void main() 64 | { 65 | v_Position = a_Position; 66 | v_Color = a_Color; 67 | gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0); 68 | } 69 | )"; 70 | 71 | std::string fragmentSrc = R"( 72 | #version 330 core 73 | 74 | layout(location = 0) out vec4 color; 75 | 76 | in vec3 v_Position; 77 | in vec4 v_Color; 78 | 79 | void main() 80 | { 81 | color = vec4(v_Position * 0.5 + 0.5, 1.0); 82 | color = v_Color; 83 | } 84 | )"; 85 | 86 | m_Shader = Hazel::Shader::Create("VertexPosColor", vertexSrc, fragmentSrc); 87 | 88 | std::string flatColorShaderVertexSrc = R"( 89 | #version 330 core 90 | 91 | layout(location = 0) in vec3 a_Position; 92 | 93 | uniform mat4 u_ViewProjection; 94 | uniform mat4 u_Transform; 95 | 96 | out vec3 v_Position; 97 | 98 | void main() 99 | { 100 | v_Position = a_Position; 101 | gl_Position = u_ViewProjection * u_Transform * vec4(a_Position, 1.0); 102 | } 103 | )"; 104 | 105 | std::string flatColorShaderFragmentSrc = R"( 106 | #version 330 core 107 | 108 | layout(location = 0) out vec4 color; 109 | 110 | in vec3 v_Position; 111 | 112 | uniform vec3 u_Color; 113 | 114 | void main() 115 | { 116 | color = vec4(u_Color, 1.0); 117 | } 118 | )"; 119 | 120 | m_FlatColorShader = Hazel::Shader::Create("FlatColor", flatColorShaderVertexSrc, flatColorShaderFragmentSrc); 121 | 122 | auto textureShader = m_ShaderLibrary.Load("assets/shaders/Texture.glsl"); 123 | 124 | m_Texture = Hazel::Texture2D::Create("assets/textures/Checkerboard.png"); 125 | m_ChernoLogoTexture = Hazel::Texture2D::Create("assets/textures/ChernoLogo.png"); 126 | 127 | textureShader->Bind(); 128 | textureShader->SetInt("u_Texture", 0); 129 | } 130 | 131 | void ExampleLayer::OnAttach() 132 | { 133 | } 134 | 135 | void ExampleLayer::OnDetach() 136 | { 137 | } 138 | 139 | void ExampleLayer::OnUpdate(Hazel::Timestep ts) 140 | { 141 | // Update 142 | m_CameraController.OnUpdate(ts); 143 | 144 | // Render 145 | Hazel::RenderCommand::SetClearColor({ 0.1f, 0.1f, 0.1f, 1 }); 146 | Hazel::RenderCommand::Clear(); 147 | 148 | Hazel::Renderer::BeginScene(m_CameraController.GetCamera()); 149 | 150 | glm::mat4 scale = glm::scale(glm::mat4(1.0f), glm::vec3(0.1f)); 151 | 152 | m_FlatColorShader->Bind(); 153 | m_FlatColorShader->SetFloat3("u_Color", m_SquareColor); 154 | 155 | for (int y = 0; y < 20; y++) 156 | { 157 | for (int x = 0; x < 20; x++) 158 | { 159 | glm::vec3 pos(x * 0.11f, y * 0.11f, 0.0f); 160 | glm::mat4 transform = glm::translate(glm::mat4(1.0f), pos) * scale; 161 | Hazel::Renderer::Submit(m_FlatColorShader, m_SquareVA, transform); 162 | } 163 | } 164 | 165 | auto textureShader = m_ShaderLibrary.Get("Texture"); 166 | 167 | m_Texture->Bind(); 168 | Hazel::Renderer::Submit(textureShader, m_SquareVA, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f))); 169 | m_ChernoLogoTexture->Bind(); 170 | Hazel::Renderer::Submit(textureShader, m_SquareVA, glm::scale(glm::mat4(1.0f), glm::vec3(1.5f))); 171 | 172 | // Triangle 173 | // Hazel::Renderer::Submit(m_Shader, m_VertexArray); 174 | 175 | Hazel::Renderer::EndScene(); 176 | } 177 | 178 | void ExampleLayer::OnImGuiRender() 179 | { 180 | ImGui::Begin("Settings"); 181 | ImGui::ColorEdit3("Square Color", glm::value_ptr(m_SquareColor)); 182 | ImGui::End(); 183 | } 184 | 185 | void ExampleLayer::OnEvent(Hazel::Event& e) 186 | { 187 | m_CameraController.OnEvent(e); 188 | } 189 | -------------------------------------------------------------------------------- /scripts/Utils.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import winreg 4 | 5 | import requests 6 | import time 7 | import urllib 8 | 9 | from zipfile import ZipFile 10 | 11 | def GetSystemEnvironmentVariable(name): 12 | key = winreg.CreateKey(winreg.HKEY_LOCAL_MACHINE, r"System\CurrentControlSet\Control\Session Manager\Environment") 13 | try: 14 | return winreg.QueryValueEx(key, name)[0] 15 | except: 16 | return None 17 | 18 | def GetUserEnvironmentVariable(name): 19 | key = winreg.CreateKey(winreg.HKEY_CURRENT_USER, r"Environment") 20 | try: 21 | return winreg.QueryValueEx(key, name)[0] 22 | except: 23 | return None 24 | 25 | def DownloadFile(url, filepath): 26 | path = filepath 27 | filepath = os.path.abspath(filepath) 28 | os.makedirs(os.path.dirname(filepath), exist_ok=True) 29 | 30 | if (type(url) is list): 31 | for url_option in url: 32 | print("Downloading", url_option) 33 | try: 34 | DownloadFile(url_option, filepath) 35 | return 36 | except urllib.error.URLError as e: 37 | print(f"URL Error encountered: {e.reason}. Proceeding with backup...\n\n") 38 | os.remove(filepath) 39 | pass 40 | except urllib.error.HTTPError as e: 41 | print(f"HTTP Error encountered: {e.code}. Proceeding with backup...\n\n") 42 | os.remove(filepath) 43 | pass 44 | except: 45 | print(f"Something went wrong. Proceeding with backup...\n\n") 46 | os.remove(filepath) 47 | pass 48 | raise ValueError(f"Failed to download {filepath}") 49 | if not(type(url) is str): 50 | raise TypeError("Argument 'url' must be of type list or string") 51 | 52 | with open(filepath, 'wb') as f: 53 | headers = {'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"} 54 | response = requests.get(url, headers=headers, stream=True) 55 | total = response.headers.get('content-length') 56 | 57 | if total is None: 58 | f.write(response.content) 59 | else: 60 | downloaded = 0 61 | total = int(total) 62 | startTime = time.time() 63 | for data in response.iter_content(chunk_size=max(int(total/1000), 1024*1024)): 64 | downloaded += len(data) 65 | f.write(data) 66 | 67 | try: 68 | done = int(50*downloaded/total) if downloaded < total else 50 69 | percentage = (downloaded / total) * 100 if downloaded < total else 100 70 | except ZeroDivisionError: 71 | done = 50 72 | percentage = 100 73 | elapsedTime = time.time() - startTime 74 | try: 75 | avgKBPerSecond = (downloaded / 1024) / elapsedTime 76 | except ZeroDivisionError: 77 | avgKBPerSecond = 0.0 78 | 79 | avgSpeedString = '{:.2f} KB/s'.format(avgKBPerSecond) 80 | if (avgKBPerSecond > 1024): 81 | avgMBPerSecond = avgKBPerSecond / 1024 82 | avgSpeedString = '{:.2f} MB/s'.format(avgMBPerSecond) 83 | sys.stdout.write('\r[{}{}] {:.2f}% ({}) '.format('█' * done, '.' * (50-done), percentage, avgSpeedString)) 84 | sys.stdout.flush() 85 | sys.stdout.write('\n') 86 | 87 | def UnzipFile(filepath, deleteZipFile=True): 88 | zipFilePath = os.path.abspath(filepath) # get full path of files 89 | zipFileLocation = os.path.dirname(zipFilePath) 90 | 91 | zipFileContent = dict() 92 | zipFileContentSize = 0 93 | with ZipFile(zipFilePath, 'r') as zipFileFolder: 94 | for name in zipFileFolder.namelist(): 95 | zipFileContent[name] = zipFileFolder.getinfo(name).file_size 96 | zipFileContentSize = sum(zipFileContent.values()) 97 | extractedContentSize = 0 98 | startTime = time.time() 99 | for zippedFileName, zippedFileSize in zipFileContent.items(): 100 | UnzippedFilePath = os.path.abspath(f"{zipFileLocation}/{zippedFileName}") 101 | os.makedirs(os.path.dirname(UnzippedFilePath), exist_ok=True) 102 | if os.path.isfile(UnzippedFilePath): 103 | zipFileContentSize -= zippedFileSize 104 | else: 105 | zipFileFolder.extract(zippedFileName, path=zipFileLocation, pwd=None) 106 | extractedContentSize += zippedFileSize 107 | try: 108 | done = int(50*extractedContentSize/zipFileContentSize) 109 | percentage = (extractedContentSize / zipFileContentSize) * 100 110 | except ZeroDivisionError: 111 | done = 50 112 | percentage = 100 113 | elapsedTime = time.time() - startTime 114 | try: 115 | avgKBPerSecond = (extractedContentSize / 1024) / elapsedTime 116 | except ZeroDivisionError: 117 | avgKBPerSecond = 0.0 118 | avgSpeedString = '{:.2f} KB/s'.format(avgKBPerSecond) 119 | if (avgKBPerSecond > 1024): 120 | avgMBPerSecond = avgKBPerSecond / 1024 121 | avgSpeedString = '{:.2f} MB/s'.format(avgMBPerSecond) 122 | sys.stdout.write('\r[{}{}] {:.2f}% ({}) '.format('█' * done, '.' * (50-done), percentage, avgSpeedString)) 123 | sys.stdout.flush() 124 | sys.stdout.write('\n') 125 | 126 | if deleteZipFile: 127 | os.remove(zipFilePath) # delete zip file --------------------------------------------------------------------------------