2022-05-28 11:32:17 +00:00
|
|
|
#include "Graphics/Window.h"
|
2022-05-27 20:47:36 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
2022-05-28 16:49:08 +00:00
|
|
|
#include <GLFW/glfw3.h>
|
|
|
|
#include <spdlog/spdlog.h>
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
bool BarinkWindow::InitGLFW(){
|
2022-04-22 20:37:38 +00:00
|
|
|
if(!glfwInit())
|
|
|
|
{
|
2022-05-28 16:49:08 +00:00
|
|
|
spdlog::error("Failed to initialise GLFW!");
|
2022-04-20 19:40:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2022-04-30 18:20:07 +00:00
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
BarinkWindow::BarinkWindow(const int width, const int height) :
|
|
|
|
Width(width), Height(height), FullScreen(false){
|
2022-04-30 18:20:07 +00:00
|
|
|
if (InitGLFW()==false) {
|
|
|
|
exit(-1);
|
|
|
|
}
|
2022-04-20 19:40:35 +00:00
|
|
|
|
|
|
|
window = glfwCreateWindow(Width, Height, "BarinkEngine", NULL, NULL);
|
|
|
|
|
2022-04-22 20:37:38 +00:00
|
|
|
if( !window)
|
|
|
|
{
|
2022-05-28 16:49:08 +00:00
|
|
|
spdlog::error("GLFW failed to create window!");
|
2022-04-20 19:40:35 +00:00
|
|
|
glfwTerminate();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
glfwMakeContextCurrent(window);
|
2022-04-30 18:20:07 +00:00
|
|
|
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
|
|
|
|
printf("Failed to initialize GLAD!\n");
|
|
|
|
exit(-1);
|
|
|
|
}
|
2022-04-20 19:40:35 +00:00
|
|
|
|
|
|
|
VulkanSupported = glfwVulkanSupported();
|
|
|
|
|
|
|
|
glfwGetFramebufferSize(window, &Width, &Height);
|
|
|
|
glViewport(0,0, Width, Height);
|
|
|
|
|
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
|
2022-04-30 18:20:07 +00:00
|
|
|
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
|
|
|
|
2022-04-20 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BarinkWindow::~BarinkWindow(){
|
|
|
|
|
|
|
|
glfwTerminate();
|
2022-05-28 11:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GLFWwindow* BarinkWindow::windowptr()
|
|
|
|
{
|
|
|
|
return window;
|
2022-04-20 19:40:35 +00:00
|
|
|
}
|
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
bool BarinkWindow::WindowShouldClose(){
|
|
|
|
return glfwWindowShouldClose(window);
|
|
|
|
}
|
2022-04-20 19:40:35 +00:00
|
|
|
|
2022-04-28 19:02:54 +00:00
|
|
|
void BarinkWindow::Poll()
|
2022-05-28 16:49:08 +00:00
|
|
|
{
|
2022-04-28 19:02:54 +00:00
|
|
|
glfwPollEvents();
|
2022-05-04 12:39:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BarinkWindow::SwapBuffers()
|
|
|
|
{
|
|
|
|
glfwSwapBuffers(window);
|
2022-04-20 19:40:35 +00:00
|
|
|
}
|