Cleanup repo
This commit is contained in:
commit
4755371ffa
18 files changed
+20826
No files matched your search
@@ -0,0 +1,111 @@
|
||||
/**
|
||||
* @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 "localeWindow.h"
|
||||
#include "log.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 *gpWindowHandle = NULL;
|
||||
|
||||
/**
|
||||
* @brief GLFW erro callback
|
||||
*
|
||||
* @param error Error code
|
||||
* @param description Error description
|
||||
*/
|
||||
static void errrorCallback(int error, const char* description)
|
||||
{
|
||||
(void)error;
|
||||
LOG(ERROR, "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 keyCallback(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 windowInit()
|
||||
{
|
||||
/* Initiliaze GLFW AP */
|
||||
if (GLFW_TRUE != glfwInit())
|
||||
{
|
||||
LOG(FATAL, "%s", LOCALIZE(windowErrorMesssages[WINDOW_GLFW_INIT_FAILED]));
|
||||
return WINDOW_ERROR_GLFW_INIT_FAILED;
|
||||
}
|
||||
|
||||
|
||||
/* Check for Vulkan support */
|
||||
if (GLFW_FALSE == glfwVulkanSupported()) {
|
||||
LOG(FATAL, "%s", LOCALIZE(windowErrorMesssages[WINDOW_VULKAN_NOT_SUPPORTED]));
|
||||
return WINDOW_ERROR_VULKAN_NOT_LOADED;
|
||||
}
|
||||
|
||||
/* Set error callback */
|
||||
glfwSetErrorCallback(errrorCallback);
|
||||
|
||||
/* Create window */
|
||||
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||
|
||||
gpWindowHandle = glfwCreateWindow(640, 480, "RedScarfEngine", NULL, NULL);
|
||||
|
||||
if (NULL == gpWindowHandle) {
|
||||
LOG(FATAL, "%s", LOCALIZE(windowErrorMesssages[WINDOW_NOT_CREATED]));
|
||||
return WINDOW_ERROR_WINDOW_NOT_CREATED;
|
||||
}
|
||||
|
||||
glfwSetKeyCallback(gpWindowHandle, keyCallback);
|
||||
|
||||
return WINDOW_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
uint16_t windowLoop()
|
||||
{
|
||||
while (!glfwWindowShouldClose(gpWindowHandle)) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
|
||||
return WINDOW_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
void windowTerminate()
|
||||
{
|
||||
glfwDestroyWindow(gpWindowHandle);
|
||||
glfwTerminate();
|
||||
}
|
||||
|
||||
|
||||
GLFWwindow* getWindowHandle()
|
||||
{
|
||||
return gpWindowHandle;
|
||||
}
|
||||
Reference in new issue
Block a user