Refactorings.

This commit is contained in:
2021-06-08 21:26:16 +02:00
parent 6ad4351118
commit cf8f9dee6f
5 changed files with 42 additions and 22 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.vscode/
build/
main

4
run.sh
View File

@@ -1,4 +1,6 @@
#!/bin/bash
gcc `pkg-config --static --libs glfw3` -o main main.c
mkdir -p build
gcc `pkg-config --static --libs glfw3` -c src/window.c -o build/window.o
gcc `pkg-config --static --libs glfw3` build/window.o -o main src/main.c
./main

22
src/main.c Normal file
View File

@@ -0,0 +1,22 @@
#include <stdio.h>
#include <GLFW/glfw3.h>
#include "window.h"
void loop(GLFWwindow* window) {
while(!glfwWindowShouldClose(window)) {
// ...
glfwPollEvents();
}
}
int main(int argc, const char *argv[]) {
GLFWwindow* window = vkeCreateWindow("Test", 800, 600);
if(window == NULL) {
return -1;
}
loop(window);
vkeDestroyWindow(window);
return 0;
}

View File

@@ -1,7 +1,8 @@
#include "window.h"
#include <stdio.h>
#include <GLFW/glfw3.h>
GLFWwindow* createWindow(const char* title, int width, int height) {
GLFWwindow* vkeCreateWindow(const char* title, int width, int height) {
int err = glfwInit();
if(err != GLFW_TRUE) {
@@ -20,26 +21,7 @@ GLFWwindow* createWindow(const char* title, int width, int height) {
return window;
}
void destroyWindow(GLFWwindow* window) {
void vkeDestroyWindow(GLFWwindow* window) {
glfwDestroyWindow(window);
glfwTerminate();
}
void loop(GLFWwindow* window) {
while(!glfwWindowShouldClose(window)) {
// ...
glfwPollEvents();
}
}
int main(int argc, const char *argv[]) {
GLFWwindow* window = createWindow("Test", 800, 600);
if(window == NULL) {
return -1;
}
loop(window);
destroyWindow(window);
return 0;
}

13
src/window.h Normal file
View File

@@ -0,0 +1,13 @@
#ifndef VKE_WINDOW_H
#define VKE_WINDOW_H
#include <GLFW/glfw3.h>
// Creates a new window for given title and dimensions.
// Returns NULL in case of an error.
GLFWwindow* vkeCreateWindow(const char* title, int width, int height);
// Destroys given window.
void vkeDestroyWindow(GLFWwindow* window);
#endif