This commit is contained in:
2026-07-02 21:59:55 -07:00
commit e14550ce63
12 changed files with 370 additions and 0 deletions

0
source/engin/shaders.c Normal file
View File

16
source/engin/shaders.h Normal file
View File

@@ -0,0 +1,16 @@
#ifndef SHADERS_H
#define SHADERS_H
typedef struct {
char* vertex;
int vertexSize;
char* fragment;
int fragmentSize;
} shader;
int ReadFragmentShader(const char* path, shader* shader);
int ReadVertexShader(const char* path, shader* shader);
#endif

75
source/engin/window.c Normal file
View File

@@ -0,0 +1,75 @@
#include "window.h"
#include "GLFW/glfw3.h"
#include <string.h>
int keyState[GLFW_KEY_LAST] = {0};
// Key name lookup table (optional, you can hardcode or load from a config)
const char* keyNames[GLFW_KEY_LAST] = {
"Escape", "F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
"Backspace", "Tab", "Return", "Space", "Delete", "Insert", "Home", "End", "PageUp", "PageDown",
"Left", "Up", "Right", "Down", "PrintScreen", "Pause", "ScrollLock", "NumLock", "CapsLock",
"Shift", "Control", "Alt", "Super", "Enter", "Backspace", "Tab", "Space",
// Add more key names as needed
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
// Add more if needed
};
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
int WindowCreate(window* w, window_config *config) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
w->ctx = glfwCreateWindow(config->width, config->height, config->Name, 0, 0);
glfwMakeContextCurrent(w->ctx);
glfwSetKeyCallback(w->ctx, keyCallback);
glewExperimental = GL_TRUE;
glewInit();
glfwGetFramebufferSize(w->ctx, &w->width, &w->height);
return 0;
}
int WindowHandleInput(window* w) {
return 0;
}
int WindowEventHandler(window* w) {
return 0;
}
static int keyNameToCode(const char* name) {
for (int i = 0; i < GLFW_KEY_LAST; ++i) {
if (strcmp(name, keyNames[i]) == 0) {
return i;
}
}
return -1; // invalid key
}
// GetKey wrapper
int GetKey(const char* keyName) {
int keyCode = keyNameToCode(keyName);
if (keyCode == -1) {
return 0; // or you can handle error differently
}
return keyState[keyCode];
}
// GLFW key callback
void keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key >= 0 && key < GLFW_KEY_LAST) {
if (action == GLFW_PRESS) {
keyState[key] = 1;
} else if (action == GLFW_RELEASE) {
keyState[key] = 0;
}
}
}

44
source/engin/window.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef WINDOW_H
#define WINDOW_H
typedef int(*window_evnet_cb)(int argc, void* argv);
typedef struct {
const char* Log;
window_evnet_cb callback;
}window_event;
#ifdef _GLFW_WAYLAND
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
typedef GLFWwindow context;
#else
// If not using GLFW
#endif
typedef struct {
const char* Name;
const char* Description;
int width;
int height;
window_event windowClosedEvent;
window_event windowOpenEvent;
window_event windowKeyEvent;
}window_config;
typedef struct {
const char* Name;
const char* Description;
int width;
int height;
context* ctx;
}window;
int WindowCreate(window* w,window_config* config);
int WindowHandleInput(window* w);
int WindowEventHandler(window* w);
int GetKeyDown(const char* keyName);
#endif