Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions EclipseEngine/EclipseEditor/EclipseEditor.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@
<ClInclude Include="ViewportPanel.h" />
<None Include="aabb.frag" />
<None Include="aabb.vert" />
<None Include="frustum.frag" />
<None Include="frustum.vert" />
<None Include="Shaders\default.frag" />
<None Include="Shaders\default.vert" />
<None Include="Shaders\grid.frag" />
Expand All @@ -147,6 +149,8 @@
<None Include="Shaders\position.vert" />
<None Include="Shaders\depth.frag" />
<None Include="Shaders\depth.vert" />
<None Include="skybox.frag" />
<None Include="skybox.vert" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
12 changes: 12 additions & 0 deletions EclipseEngine/EclipseEditor/EclipseEditor.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,17 @@
<None Include="aabb.frag">
<Filter>Resource Files\Shaders</Filter>
</None>
<None Include="skybox.vert">
<Filter>Resource Files\Shaders</Filter>
</None>
<None Include="skybox.frag">
<Filter>Resource Files\Shaders</Filter>
</None>
<None Include="frustum.vert">
<Filter>Resource Files\Shaders</Filter>
</None>
<None Include="frustum.frag">
<Filter>Resource Files\Shaders</Filter>
</None>
</ItemGroup>
</Project>
77 changes: 74 additions & 3 deletions EclipseEngine/EclipseEditor/EditorRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "App.h"
#include "EditorRenderer.h"

EditorRenderer::EditorRenderer()
EditorRenderer::EditorRenderer(App* application) : app(application)
{
fbo = new Framebuffer(core->window->GetWidth(), core->window->GetHeight());
}
Expand All @@ -25,6 +25,7 @@ bool EditorRenderer::Initialize()
optionShader = normalShader = new Shader("Shaders/normal.vert", "Shaders/normal.frag");
outliningShader = new Shader("Shaders/outline.vert", "Shaders/outline.frag");
aabbShader = new Shader("Shaders/aabb.vert", "Shaders/aabb.frag");
frustumShader = new Shader("Shaders/frustum.vert", "Shaders/frustum.frag");
glEnable(GL_CULL_FACE); // Backface culling testing
glEnable(GL_STENCIL_TEST); // Stencil testing
glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
Expand All @@ -51,6 +52,21 @@ void EditorRenderer::Render(Scene* scene, Camera* editorCamera, std::shared_ptr<
{
if (!scene) return;

ViewportPanel* viewport = app->panelHandler->viewportPanel;

if (!viewport) {
std::cerr << "Error: Viewport Panel not found!" << std::endl;
return;
}

bool showSkybox = viewport->showSkybox;
bool showGrid = viewport->showGrid;
bool showGizmo = viewport->showGizmo;

if (showSkybox && scene->skybox) {
scene->skybox->Draw(*editorCamera);
}

// Normal object rendering
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Write 1 to the stencil buffer for all objects
glStencilMask(0xFF); // Enable writing to the stencil buffer
Expand Down Expand Up @@ -84,6 +100,20 @@ void EditorRenderer::Render(Scene* scene, Camera* editorCamera, std::shared_ptr<
}
}

// Ensure correct OpenGL state for drawing lines
glDisable(GL_DEPTH_TEST);
glLineWidth(1.0f);

for (const auto& gameObject : scene->GetObjects()) {
if (Camera* camera = gameObject->GetComponent<Camera>()) {
auto frustumVertices = camera->GetFrustumVertices(camera->nearPlane, camera->farPlane); // Adjust near and far planes as needed
DrawFrustum(frustumVertices, *frustumShader, editorCamera->GetViewMatrix(), editorCamera->GetProjectionMatrix());
}
}

glEnable(GL_DEPTH_TEST);
glLineWidth(1.0f);

if (selectedObject != nullptr)
{
// Calculate the world transform for the selected object
Expand All @@ -102,8 +132,15 @@ void EditorRenderer::Render(Scene* scene, Camera* editorCamera, std::shared_ptr<
glStencilFunc(GL_ALWAYS, 1, 0xFF); // Reset stencil function
glEnable(GL_DEPTH_TEST); // Re-enable depth testing

RenderGrid(grid, editorCamera);
RenderGuizmo();
// Render Grid if enabled
if (showGrid) {
RenderGrid(grid, editorCamera);
}

// Render Gizmo if enabled
if (showGizmo) {
RenderGuizmo();
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

Expand Down Expand Up @@ -168,3 +205,37 @@ void EditorRenderer::RenderAABB(AABB aabb, Shader& shader)
glDeleteBuffers(1, &EBO);
glDeleteVertexArrays(1, &VAO);
}

void EditorRenderer::DrawFrustum(const std::array<glm::vec3, 8>& frustumVertices, Shader& shader, const glm::mat4& view, const glm::mat4& projection) {
std::vector<glm::vec3> lines = {
frustumVertices[0], frustumVertices[1], frustumVertices[1], frustumVertices[2],
frustumVertices[2], frustumVertices[3], frustumVertices[3], frustumVertices[0],
frustumVertices[4], frustumVertices[5], frustumVertices[5], frustumVertices[6],
frustumVertices[6], frustumVertices[7], frustumVertices[7], frustumVertices[4],
frustumVertices[0], frustumVertices[4], frustumVertices[1], frustumVertices[5],
frustumVertices[2], frustumVertices[6], frustumVertices[3], frustumVertices[7]
};

GLuint VAO, VBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);

glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, lines.size() * sizeof(glm::vec3), lines.data(), GL_STATIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(glm::vec3), (void*)0);
glEnableVertexAttribArray(0);

shader.Activate();
shader.SetMat4("view", view);
shader.SetMat4("projection", projection);

glDrawArrays(GL_LINES, 0, lines.size());

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

glDeleteBuffers(1, &VBO);
glDeleteVertexArrays(1, &VAO);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions EclipseEngine/EclipseEditor/Shaders/skybox.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#version 330 core
out vec4 FragColor;

in vec3 TexCoords;

uniform samplerCube skybox;

void main() {
FragColor = texture(skybox, TexCoords);
}
13 changes: 13 additions & 0 deletions EclipseEngine/EclipseEditor/Shaders/skybox.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#version 330 core
layout (location = 0) in vec3 aPos;

out vec3 TexCoords;

uniform mat4 view;
uniform mat4 projection;

void main() {
TexCoords = aPos;
vec4 pos = projection * view * vec4(aPos, 1.0);
gl_Position = pos.xyww; // Make sure depth is always 1.0
}
24 changes: 23 additions & 1 deletion EclipseEngine/EclipseEditor/ViewportPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ViewportPanel::ViewportPanel(const std::string& name, Framebuffer* framebuffer,
m_Trans = std::make_unique<Texture>("EditorResources/trans.png", "icon", 0, GL_RGBA, GL_UNSIGNED_BYTE);
m_Rot = std::make_unique<Texture>("EditorResources/rot.png", "icon", 0, GL_RGBA, GL_UNSIGNED_BYTE);
m_Sca = std::make_unique<Texture>("EditorResources/sca.png", "icon", 0, GL_RGBA, GL_UNSIGNED_BYTE);
m_Skybox = std::make_unique<Texture>("EditorResources/skybox.png", "icon", 0, GL_RGBA, GL_UNSIGNED_BYTE);
}

void ViewportPanel::Render()
Expand Down Expand Up @@ -120,6 +121,27 @@ void ViewportPanel::Render()
ImGui::EndDragDropTarget();
}

// Toggle buttons
ImGui::SetCursorScreenPos(ImVec2(viewportPosition.x + 600, viewportPosition.y + 15));

//if (ImGui::ImageButton(reinterpret_cast<void*>(static_cast<intptr_t>(m_Framebuffer->GetTextureID())), ImVec2(15, 15)))
//{
// showGrid = !showGrid;
//}
//ImGui::SameLine();

if (ImGui::ImageButton(reinterpret_cast<void*>(static_cast<intptr_t>(m_Skybox->textureID)), ImVec2(20, 20)))
{
showSkybox = !showSkybox;
}
ImGui::SameLine();

//if (ImGui::ImageButton(reinterpret_cast<void*>(static_cast<intptr_t>(m_Framebuffer->GetTextureID())), ImVec2(15, 15)))
//{
// showGizmo = !showGizmo;
//}


// Function to set button colors based on the active state
auto setActiveButtonColor = [](bool isActive) {
if (isActive) {
Expand Down Expand Up @@ -189,7 +211,7 @@ void ViewportPanel::Render()
}

// Gizmo manipulation (only active if not idle)
if (operation != ManipulationOperation::IDLE && m_SelectedObject)
if (operation != ManipulationOperation::IDLE && m_SelectedObject && showGizmo)
{
ImGuizmo::SetOrthographic(false);
ImGuizmo::SetDrawlist(ImGui::GetWindowDrawList());
Expand Down
5 changes: 5 additions & 0 deletions EclipseEngine/EclipseEditor/ViewportPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class ViewportPanel : public Panel

void Resize(int width, int height);

bool showGrid = true;
bool showSkybox = true;
bool showGizmo = true;
private:
Framebuffer* m_Framebuffer;
Camera* m_camera;
Expand All @@ -41,9 +44,11 @@ class ViewportPanel : public Panel
std::unique_ptr<Texture> m_Trans;
std::unique_ptr<Texture> m_Rot;
std::unique_ptr<Texture> m_Sca;
std::unique_ptr<Texture> m_Skybox;

const float iconSize = 25.0f;
const float iconSpacing = 5.0f; //spacing between icons

};

#endif // VIEWPORTPANEL_H
2 changes: 2 additions & 0 deletions EclipseEngine/EclipseEngine/EclipseEngine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
<ClCompile Include="Renderer.cpp" />
<ClCompile Include="Scene.cpp" />
<ClCompile Include="Shader.cpp" />
<ClCompile Include="SkyBox.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="Transform.cpp" />
<ClCompile Include="VAO.cpp" />
Expand All @@ -113,6 +114,7 @@
<ClInclude Include="Renderer.h" />
<ClInclude Include="Scene.h" />
<ClInclude Include="Shader.h" />
<ClInclude Include="SkyBox.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="Transform.h" />
<ClInclude Include="TreeExt.h" />
Expand Down
6 changes: 6 additions & 0 deletions EclipseEngine/EclipseEngine/EclipseEngine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<ClCompile Include="AABB.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="SkyBox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Shader.h">
Expand Down Expand Up @@ -137,5 +140,8 @@
<ClInclude Include="AABB.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="SkyBox.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
15 changes: 15 additions & 0 deletions EclipseEngine/EclipseEngine/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ bool Scene::Initialize()
cameraGO->name = "Main Camera";
cameraGO->AddComponent<Camera>(1500, 844, glm::vec3(7.0f, 4.0f, -7.0f));
SetActiveCamera(cameraGO->GetComponent<Camera>());
activeCamera->SetNearPlane(5.0f);
activeCamera->SetFarPlane(100.0f);
AddGameObject(cameraGO);
//auto initScene = modelLoader.LoadModel("Resources/Assets/fbx_files/Street/untitled.fbx");
//AddGameObject(initScene);

std::vector<std::string> cubemapFaces = {
"Resources/skybox/skybox1/right.png", "Resources/skybox/skybox1/left.png", "Resources/skybox/skybox1/top.png",
"Resources/skybox/skybox1/bottom.png", "Resources/skybox/skybox1/front.png", "Resources/skybox/skybox1/back.png"
};

//std::vector<std::string> cubemapFaces = {
//"Resources/skybox/skycube_1/right.bmp", "Resources/skybox/skycube_1/left.bmp", "Resources/skybox/skycube_1/top.bmp",
//"Resources/skybox/skycube_1/bottom.bmp", "Resources/skybox/skycube_1/front.bmp", "Resources/skybox/skycube_1/back.bmp"
//};

skybox = std::make_unique<Skybox>(cubemapFaces);

return true;
}

Expand Down
2 changes: 2 additions & 0 deletions EclipseEngine/EclipseEngine/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "GameObject.h"
#include "Camera.h"
#include "ModelLoader.h"
#include "Skybox.h"

class Scene
{
Expand All @@ -26,6 +27,7 @@ class Scene

void AddCube();

std::unique_ptr<Skybox> skybox;
private:
std::list<std::shared_ptr<GameObject >> gameObjects;
Camera* activeCamera = nullptr;
Expand Down
Loading