Compare commits
2 Commits
ba69726e33
...
89f5b1497f
Author | SHA1 | Date | |
---|---|---|---|
89f5b1497f | |||
7448017701 |
@ -18,6 +18,7 @@ void Viewport::Draw() {
|
||||
});
|
||||
|
||||
cam.Update();
|
||||
renderer.SetMainCamera(cam);
|
||||
renderer.Render(scene);
|
||||
|
||||
ImVec2 WinPos = ImGui::GetWindowPos();
|
||||
@ -37,6 +38,7 @@ void Viewport::Draw() {
|
||||
ImGuizmo::SetRect(ScreenSpaceMin.x, ScreenSpaceMin.y, ContentRegionMax.x, ContentRegionMax.y);
|
||||
|
||||
glm::mat4 transposed_view = glm::transpose(cam.ViewMatrix);
|
||||
isFocused = ImGui::IsWindowFocused();
|
||||
|
||||
//ImGuizmo::DrawGrid(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), glm::value_ptr(worldOrigin), 100.0f);
|
||||
//ImGuizmo::ViewManipulate(glm::value_ptr(cam.ViewMatrix), 1, { ScreenSpaceMin.x,ScreenSpaceMin.y }, { 90,90 }, 0x22CCCCCC);
|
||||
@ -44,12 +46,4 @@ void Viewport::Draw() {
|
||||
// Matrix is the model matrix we would want to manipulate
|
||||
//ImGuizmo::Manipulate(glm::value_ptr(cam.ViewMatrix), glm::value_ptr(cam.ProjectionMatrix), ImGuizmo::TRANSLATE, ImGuizmo::WORLD, glm::value_ptr(cam.ViewMatrix));
|
||||
|
||||
if (ImGui::IsWindowFocused())
|
||||
{
|
||||
isFocused = true;
|
||||
|
||||
}
|
||||
else {
|
||||
isFocused = false;
|
||||
}
|
||||
}
|
@ -38,82 +38,32 @@ public:
|
||||
SceneExplorer explorer(Selected, scene);
|
||||
Inspector inspector = Inspector(Selected);
|
||||
Settings settings = Settings();
|
||||
// AssetFinder assetsView = AssetFinder();
|
||||
// AssetFinder assetsView = AssetFinder();
|
||||
Console console = Console();
|
||||
|
||||
Selected = YoggieEngine::Entity((entt::entity) -1, &scene);
|
||||
|
||||
double previous = glfwGetTime();
|
||||
double lag = 0.0;
|
||||
while (!appWindow.WindowShouldClose())
|
||||
while (!appWindow->WindowShouldClose())
|
||||
{
|
||||
PollEvents();
|
||||
double now = glfwGetTime();
|
||||
double elapsed = now - previous ;
|
||||
previous = now;
|
||||
lag += elapsed;
|
||||
|
||||
if (sceneview.isFocused)
|
||||
{
|
||||
const float movement_speed = 0.1f;
|
||||
static float lastX = 400, lastY = 300;
|
||||
const float sensitivity = 0.1;
|
||||
static bool firstMouse = true;
|
||||
|
||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
||||
scene.Update();
|
||||
|
||||
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
auto newX = getCursorPosX(&appWindow);
|
||||
auto newY = getCursorPosY(&appWindow);
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
firstMouse = false;
|
||||
}
|
||||
|
||||
|
||||
float xoffset = newX - lastX;
|
||||
float yoffset = newY - lastY;
|
||||
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
|
||||
xoffset *= sensitivity;
|
||||
yoffset *= sensitivity;
|
||||
|
||||
sceneview.cam.yaw += xoffset;
|
||||
sceneview.cam.pitch += yoffset;
|
||||
|
||||
if (sceneview.cam.pitch > 89.0f)
|
||||
sceneview.cam.pitch = 89.0f;
|
||||
if (sceneview.cam.pitch < -89.0f)
|
||||
sceneview.cam.pitch = -89.0f;
|
||||
|
||||
}
|
||||
else if (firstMouse == false)
|
||||
{
|
||||
glfwSetInputMode(appWindow.GetGLFWHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
firstMouse = true;
|
||||
}
|
||||
|
||||
// Check for Camara movement input here!
|
||||
if (keyIsPressed(YOGGIE_KEY_W))
|
||||
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_A))
|
||||
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_S))
|
||||
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_D))
|
||||
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
||||
if (sceneview.isFocused) {
|
||||
UpdateSceneCamera(sceneview);
|
||||
|
||||
std::cout << "Scene view in Focus!\r" ;
|
||||
}
|
||||
|
||||
GuiBegin();
|
||||
|
||||
|
||||
{
|
||||
MainMenuBar menuBar = MainMenuBar();
|
||||
|
||||
@ -179,10 +129,70 @@ public:
|
||||
private:
|
||||
bool SimulatePhysics = true;
|
||||
YoggieEngine::Entity Selected;
|
||||
|
||||
Project project;
|
||||
Scene scene;
|
||||
|
||||
|
||||
void UpdateSceneCamera(Viewport& sceneview) {
|
||||
const float movement_speed = 0.1f;
|
||||
static float lastX = 400, lastY = 300;
|
||||
const float sensitivity = 0.1;
|
||||
static bool firstMouse = true;
|
||||
|
||||
if (MouseButtonPressed(YOGGIE_MOUSE_BUTTON_RIGHT)) {
|
||||
|
||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
auto newX = getCursorPosX(appWindow);
|
||||
auto newY = getCursorPosY(appWindow);
|
||||
|
||||
if (firstMouse)
|
||||
{
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
firstMouse = false;
|
||||
}
|
||||
|
||||
|
||||
float xoffset = newX - lastX;
|
||||
float yoffset = newY - lastY;
|
||||
|
||||
lastX = newX;
|
||||
lastY = newY;
|
||||
|
||||
xoffset *= sensitivity;
|
||||
yoffset *= sensitivity;
|
||||
|
||||
sceneview.cam.yaw += xoffset;
|
||||
sceneview.cam.pitch += yoffset;
|
||||
|
||||
if (sceneview.cam.pitch > 89.0f)
|
||||
sceneview.cam.pitch = 89.0f;
|
||||
if (sceneview.cam.pitch < -89.0f)
|
||||
sceneview.cam.pitch = -89.0f;
|
||||
|
||||
}
|
||||
else if (firstMouse == false)
|
||||
{
|
||||
glfwSetInputMode((GLFWwindow*)appWindow->GetHandle(), GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
firstMouse = true;
|
||||
}
|
||||
|
||||
// Check for Camara movement input here!
|
||||
if (keyIsPressed(YOGGIE_KEY_W)) {
|
||||
sceneview.cam.Position += sceneview.cam.Front * movement_speed;
|
||||
std::cout << "Pressed W !" << std::endl;
|
||||
}
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_A))
|
||||
sceneview.cam.Position -= sceneview.cam.Right * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_S))
|
||||
sceneview.cam.Position -= sceneview.cam.Front * movement_speed;
|
||||
|
||||
if (keyIsPressed(YOGGIE_KEY_D))
|
||||
sceneview.cam.Position += sceneview.cam.Right * movement_speed;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
YoggieEngine::Application* CreateApplication() {
|
||||
@ -190,3 +200,5 @@ YoggieEngine::Application* CreateApplication() {
|
||||
return new Editor();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,6 +11,10 @@ project "YoggieEngine"
|
||||
|
||||
}
|
||||
|
||||
filter "system:Windows"
|
||||
defines{
|
||||
"GLFW"
|
||||
}
|
||||
|
||||
includedirs {
|
||||
"./src",
|
||||
|
@ -9,8 +9,10 @@
|
||||
namespace YoggieEngine {
|
||||
|
||||
Application::Application(const std::string& name)
|
||||
: m_AppName(name), appWindow(1200, 700)
|
||||
: m_AppName(name)
|
||||
{
|
||||
appWindow = CreateNativeWindow(1200, 700, m_AppName.c_str());
|
||||
|
||||
// Initialize engine should possibly happen here
|
||||
EngineInstrumentation::PerfomanceSamplerInit();
|
||||
|
||||
@ -24,14 +26,14 @@ namespace YoggieEngine {
|
||||
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGui_ImplGlfw_InitForOpenGL(appWindow.GetGLFWHandle(), true);
|
||||
ImGui_ImplGlfw_InitForOpenGL((GLFWwindow*)appWindow->GetHandle(), true);
|
||||
ImGui_ImplOpenGL3_Init("#version 450");
|
||||
|
||||
ImGuizmo::SetImGuiContext(ImGui::GetCurrentContext());
|
||||
ImGuizmo::SetOrthographic(true);
|
||||
|
||||
|
||||
init_inputSystem(&appWindow);
|
||||
init_inputSystem(appWindow);
|
||||
}
|
||||
|
||||
|
||||
@ -41,12 +43,12 @@ namespace YoggieEngine {
|
||||
|
||||
|
||||
void Application::PollEvents() {
|
||||
appWindow.Poll();
|
||||
appWindow->Poll();
|
||||
}
|
||||
|
||||
void Application::SwapBuffers()
|
||||
{
|
||||
appWindow.SwapBuffers();
|
||||
appWindow->SwapBuffers();
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
@ -81,5 +83,8 @@ namespace YoggieEngine {
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
ImGui_ImplGlfw_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
|
||||
delete appWindow;
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace YoggieEngine {
|
||||
|
||||
protected:
|
||||
std::string m_AppName;
|
||||
NativeWindow appWindow;
|
||||
NativeWindow* appWindow;
|
||||
friend class ApplicationRuntime;
|
||||
};
|
||||
|
||||
|
@ -71,14 +71,14 @@ Renderer::Renderer(RendererConfig& config)
|
||||
lightingPassShader("build/Debug/Shaders/deferred/lightPass.vert", "build/Debug/Shaders/deferred/lightPass.frag"),
|
||||
SkyboxShader("build/Debug/Shaders/Cubemaps/Skybox.vert", "build/Debug/Shaders/Cubemaps/Skybox.frag"),
|
||||
BlendingShader("build/Debug/Shaders/forward/Blending.vert", "build/Debug/Shaders/forward/Blending.frag"),
|
||||
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag")
|
||||
forwardShader("build/Debug/Shaders/forward/geometry.vert", "build/Debug/Shaders/forward/geometry.frag"),
|
||||
postProcessingShader("build/Debug/Shaders/forward/postprocessing.vert", "build/Debug/Shaders/forward/postprocessing.frag")
|
||||
{
|
||||
width = config.ScreenWidth;
|
||||
height = config.ScreenHeight;
|
||||
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
// Deferred Rendering
|
||||
glGenFramebuffers(1, &gBuffer);
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, gBuffer);
|
||||
@ -150,9 +150,6 @@ Renderer::Renderer(RendererConfig& config)
|
||||
#else
|
||||
grassTexture = Texture("build/Debug/Texture/grass.png", true);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -257,6 +254,32 @@ void Renderer::GeometryPass() {
|
||||
|
||||
}
|
||||
|
||||
void Renderer::ForwardGeometryPass()
|
||||
{
|
||||
for (const DrawCommand& command : commands)
|
||||
{
|
||||
if (command.isDynamic == false)
|
||||
continue;
|
||||
|
||||
glBindVertexArray(command.VAO_identifier);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||
|
||||
forwardShader.Use();
|
||||
|
||||
forwardShader.setUniformVec3("Color", command.color);
|
||||
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
||||
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
||||
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||
GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Renderer::SkyboxPass() {
|
||||
// Render skybox
|
||||
glDepthMask(GL_FALSE);
|
||||
@ -267,7 +290,6 @@ void Renderer::SkyboxPass() {
|
||||
glBindTexture(GL_TEXTURE_CUBE_MAP, sky.getID());
|
||||
glDrawArrays(GL_TRIANGLES, 0, 36);
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDepthMask(GL_TRUE);
|
||||
|
||||
}
|
||||
@ -361,12 +383,38 @@ void Renderer::BlendingPass() {
|
||||
|
||||
}
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
glDisable(GL_BLEND);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Renderer::PostProcessing()
|
||||
{
|
||||
postProcessingShader.Use();
|
||||
postProcessingShader.setUniformInt("screen", 0);
|
||||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, m_framebuffer.GetColourAttachment());
|
||||
|
||||
|
||||
glBindVertexArray(quadVAO);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
glBindVertexArray(0);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void Renderer::CopyGBuffer() {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
}
|
||||
|
||||
void Renderer::Render(Scene& scene)
|
||||
{
|
||||
SubmitVegetationDemo();
|
||||
@ -380,37 +428,13 @@ void Renderer::Render(Scene& scene)
|
||||
|
||||
lightingPass(scene);
|
||||
|
||||
CopyGBuffer();
|
||||
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, gBuffer);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
glBlitFramebuffer(0, 0, width, height, 0, 0, width, height, GL_DEPTH_BUFFER_BIT, GL_NEAREST);
|
||||
ForwardGeometryPass();
|
||||
|
||||
// Forward rendering approach
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer.GetId());
|
||||
|
||||
for (const DrawCommand& command : commands)
|
||||
{
|
||||
if (command.isDynamic == false)
|
||||
continue;
|
||||
|
||||
glBindVertexArray(command.VAO_identifier);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, command.IBO_identifier);
|
||||
|
||||
forwardShader.Use();
|
||||
|
||||
forwardShader.setUniformVec3("Color", command.color);
|
||||
forwardShader.setUniformMat4("M", command.transform.LocalTransform);
|
||||
forwardShader.setUniformMat4("V", MainCamera.ViewMatrix);
|
||||
forwardShader.setUniformMat4("P", MainCamera.ProjectionMatrix);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, static_cast<unsigned int>(command.num_elements),
|
||||
GL_UNSIGNED_INT, NULL);
|
||||
|
||||
glBindVertexArray(0);
|
||||
|
||||
}
|
||||
BlendingPass();
|
||||
|
||||
//PostProcessing();
|
||||
|
||||
|
||||
// Lighting pass
|
||||
|
@ -35,10 +35,12 @@ namespace YoggieEngine {
|
||||
Framebuffer& getCurrentFrameBuffer() { return m_framebuffer; }
|
||||
private:
|
||||
void GeometryPass();
|
||||
void ForwardGeometryPass();
|
||||
void SkyboxPass();
|
||||
void lightingPass(Scene& scene);
|
||||
void BlendingPass();
|
||||
|
||||
void PostProcessing();
|
||||
void CopyGBuffer();
|
||||
|
||||
|
||||
private:
|
||||
@ -59,6 +61,8 @@ namespace YoggieEngine {
|
||||
Shader lightingPassShader;
|
||||
Shader gBufferShader;
|
||||
Shader SkyboxShader;
|
||||
Shader postProcessingShader;
|
||||
|
||||
|
||||
// blending
|
||||
Shader BlendingShader;
|
||||
|
@ -17,10 +17,10 @@ namespace YoggieEngine {
|
||||
void init_inputSystem(NativeWindow* window) {
|
||||
cursor_pos_x = 0;
|
||||
cursor_pos_y = 0;
|
||||
glfwSetKeyCallback(window->GetGLFWHandle(), key_callback);
|
||||
glfwSetMouseButtonCallback(window->GetGLFWHandle(), mouseButton_callback);
|
||||
glfwSetCursorPosCallback(window->GetGLFWHandle(), cursorPos_callback);
|
||||
glfwSetCursorEnterCallback(window->GetGLFWHandle(), cursorEnter_callback);
|
||||
glfwSetKeyCallback((GLFWwindow*) window->GetHandle(), key_callback);
|
||||
glfwSetMouseButtonCallback((GLFWwindow*)window->GetHandle(), mouseButton_callback);
|
||||
glfwSetCursorPosCallback((GLFWwindow*)window->GetHandle(), cursorPos_callback);
|
||||
glfwSetCursorEnterCallback((GLFWwindow*)window->GetHandle(), cursorEnter_callback);
|
||||
}
|
||||
|
||||
void ReceiveInput() {
|
||||
@ -43,13 +43,13 @@ namespace YoggieEngine {
|
||||
|
||||
double getCursorPosX(NativeWindow* window)
|
||||
{
|
||||
glfwGetCursorPos(window->GetGLFWHandle(), &cursor_pos_x, nullptr);
|
||||
glfwGetCursorPos((GLFWwindow*)window->GetHandle(), &cursor_pos_x, nullptr);
|
||||
return cursor_pos_x;
|
||||
}
|
||||
|
||||
double getCursorPosY(NativeWindow* window)
|
||||
{
|
||||
glfwGetCursorPos(window->GetGLFWHandle(), nullptr, &cursor_pos_y);
|
||||
glfwGetCursorPos((GLFWwindow*)window->GetHandle(), nullptr, &cursor_pos_y);
|
||||
return cursor_pos_y;
|
||||
}
|
||||
|
||||
|
26
YoggieEngine/src/Platform/Linux/X11Window.cpp
Normal file
26
YoggieEngine/src/Platform/Linux/X11Window.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
#include "YoggieEngine.h"
|
||||
#include "X11Window.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
X11Window::X11Window(const int width, const int height, const char* title) : NativeWindow()
|
||||
{
|
||||
|
||||
// Open a display
|
||||
//Display* d = XOpenDisplay(0);
|
||||
|
||||
//if (d) {
|
||||
// // create the window
|
||||
// Window w = XCreateWindow(d, DefaultRootWindow(d), 0, 0, 200, 100, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, 0);
|
||||
// // show the window
|
||||
// XMapWindow(d, w);
|
||||
// XFlush(d);
|
||||
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
32
YoggieEngine/src/Platform/Linux/X11Window.h
Normal file
32
YoggieEngine/src/Platform/Linux/X11Window.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include "../Window.h"
|
||||
|
||||
//#include <X11/Xlib.h>
|
||||
//#include <unistd.h>
|
||||
|
||||
namespace YoggieEngine {
|
||||
class X11Window : public NativeWindow {
|
||||
public:
|
||||
X11Window(const int width, const int height, const char* title);
|
||||
~X11Window();
|
||||
|
||||
bool WindowShouldClose();
|
||||
|
||||
void SetViewPort(int width, int height);
|
||||
void Poll();
|
||||
void SwappBuffers();
|
||||
|
||||
void* GetHandle();
|
||||
|
||||
private:
|
||||
void* m_handle;
|
||||
bool m_fullscreen;
|
||||
bool m_resizable;
|
||||
bool m_vsync;
|
||||
int m_widht;
|
||||
int m_height;
|
||||
|
||||
void SetContext();
|
||||
|
||||
};
|
||||
}
|
25
YoggieEngine/src/Platform/Platform.h
Normal file
25
YoggieEngine/src/Platform/Platform.h
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include "Window.h"
|
||||
#include "glfw/glfwWindow.h"
|
||||
#include "Windows/win32Window.h"
|
||||
namespace YoggieEngine {
|
||||
|
||||
inline NativeWindow* CreateNativeWindow(int width, int height, const char* title) {
|
||||
spdlog::debug("CreateNativeWindow is called!");
|
||||
|
||||
|
||||
#ifdef PLATFORM_WINDOWS
|
||||
spdlog::debug("PLATFROM_WINDOWS");
|
||||
return win32Window(width, height, title);
|
||||
#elseif PLATFORM_LINUX
|
||||
spdlog::debug("PLATFORM_LINUX");
|
||||
return X11Window(width, height, title);
|
||||
#else
|
||||
spdlog::debug("PLATFORM_GLFW");
|
||||
return new glfwWindow(width, height, title);
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,86 +0,0 @@
|
||||
#include <YoggieEngine.h>
|
||||
#include "Window.h"
|
||||
namespace YoggieEngine {
|
||||
void LoadGLExtensions();
|
||||
|
||||
NativeWindow::NativeWindow(const int width, const int height) :
|
||||
Width(width), Height(height), FullScreen(false)
|
||||
{
|
||||
if (InitGLFW() == false) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
|
||||
|
||||
if( FullScreen )
|
||||
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||
if( !Resizable)
|
||||
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
|
||||
if (!VSync)
|
||||
glfwSwapInterval(0);
|
||||
|
||||
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
||||
|
||||
if (!window)
|
||||
{
|
||||
spdlog::error("GLFW failed to create window!");
|
||||
glfwTerminate();
|
||||
return;
|
||||
}
|
||||
|
||||
SetContext();
|
||||
glfwGetFramebufferSize(window, &Width, &Height);
|
||||
LoadGLExtensions();
|
||||
|
||||
}
|
||||
|
||||
void NativeWindow::SetViewPort(int width, int height) {
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
NativeWindow::~NativeWindow() {
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
bool NativeWindow::WindowShouldClose() {
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void NativeWindow::SetContext()
|
||||
{
|
||||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
|
||||
void NativeWindow::Poll()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void NativeWindow::SwapBuffers()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
bool NativeWindow::InitGLFW()
|
||||
{
|
||||
if (!glfwInit())
|
||||
{
|
||||
spdlog::error("Failed to initialise GLFW!");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LoadGLExtensions()
|
||||
{
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
spdlog::error("Failed to initialize GLAD!\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,41 +1,33 @@
|
||||
#pragma once
|
||||
#define GLFW_STATIC
|
||||
|
||||
#include <iostream>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include "../EventSystem/Event.h"
|
||||
#include "../EventSystem/EventListener.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
class NativeWindow {
|
||||
|
||||
public:
|
||||
NativeWindow(const int width, const int height);
|
||||
~NativeWindow();
|
||||
NativeWindow() { spdlog::debug("NativeWindow Constructor called!"); }
|
||||
virtual bool WindowShouldClose() { return true; }
|
||||
|
||||
bool WindowShouldClose();
|
||||
virtual void SetViewPort(int width , int height) {}
|
||||
virtual void Poll() {}
|
||||
virtual void SwapBuffers() {}
|
||||
|
||||
void SetViewPort(int width , int height);
|
||||
void Poll();
|
||||
void SwapBuffers();
|
||||
const int getWidth()const { return m_width; }
|
||||
const int getHeight()const { return m_height; }
|
||||
|
||||
GLFWwindow* GetGLFWHandle() { return window; }
|
||||
const int getWidth()const { return Width; }
|
||||
const int getHeight()const { return Height; }
|
||||
virtual void* GetHandle() { return m_handle; }
|
||||
|
||||
|
||||
private:
|
||||
GLFWwindow* window;
|
||||
bool FullScreen = false;
|
||||
bool Resizable = true;
|
||||
bool VSync = false;
|
||||
int Width, Height;
|
||||
protected:
|
||||
virtual void SetContext() {}
|
||||
|
||||
void SetContext();
|
||||
static bool InitGLFW();
|
||||
bool m_fullscreen = false;
|
||||
bool m_resizable = true;
|
||||
bool m_vsync = false;
|
||||
int m_width;
|
||||
int m_height;
|
||||
void* m_handle;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
46
YoggieEngine/src/Platform/Windows/win32Window.cpp
Normal file
46
YoggieEngine/src/Platform/Windows/win32Window.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
#include "YoggieEngine.h"
|
||||
#include "win32Window.h"
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
namespace YoggieEngine {
|
||||
Win32Window::Win32Window(const int width, const int height, const char* title)
|
||||
{
|
||||
|
||||
//WNDCLASS wc = {};
|
||||
|
||||
//wc.lpfnWndProc = WindowProc;
|
||||
//wc.hInstance = GetModuleHandle(NULL);
|
||||
//wc.lpszClassName = (const wchar_t*) title;
|
||||
|
||||
//RegisterClass(&wc);
|
||||
|
||||
//HWND hwnd = CreateWindowEx(
|
||||
// 0, // Optional window style
|
||||
// (const wchar_t*)title, // Window Class
|
||||
// (const wchar_t*)title, // Window Text
|
||||
// WS_OVERLAPPEDWINDOW, // Window Style
|
||||
// // Size and Position
|
||||
// CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
|
||||
|
||||
// NULL, // Parent window
|
||||
// NULL, // Menu
|
||||
// wc.hInstance, // Instance handle
|
||||
// NULL // Additional appplication data
|
||||
//);
|
||||
|
||||
//if (hwnd == NULL) {
|
||||
// spdlog::error("This is bad!! Window creation failed!");
|
||||
|
||||
// return;
|
||||
//}
|
||||
|
||||
//ShowWindow(hwnd, SW_NORMAL);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
31
YoggieEngine/src/Platform/Windows/win32Window.h
Normal file
31
YoggieEngine/src/Platform/Windows/win32Window.h
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include "../Window.h"
|
||||
|
||||
|
||||
namespace YoggieEngine {
|
||||
class Win32Window : public NativeWindow {
|
||||
public:
|
||||
Win32Window(const int width, const int height, const char* title);
|
||||
~Win32Window();
|
||||
|
||||
bool WindowShouldClose();
|
||||
|
||||
void setViewPort(int width, int height);
|
||||
void Poll();
|
||||
void SwapBuffers();
|
||||
|
||||
void* GetHandle();
|
||||
|
||||
|
||||
private:
|
||||
void SetContext();
|
||||
bool m_vsync;
|
||||
bool m_resizable;
|
||||
bool m_fullscreen;
|
||||
int m_width;
|
||||
int m_height;
|
||||
|
||||
|
||||
};
|
||||
|
||||
}
|
93
YoggieEngine/src/Platform/glfw/glfwWindow.cpp
Normal file
93
YoggieEngine/src/Platform/glfw/glfwWindow.cpp
Normal file
@ -0,0 +1,93 @@
|
||||
#include "YoggieEngine.h"
|
||||
#include "glfwWindow.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
void LoadGLExtensions() {
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
||||
spdlog::error("Failed to initialize GLAD!\n");
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
glfwWindow::glfwWindow(const int width, const int height, const char* title)
|
||||
: NativeWindow()
|
||||
{
|
||||
spdlog::debug("Creating window");
|
||||
m_width = width;
|
||||
m_height = height;
|
||||
m_fullscreen = false;
|
||||
|
||||
|
||||
if (!glfwInit()) {
|
||||
|
||||
spdlog::error("Failed to initialise GLFW!");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
|
||||
glfwWindowHint(GLFW_FOCUS_ON_SHOW, GLFW_TRUE);
|
||||
|
||||
if (m_fullscreen) {
|
||||
glfwWindowHint(GLFW_MAXIMIZED, GLFW_TRUE);
|
||||
}
|
||||
|
||||
if (!m_resizable) {
|
||||
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
|
||||
}
|
||||
|
||||
if (!m_vsync) {
|
||||
glfwSwapInterval(0);
|
||||
}
|
||||
|
||||
window = glfwCreateWindow(m_width, m_height, title, NULL, NULL);
|
||||
|
||||
if (!window) {
|
||||
spdlog::error("GLFW failed to create a window!");
|
||||
glfwTerminate();
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
SetContext();
|
||||
glfwGetFramebufferSize(window, &m_width, &m_height);
|
||||
LoadGLExtensions();
|
||||
|
||||
|
||||
}
|
||||
|
||||
glfwWindow::~glfwWindow()
|
||||
{
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
bool glfwWindow::WindowShouldClose()
|
||||
{
|
||||
return glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void glfwWindow::Poll()
|
||||
{
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void glfwWindow::SwapBuffers()
|
||||
{
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
void* glfwWindow::GetHandle()
|
||||
{
|
||||
return window;
|
||||
}
|
||||
|
||||
void glfwWindow::SetViewPort(int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
}
|
||||
|
||||
void glfwWindow::SetContext()
|
||||
{
|
||||
glfwMakeContextCurrent(window);
|
||||
}
|
||||
}
|
||||
|
29
YoggieEngine/src/Platform/glfw/glfwWindow.h
Normal file
29
YoggieEngine/src/Platform/glfw/glfwWindow.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <GLFW/glfw3.h>
|
||||
#include "../Window.h"
|
||||
|
||||
namespace YoggieEngine {
|
||||
|
||||
class glfwWindow : public NativeWindow {
|
||||
|
||||
public:
|
||||
glfwWindow(const int width, const int height, const char* title);
|
||||
~glfwWindow();
|
||||
|
||||
bool WindowShouldClose() override;
|
||||
void Poll() override;
|
||||
void SwapBuffers() override;
|
||||
void* GetHandle() override;
|
||||
void SetViewPort(int width, int height) override;
|
||||
|
||||
private:
|
||||
void SetContext() override;
|
||||
|
||||
private:
|
||||
// GLFW specific
|
||||
GLFWwindow* window;
|
||||
|
||||
|
||||
|
||||
};
|
||||
}
|
@ -31,8 +31,7 @@ extern "C"
|
||||
|
||||
|
||||
// Main library stuff
|
||||
|
||||
#include "Platform/Window.h"
|
||||
#include "Platform/Platform.h"
|
||||
|
||||
#include "Graphics/Primitives/Mesh.h"
|
||||
#include "Graphics/Primitives/Shader.h"
|
||||
|
@ -16,6 +16,7 @@ workspace "Yoggie GameEngine"
|
||||
|
||||
defines{
|
||||
" _CRT_SECURE_NO_WARNINGS",
|
||||
"GLFW_STATIC"
|
||||
}
|
||||
|
||||
filter "configurations:Debug"
|
||||
|
Loading…
x
Reference in New Issue
Block a user