restructure work
This commit is contained in:
parent
64c8492e5c
commit
e01595e155
3424 changed files with 492 additions and 1696851 deletions
99
engine/Backend/Backend.cpp
Normal file
99
engine/Backend/Backend.cpp
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
|
||||
#include "Backend.h"
|
||||
|
||||
namespace engine::Backend
|
||||
{
|
||||
GLFWwindow* window;
|
||||
int SCREEN_WIDTH = 1920;
|
||||
int SCREEN_HEIGHT = 1080;
|
||||
|
||||
bool Init(const char* title, int width = SCREEN_WIDTH, int height = SCREEN_HEIGHT)
|
||||
{
|
||||
SCREEN_WIDTH = width;
|
||||
SCREEN_HEIGHT = height;
|
||||
|
||||
// Initialize GLFW
|
||||
glfwInit();
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
|
||||
// Create GLFW Window
|
||||
window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, title, NULL, NULL);
|
||||
if (window == NULL)
|
||||
{
|
||||
std::cout << "Failed to create GLFW window" << std::endl;
|
||||
glfwTerminate();
|
||||
return false;
|
||||
}
|
||||
glfwMakeContextCurrent(window);
|
||||
|
||||
// Initialize GLAD
|
||||
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
|
||||
{
|
||||
std::cout << "Failed to initialize GLAD" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
// Initialize Viewport & setup resize callback
|
||||
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
|
||||
glfwSetFramebufferSizeCallback(window, window_resize_callback);
|
||||
glfwSetCursorPosCallback(window, mouse_callback);
|
||||
glfwSetScrollCallback(window, scroll_callback);
|
||||
|
||||
// depth testing
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PreFrame()
|
||||
{
|
||||
// Input processing
|
||||
processInput(window);
|
||||
|
||||
// Depth buffer
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void PostFrame()
|
||||
{
|
||||
// Call events & swap buffers
|
||||
glfwSwapBuffers(window);
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
void Cleanup()
|
||||
{
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
bool isWindowOpen()
|
||||
{
|
||||
return !glfwWindowShouldClose(window);
|
||||
}
|
||||
|
||||
void window_resize_callback(GLFWwindow* window2, int width, int height)
|
||||
{
|
||||
glViewport(0, 0, width, height);
|
||||
SCREEN_WIDTH = width;
|
||||
SCREEN_HEIGHT = height;
|
||||
}
|
||||
|
||||
void processInput(GLFWwindow* window2)
|
||||
{
|
||||
// Close on Escape
|
||||
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
|
||||
glfwSetWindowShouldClose(window, true);
|
||||
}
|
||||
|
||||
void mouse_callback(GLFWwindow* window2, double xposIn, double yposIn)
|
||||
{
|
||||
}
|
||||
|
||||
void scroll_callback(GLFWwindow* window2, double xoffset, double yoffset)
|
||||
{
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue