|
@@ -3,39 +3,39 @@
|
|
|
#include <GLFW/glfw3.h>
|
|
#include <GLFW/glfw3.h>
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
-bool windowTest() {
|
|
|
|
|
- GLFWwindow* window;
|
|
|
|
|
|
|
+#define SET_ERROR(format, ...) \
|
|
|
|
|
+ snprintf(e.text, sizeof(e.text), format __VA_OPT__(, ) __VA_ARGS__);
|
|
|
|
|
|
|
|
- /* Initialize the library */
|
|
|
|
|
|
|
+static GLFWwindow* window = nullptr;
|
|
|
|
|
+
|
|
|
|
|
+Error windowInit(const WindowSettings* ws) {
|
|
|
|
|
+ Error e = {};
|
|
|
if(!glfwInit()) {
|
|
if(!glfwInit()) {
|
|
|
- printf("init failed\n");
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ SET_ERROR("Init window failed");
|
|
|
|
|
+ return e;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /* Create a windowed mode window and its OpenGL context */
|
|
|
|
|
- window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
|
|
|
|
|
- if(!window) {
|
|
|
|
|
|
|
+ window =
|
|
|
|
|
+ glfwCreateWindow(ws->width, ws->height, ws->title, nullptr, nullptr);
|
|
|
|
|
+ if(window == nullptr) {
|
|
|
glfwTerminate();
|
|
glfwTerminate();
|
|
|
- printf("create window failed\n");
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ SET_ERROR("Create window failed\n");
|
|
|
|
|
+ return e;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- /* Make the window's context current */
|
|
|
|
|
glfwMakeContextCurrent(window);
|
|
glfwMakeContextCurrent(window);
|
|
|
|
|
+ return e;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- /* Loop until the user closes the window */
|
|
|
|
|
- while(!glfwWindowShouldClose(window)) {
|
|
|
|
|
- /* Render here */
|
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
-
|
|
|
|
|
- /* Swap front and back buffers */
|
|
|
|
|
- glfwSwapBuffers(window);
|
|
|
|
|
|
|
+void windowDestroy() {
|
|
|
|
|
+ glfwDestroyWindow(window);
|
|
|
|
|
+ glfwTerminate();
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- /* Poll for and process events */
|
|
|
|
|
- glfwPollEvents();
|
|
|
|
|
- }
|
|
|
|
|
- printf("YES\n");
|
|
|
|
|
|
|
+void windowNextFrame() {
|
|
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
+ glfwSwapBuffers(window);
|
|
|
|
|
+ glfwPollEvents();
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- glfwTerminate();
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+bool windowShouldClose() {
|
|
|
|
|
+ return glfwWindowShouldClose(window);
|
|
|
}
|
|
}
|