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)
|
||||
{
|
||||
}
|
||||
}
|
||||
21
engine/Backend/Backend.h
Normal file
21
engine/Backend/Backend.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <glad/glad.h>
|
||||
#include <glfw/include/GLFW/glfw3.h>
|
||||
|
||||
namespace engine::Backend
|
||||
{
|
||||
void window_resize_callback(GLFWwindow* window, int width, int height);
|
||||
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
|
||||
void scroll_callback(GLFWwindow* window, double xoffset, double yoffset);
|
||||
void processInput(GLFWwindow *window);
|
||||
bool isWindowOpen();
|
||||
|
||||
void PreFrame();
|
||||
void PostFrame();
|
||||
|
||||
bool Init(const char* title, int width, int height);
|
||||
void Cleanup();
|
||||
}
|
||||
22
engine/assets/modelLoader.cpp
Normal file
22
engine/assets/modelLoader.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
|
||||
#include "modelLoader.h"
|
||||
|
||||
namespace engine::assets
|
||||
{
|
||||
Model loadBlendModel(const char *path)
|
||||
{
|
||||
return Model(path);
|
||||
}
|
||||
Model loadModel(const char *path)
|
||||
{
|
||||
int length = strlen(path);
|
||||
const char *blendEnd = &path[length - 6];
|
||||
std::cout << blendEnd << std::endl;
|
||||
|
||||
if (std::strcmp(blendEnd, ".blend")) {
|
||||
return loadBlendModel(path);
|
||||
}
|
||||
|
||||
return Model(path);
|
||||
}
|
||||
}
|
||||
9
engine/assets/modelLoader.h
Normal file
9
engine/assets/modelLoader.h
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#pragma once
|
||||
#include "engine/model.h"
|
||||
|
||||
namespace engine::assets
|
||||
{
|
||||
Model loadBlendModel(const char *path);
|
||||
Model loadModel(const char *path);
|
||||
}
|
||||
|
|
@ -218,7 +218,7 @@ private:
|
|||
};
|
||||
|
||||
|
||||
unsigned int TextureFromFile(const char *path, const string &directory, bool gamma)
|
||||
unsigned inline int TextureFromFile(const char *path, const string &directory, bool gamma)
|
||||
{
|
||||
string filename = string(path);
|
||||
filename = directory + '/' + filename;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue