First pass of window manager file
This commit is contained in:
parent
5a78f43e55
commit
05b0361c69
3 changed files with 15 additions and 14 deletions
21
src/main.c
21
src/main.c
|
|
@ -14,8 +14,8 @@ const unsigned int SCR_HEIGHT = 600;
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
wn_window wn_window = {0};
|
||||
if (!wn_window_init(&wn_window)) {
|
||||
wn_window window = {0};
|
||||
if (!wn_window_init(&window)) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize wn_window");
|
||||
}
|
||||
|
||||
|
|
@ -111,21 +111,16 @@ int main(int argc, char *argv[]) {
|
|||
// Initialise camera
|
||||
Camera camera = Camera_default;
|
||||
|
||||
// Lock and hide mouse
|
||||
SDL_SetWindowRelativeMouseMode(wn_window.window, true);
|
||||
SDL_GetRelativeMouseState(NULL, NULL);
|
||||
|
||||
bool wants_running = true;
|
||||
while (wants_running) {
|
||||
|
||||
// handle input events
|
||||
while (SDL_PollEvent(&wn_window.event)) {
|
||||
switch (wn_window.event.type) {
|
||||
// TODO: Create event handler files
|
||||
while (SDL_PollEvent(&window.event)) {
|
||||
switch (window.event.type) {
|
||||
case SDL_EVENT_QUIT:
|
||||
wants_running = false;
|
||||
break;
|
||||
case SDL_EVENT_KEY_DOWN:
|
||||
if (wn_window.event.key.key == SDLK_ESCAPE) {
|
||||
if (window.event.key.key == SDLK_ESCAPE) {
|
||||
wants_running = false;
|
||||
}
|
||||
break;
|
||||
|
|
@ -155,7 +150,7 @@ int main(int argc, char *argv[]) {
|
|||
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
||||
// glBindVertexArray(0); // no need to unbind it every time
|
||||
|
||||
SDL_GL_SwapWindow(wn_window.window);
|
||||
wn_swapwindow(&window);
|
||||
}
|
||||
|
||||
glDeleteVertexArrays(1, &VAO);
|
||||
|
|
@ -163,7 +158,7 @@ int main(int argc, char *argv[]) {
|
|||
glDeleteBuffers(1, &EBO);
|
||||
glDeleteProgram(shaderProgram);
|
||||
|
||||
wn_window_deinit(&wn_window);
|
||||
wn_window_deinit(&window);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,10 @@ bool wn_window_init(wn_window *window) {
|
|||
"Couldn't make glcontext current: %s", SDL_GetError());
|
||||
}
|
||||
|
||||
// hide and lock mouse
|
||||
SDL_SetWindowRelativeMouseMode(window->window, true);
|
||||
SDL_GetRelativeMouseState(NULL, NULL);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -51,3 +55,5 @@ void wn_window_deinit(wn_window *window) {
|
|||
SDL_DestroyWindow(window->window);
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void wn_swapwindow(wn_window *window) { SDL_GL_SwapWindow(window->window); }
|
||||
|
|
|
|||
|
|
@ -16,4 +16,4 @@ typedef struct wn_window_s wn_window;
|
|||
bool wn_window_init(wn_window *window);
|
||||
void wn_window_deinit(wn_window *window);
|
||||
|
||||
void wn_swapwindow(wn_window *);
|
||||
void wn_swapwindow(wn_window *window);
|
||||
|
|
|
|||
Loading…
Reference in a new issue