Move back to C

I'm insane and as such I have moved to C AGAIN! Without any reason.
This commit is contained in:
Piotr Krygier committed 2023-08-14 13:48:29 +02:00
1 parent bf31b96a2e
commit 3d538eaa2c
43 files changed
+2645 -2649

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
/**
* @file window.cxx
* @author Piotr Krygier (everyonencancode@gmail.com)
* @brief
* @version 0.1
* @date 2022-02-15
*
* @copyright Copyright (c) 2022
*
*/
#include "window.h"
#include "locale_window.h"
#include "utilities/logger.h"
#include "vulkan_base.h"
/* Error codes */
typedef enum {
WINDOW_ERROR_NO_ERROR = 0U,
WINDOW_ERROR_GLFW_INIT_FAILED,
WINDOW_ERROR_VULKAN_NOT_LOADED,
WINDOW_ERROR_WINDOW_NOT_CREATED
} WINDOW_ERROR;
GLFWwindow *g_window_handle = NULL;
/**
* @brief GLFW error callback
*
* @param error Error code
* @param description Error description
*/
static void error_callback(int error, const char* description)
{
(void)error;
LOGE("Error: %s", description);
}
/**
* @brief Pressed key callback
*
* @param window Window in which contex the key has been pressed
* @param key The keyboard key that was pressed or released
* @param scancode The system-specific scancode of the key.
* @param action GLFW_PRESS, GLFW_RELEASE or GLFW_REPEAT
* @param mods Bit field describing which modifier keys were held down
*/
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
(void)scancode;
(void)action;
(void)mods;
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) {
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
}
uint16_t window_init()
{
/* Initiliaze GLFW AP */
if (GLFW_TRUE != glfwInit())
{
LOGF(window_error_messages[WINDOW_GLFW_INIT_FAILED]);
return WINDOW_ERROR_GLFW_INIT_FAILED;
}
/* Check for Vulkan support */
if (GLFW_FALSE == glfwVulkanSupported()) {
LOGF(window_error_messages[WINDOW_VULKAN_NOT_SUPPORTED]);
return WINDOW_ERROR_VULKAN_NOT_LOADED;
}
/* Set error callback */
glfwSetErrorCallback(error_callback);
/* Create window */
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
g_window_handle = glfwCreateWindow(640, 480, "RedScarfEngine", NULL, NULL);
if (NULL == g_window_handle) {
LOGF(window_error_messages[WINDOW_NOT_CREATED]);
return WINDOW_ERROR_WINDOW_NOT_CREATED;
}
glfwSetKeyCallback(g_window_handle, key_callback);
return WINDOW_ERROR_NO_ERROR;
}
uint16_t window_loop()
{
while (!glfwWindowShouldClose(g_window_handle)) {
glfwPollEvents();
draw_frame();
}
return WINDOW_ERROR_NO_ERROR;
}
void window_terminate()
{
glfwDestroyWindow(g_window_handle);
glfwTerminate();
}
GLFWwindow* get_window_handle()
{
return g_window_handle;
}