Testing textures and events
This commit is contained in:
@ -12,12 +12,8 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
GLFWwindow *window;
|
||||
|
||||
// GLFW Callbacks
|
||||
void glfwOnError(int error, const char* description) {
|
||||
fputs(description, stderr);
|
||||
}
|
||||
// Static declaration of the host, needed due to GLFW events being C-like
|
||||
DawnHost *DAWN_HOST = nullptr;
|
||||
|
||||
// Host
|
||||
DawnHost::DawnHost() {
|
||||
@ -26,6 +22,10 @@ DawnHost::DawnHost() {
|
||||
}
|
||||
|
||||
int32_t DawnHost::init(DawnGame &game) {
|
||||
// Update values
|
||||
this->game = &game;
|
||||
DAWN_HOST = this;
|
||||
|
||||
// Init GLFW
|
||||
if(!glfwInit()) return DAWN_GLFW_INIT_RESULT_INIT_FAILED;
|
||||
|
||||
@ -35,18 +35,18 @@ int32_t DawnHost::init(DawnGame &game) {
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
|
||||
|
||||
// Create Window
|
||||
window = glfwCreateWindow(
|
||||
this->data->window = glfwCreateWindow(
|
||||
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT,
|
||||
"Dawn", NULL, NULL
|
||||
);
|
||||
if(window == nullptr) {
|
||||
if(this->data->window == nullptr) {
|
||||
glfwTerminate();
|
||||
return DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED;
|
||||
}
|
||||
|
||||
// Load GLAD
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwMakeContextCurrent(this->data->window);
|
||||
glfwSwapInterval(0);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
@ -59,6 +59,9 @@ int32_t DawnHost::init(DawnGame &game) {
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT
|
||||
);
|
||||
|
||||
// Set up event listeners
|
||||
glfwSetWindowSizeCallback(this->data->window, &glfwOnResize);
|
||||
|
||||
return DAWN_HOST_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -69,7 +72,7 @@ int32_t DawnHost::start(DawnGame &game) {
|
||||
|
||||
// Main Render Loop
|
||||
time = 0.0f;
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
while(!glfwWindowShouldClose(this->data->window)) {
|
||||
// Determine the delta.
|
||||
newTime = glfwGetTime();
|
||||
fDelta = (float_t)(newTime - time);
|
||||
@ -86,7 +89,7 @@ int32_t DawnHost::start(DawnGame &game) {
|
||||
}
|
||||
|
||||
// Tick the engine.
|
||||
glfwSwapBuffers(window);
|
||||
glfwSwapBuffers(this->data->window);
|
||||
|
||||
// Update events
|
||||
glfwPollEvents();
|
||||
@ -116,5 +119,24 @@ void DawnHost::unload(DawnGame &game) {
|
||||
}
|
||||
|
||||
DawnHost::~DawnHost() {
|
||||
DAWN_HOST = nullptr;
|
||||
}
|
||||
|
||||
|
||||
// GLFW Callbacks
|
||||
void glfwOnError(int error, const char* description) {
|
||||
fputs(description, stderr);
|
||||
}
|
||||
|
||||
void glfwOnResize(
|
||||
GLFWwindow *window,
|
||||
int32_t width,
|
||||
int32_t height
|
||||
) {
|
||||
if(DAWN_HOST == nullptr) return;
|
||||
// TODO: I may throttle this, it calls for every frame the window's resized.
|
||||
DAWN_HOST->game->renderManager.backBuffer.setSize(
|
||||
(float_t)width,
|
||||
(float_t)height
|
||||
);
|
||||
}
|
@ -22,4 +22,8 @@ namespace Dawn {
|
||||
public:
|
||||
GLFWwindow *window;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// GLFW Callbacks
|
||||
void glfwOnError(int error, const char* description);
|
||||
void glfwOnResize(GLFWwindow *window, int32_t width, int32_t height);
|
Reference in New Issue
Block a user