Game rendering now.
This commit is contained in:
@ -7,9 +7,17 @@
|
||||
|
||||
#include "DawnGLFWHost.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "dawnopengl.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
GLFWwindow *window;
|
||||
|
||||
// GLFW Callbacks
|
||||
void glfwOnError(int error, const char* description) {
|
||||
fputs(description, stderr);
|
||||
}
|
||||
|
||||
// Host
|
||||
DawnHost::DawnHost() {
|
||||
this->data = std::make_unique<DawnHostData>();
|
||||
@ -19,23 +27,36 @@ DawnHost::DawnHost() {
|
||||
int32_t DawnHost::init(std::weak_ptr<DawnGame> game) {
|
||||
// Init GLFW
|
||||
if(!glfwInit()) return DAWN_GLFW_INIT_RESULT_INIT_FAILED;
|
||||
|
||||
glfwSetErrorCallback(&glfwOnError);
|
||||
|
||||
// Setup window hints
|
||||
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, false);
|
||||
|
||||
// Create Window
|
||||
this->data->window = glfwCreateWindow(
|
||||
window = glfwCreateWindow(
|
||||
DAWN_GLFW_WINDOW_WIDTH_DEFAULT,
|
||||
DAWN_GLFW_WINDOW_HEIGHT_DEFAULT,
|
||||
"Dawn", NULL, NULL
|
||||
);
|
||||
if(this->data->window == nullptr) {
|
||||
if(window == nullptr) {
|
||||
glfwTerminate();
|
||||
return DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED;
|
||||
}
|
||||
|
||||
// Load GLAD
|
||||
glfwMakeContextCurrent(this->data->window);
|
||||
// glfwSwapInterval(0); // "Vsync" disabled if uncommented
|
||||
glfwMakeContextCurrent(window);
|
||||
glfwSwapInterval(0);
|
||||
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
// Initialize the game
|
||||
if(auto g = game.lock()) {
|
||||
auto result = g->init();
|
||||
if(result != DAWN_GAME_INIT_RESULT_SUCCESS) return result;
|
||||
} else {
|
||||
return DAWN_GLFW_INIT_RESULT_GAME_LOCK_FAILED;
|
||||
}
|
||||
|
||||
return DAWN_HOST_INIT_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
@ -46,7 +67,7 @@ int32_t DawnHost::start(std::weak_ptr<DawnGame> game) {
|
||||
|
||||
// Main Render Loop
|
||||
time = 0.0f;
|
||||
while(true) {
|
||||
while(!glfwWindowShouldClose(window)) {
|
||||
// Determine the delta.
|
||||
newTime = glfwGetTime();
|
||||
fDelta = (float_t)(newTime - time);
|
||||
@ -63,15 +84,10 @@ int32_t DawnHost::start(std::weak_ptr<DawnGame> game) {
|
||||
}
|
||||
|
||||
// Tick the engine.
|
||||
glfwSwapBuffers(this->data->window);
|
||||
glfwSwapBuffers(window);
|
||||
|
||||
// Update events
|
||||
glfwPollEvents();
|
||||
|
||||
// Was the window requested to close?
|
||||
if(glfwWindowShouldClose(this->data->window)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return DAWN_HOST_START_RESULT_EXIT_SUCCESS;
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
#define DAWN_GLFW_INIT_RESULT_INIT_FAILED -1
|
||||
#define DAWN_GLFW_INIT_RESULT_WINDOW_CREATE_FAILED -2
|
||||
#define DAWN_GLFW_INIT_RESULT_GAME_LOCK_FAILED -3
|
||||
|
||||
#define DAWN_GLFW_START_RESULT_UPDATE_FAILED -1
|
||||
|
||||
|
@ -15,17 +15,16 @@ RenderManager::RenderManager(std::weak_ptr<DawnGame> game) {
|
||||
|
||||
void RenderManager::init() {
|
||||
glClearColor(
|
||||
0.39215686274f,
|
||||
0.39215686274f,
|
||||
0.58431372549f,
|
||||
0.9294117647f,
|
||||
1.0f
|
||||
);
|
||||
|
||||
glViewport(0, 0, 500, 500);
|
||||
glViewport(0, 0, 1280, 720);
|
||||
}
|
||||
|
||||
void RenderManager::update() {
|
||||
printf("Rendering\n");
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user