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