Mirror
- Added Mirror: Mirror is the LightEngine's editor >w< (cuz it reflects light uwu)
This commit is contained in:
parent
271f3b2075
commit
0b19b1aa30
5 changed files with 214 additions and 1 deletions
|
@ -16,8 +16,9 @@ dependenciesdir = "%{wks.location}/Dependencies/"
|
||||||
outputdir = "%{cfg.buildcfg}/%{cfg.system}/%{cfg.architecture}/%{prj.name}"
|
outputdir = "%{cfg.buildcfg}/%{cfg.system}/%{cfg.architecture}/%{prj.name}"
|
||||||
|
|
||||||
-- Projects --
|
-- Projects --
|
||||||
include "../Sandbox/"
|
|
||||||
include "../Engine/"
|
include "../Engine/"
|
||||||
|
include "../Mirror/"
|
||||||
|
include "../Sandbox/"
|
||||||
|
|
||||||
-- Dependencies --
|
-- Dependencies --
|
||||||
group "Dependencies"
|
group "Dependencies"
|
||||||
|
|
77
Mirror/premake5.lua
Normal file
77
Mirror/premake5.lua
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
project "Mirror"
|
||||||
|
|
||||||
|
-- Output Directories --
|
||||||
|
location "%{wks.location}/Mirror/"
|
||||||
|
|
||||||
|
targetdir ("%{wks.location}/bin/" .. outputdir)
|
||||||
|
objdir ("%{wks.location}/bin-int/" .. outputdir)
|
||||||
|
|
||||||
|
-- Compiler --
|
||||||
|
kind "ConsoleApp"
|
||||||
|
language "C++"
|
||||||
|
cppdialect "C++17"
|
||||||
|
|
||||||
|
-- Project Files ---
|
||||||
|
files
|
||||||
|
{
|
||||||
|
"%{prj.location}/src/**.h",
|
||||||
|
"%{prj.location}/src/**.cpp",
|
||||||
|
|
||||||
|
"%{prj.location}/premake5.lua",
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Dependencies --
|
||||||
|
includedirs
|
||||||
|
{
|
||||||
|
-- Engine
|
||||||
|
"%{wks.location}/Engine/src",
|
||||||
|
"%{wks.location}/Engine/src/Engine",
|
||||||
|
"%{wks.location}/Engine/src/Platform/GraphicsAPI",
|
||||||
|
"%{wks.location}/Engine/src/Platform/OS",
|
||||||
|
|
||||||
|
-- 3rd party
|
||||||
|
(dependenciesdir .. "spdlog/include/"),
|
||||||
|
(dependenciesdir .. "imgui/"),
|
||||||
|
(dependenciesdir .. "imgui/backends"),
|
||||||
|
(dependenciesdir .. "glm/"),
|
||||||
|
}
|
||||||
|
|
||||||
|
links
|
||||||
|
{
|
||||||
|
"Engine",
|
||||||
|
"GLFW",
|
||||||
|
"GLAD",
|
||||||
|
"ImGui",
|
||||||
|
}
|
||||||
|
|
||||||
|
--- Filters ---
|
||||||
|
-- windows
|
||||||
|
filter "system:windows"
|
||||||
|
defines "LIGHT_PLATFORM_WINDOWS"
|
||||||
|
systemversion "latest"
|
||||||
|
staticruntime "On"
|
||||||
|
|
||||||
|
-- linux
|
||||||
|
filter "system:linux"
|
||||||
|
defines "LIGHT_PLATFORM_LINUX"
|
||||||
|
|
||||||
|
links
|
||||||
|
{
|
||||||
|
"dl",
|
||||||
|
"pthread",
|
||||||
|
}
|
||||||
|
|
||||||
|
-- debug
|
||||||
|
filter "configurations:Debug"
|
||||||
|
defines "LIGHT_DEBUG"
|
||||||
|
symbols "on"
|
||||||
|
|
||||||
|
-- release
|
||||||
|
filter "configurations:Release"
|
||||||
|
defines "LIGHT_RELEASE"
|
||||||
|
optimize "on"
|
||||||
|
|
||||||
|
-- distribution
|
||||||
|
filter "configurations:Distribution"
|
||||||
|
defines "LIGHT_DIST"
|
||||||
|
optimize "on"
|
BIN
Mirror/res/Textures/awesomeface.png
Normal file
BIN
Mirror/res/Textures/awesomeface.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 75 KiB |
35
Mirror/src/MirrorApp.cpp
Normal file
35
Mirror/src/MirrorApp.cpp
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
#define LIGHT_ENTRY_POINT
|
||||||
|
#include <LightEngine.h>
|
||||||
|
#include <EntryPoint.h>
|
||||||
|
|
||||||
|
#include "MirrorLayer.h"
|
||||||
|
|
||||||
|
class Mirror : public Light::Application
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Mirror()
|
||||||
|
{
|
||||||
|
LT_CLIENT_TRACE("Sandbox::Sandbox");
|
||||||
|
|
||||||
|
// Set window properties
|
||||||
|
Light::WindowProperties properties;
|
||||||
|
properties.title = "Sandbox";
|
||||||
|
properties.size = glm::uvec2(800u, 600u);
|
||||||
|
properties.vsync = true;
|
||||||
|
|
||||||
|
m_Window->SetProperties(properties);
|
||||||
|
|
||||||
|
// Attach the sandbox layer
|
||||||
|
Light::LayerStack::AttachLayer(new MirrorLayer("SandboxLayer"));
|
||||||
|
}
|
||||||
|
|
||||||
|
~Mirror()
|
||||||
|
{
|
||||||
|
LT_CLIENT_TRACE("Sandbox::~Sandbox");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Light::Application* Light::CreateApplication()
|
||||||
|
{
|
||||||
|
return new Mirror();
|
||||||
|
}
|
100
Mirror/src/MirrorLayer.h
Normal file
100
Mirror/src/MirrorLayer.h
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
#include <LightEngine.h>
|
||||||
|
|
||||||
|
class MirrorLayer : public Light::Layer
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
std::shared_ptr<Light::Texture> m_AwesomefaceTexture;
|
||||||
|
|
||||||
|
std::vector<glm::vec3> positions;
|
||||||
|
std::vector<glm::vec2> sizes;
|
||||||
|
|
||||||
|
glm::vec2 m_Direction;
|
||||||
|
float m_Speed = 1.2f;
|
||||||
|
|
||||||
|
std::shared_ptr<Light::Camera> m_Camera;
|
||||||
|
|
||||||
|
std::shared_ptr<Light::Framebuffer> m_Framebuffer;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MirrorLayer(const std::string& name)
|
||||||
|
: Light::Layer(name), m_Direction(glm::vec2(0.0f, 0.0f))
|
||||||
|
{
|
||||||
|
m_Camera = std::make_shared<Light::Camera>(glm::vec2(0.0f), 800.0f / 600.0f, 1.0f);
|
||||||
|
|
||||||
|
Light::ResourceManager::LoadTexture("awesomeface", "res/Textures/awesomeface.png");
|
||||||
|
m_AwesomefaceTexture = Light::ResourceManager::GetTexture("awesomeface");
|
||||||
|
|
||||||
|
m_Framebuffer = std::shared_ptr<Light::Framebuffer>(Light::Framebuffer::Create({ 800u, 600u, 1, glm::vec4(1.0f, 0.0f, 0.0f, 1.0f), false }, Light::GraphicsContext::GetSharedContext()));
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
glm::vec3 position = glm::vec3(-1.0f + (-100.0f / 400.0f) + ((rand() % 1000) / 400.0f), -1.0f + (-100.0f / 300.0f) + ((rand() % 800) / 300.0f), 0.0f);
|
||||||
|
glm::vec2 size = glm::vec2(100 / 400.0f, 100 / 300.0f);
|
||||||
|
|
||||||
|
positions.push_back(position);
|
||||||
|
sizes.push_back(size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnRender() override
|
||||||
|
{
|
||||||
|
m_Camera->CalculateProjection();
|
||||||
|
m_Camera->CalculateView();
|
||||||
|
|
||||||
|
Light::Renderer::BeginScene(m_Camera, m_Framebuffer);
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
Light::Renderer::DrawQuad(positions[i], sizes[i], m_AwesomefaceTexture);
|
||||||
|
|
||||||
|
Light::Renderer::EndScene();
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUserInterfaceUpdate()
|
||||||
|
{
|
||||||
|
ImGui::Begin("GameView");
|
||||||
|
|
||||||
|
if(Light::GraphicsContext::GetGraphicsAPI() == Light::GraphicsAPI::DirectX)
|
||||||
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), ImVec2(400, 300));
|
||||||
|
else
|
||||||
|
ImGui::Image(m_Framebuffer->GetColorAttachment(), ImVec2(400, 300), ImVec2(0, 1), ImVec2(1, 0));
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnKeyPressed(const Light::KeyPressedEvent& event) override
|
||||||
|
{
|
||||||
|
if (event.GetKey() == 65) // GLFW_KEY_A
|
||||||
|
m_Direction.x += -1.0f;
|
||||||
|
if(event.GetKey() == 68) // GLFW_KEY_D
|
||||||
|
m_Direction.x += 1.0f;
|
||||||
|
|
||||||
|
if (event.GetKey() == 87) // GLFW_KEY_W
|
||||||
|
m_Direction.y += 1.0f;
|
||||||
|
if (event.GetKey() == 83) // GLFW_KEY_S
|
||||||
|
m_Direction.y += -1.0f;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnKeyReleased(const Light::KeyReleasedEvent& event) override
|
||||||
|
{
|
||||||
|
// #todo: add input class
|
||||||
|
if (event.GetKey() == 65) // GLFW_KEY_A
|
||||||
|
m_Direction.x -= -1.0f;
|
||||||
|
if (event.GetKey() == 68) // GLFW_KEY_D
|
||||||
|
m_Direction.x -= 1.0f;
|
||||||
|
|
||||||
|
if (event.GetKey() == 87) // GLFW_KEY_W
|
||||||
|
m_Direction.y -= 1.0f;
|
||||||
|
if (event.GetKey() == 83) // GLFW_KEY_S
|
||||||
|
m_Direction.y -= -1.0f;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnUpdate(float deltaTime) override
|
||||||
|
{
|
||||||
|
m_Camera->Move(m_Direction * m_Speed * deltaTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
Loading…
Add table
Reference in a new issue