summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSchark <jordan@schark.online>2023-05-10 23:42:32 -0700
committerSchark <jordan@schark.online>2023-05-10 23:42:32 -0700
commit79173c530d1846082c631dd4fe81c6429fffa5f0 (patch)
tree70603091ac337f34f9f54b5b9aa8acfc4e6bcef7 /src
parent1f63b19853f5dbbffb9a0c170f2260288d2f6020 (diff)
downloadgamedev-79173c530d1846082c631dd4fe81c6429fffa5f0.tar.gz
gamedev-79173c530d1846082c631dd4fe81c6429fffa5f0.zip
Transition to opengl and glfw
Diffstat (limited to 'src')
-rw-r--r--src/main.c50
1 files changed, 19 insertions, 31 deletions
diff --git a/src/main.c b/src/main.c
index c225b14..cb652fd 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,46 +1,34 @@
-#include <SDL.h>
+#include <GLFW/glfw3.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
- printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
- return 1;
- }
+ GLFWwindow* window;
- SDL_Window *window = SDL_CreateWindow("Raycaster", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
- if (!window) {
- printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
- return 1;
+ // initiate glfw library
+ if (!glfwInit()){
+ printf("Failed to initiate GLFW.\n");
+ return -1;
}
- SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_SOFTWARE);
- if (!renderer) {
- printf("Renderer could not be created. SDL_Error: %s\n", SDL_GetError());
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 1;
+ // create glfw window
+ window = glfwCreateWindow(800, 600, "raycaster", NULL, NULL);
+ if (!window){
+ printf("Failed to create GLFW window.\n");
+ glfwTerminate();
+ return -1;
}
- int running = 1;
- SDL_Event event;
-
- while (running) {
- while (SDL_PollEvent(&event)){
- if (event.type == SDL_QUIT) {
- running = 0;
- }
- }
+ // make window current
+ glfwMakeContextCurrent(window);
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- SDL_RenderClear(renderer);
+ while (!glfwWindowShouldClose(window)) {
- SDL_RenderPresent(renderer);
+ glClear(GL_COLOR_BUFFER_BIT);
+ glfwSwapBuffers(window);
+ glfwPollEvents();
}
- SDL_DestroyRenderer(renderer);
- SDL_DestroyWindow(window);
- SDL_Quit();
-
+ glfwTerminate();
return 0;
}