commit 8a8df1164130afcba2bbee9d3f2adfeab32be021
parent 2da13fe8158ad7dce6632795df417fbc1fbcc69f
Author: rexim <reximkut@gmail.com>
Date: Mon, 9 Jan 2023 13:38:45 +0700
Remove sdl_extra translation unit
Diffstat:
4 files changed, 24 insertions(+), 63 deletions(-)
diff --git a/build.sh b/build.sh
@@ -6,7 +6,7 @@ CC="${CXX:-cc}"
PKGS="sdl2 glew freetype2"
CFLAGS="-Wall -Wextra -std=c11 -pedantic -ggdb"
LIBS=-lm
-SRC="src/main.c src/la.c src/editor.c src/sdl_extra.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
+SRC="src/main.c src/la.c src/editor.c src/file.c src/gl_extra.c src/free_glyph.c src/simple_renderer.c"
if [ `uname` = "Darwin" ]; then
CFLAGS+=" -framework OpenGL"
diff --git a/src/main.c b/src/main.c
@@ -16,7 +16,6 @@
#include "./editor.h"
#include "./la.h"
-#include "./sdl_extra.h"
#include "./gl_extra.h"
#include "./free_glyph.h"
#include "./simple_renderer.h"
@@ -160,7 +159,7 @@ int main(int argc, char **argv)
FT_Error error = FT_Init_FreeType(&library);
if (error) {
fprintf(stderr, "ERROR: could initialize FreeType2 library\n");
- exit(1);
+ return 1;
}
const char *const font_file_path = "./VictorMono-Regular.ttf";
@@ -169,10 +168,10 @@ int main(int argc, char **argv)
error = FT_New_Face(library, font_file_path, 0, &face);
if (error == FT_Err_Unknown_File_Format) {
fprintf(stderr, "ERROR: `%s` has an unknown format\n", font_file_path);
- exit(1);
+ return 1;
} else if (error) {
fprintf(stderr, "ERROR: could not load file `%s`\n", font_file_path);
- exit(1);
+ return 1;
}
FT_UInt pixel_size = FREE_GLYPH_FONT_SIZE;
@@ -181,7 +180,7 @@ int main(int argc, char **argv)
error = FT_Set_Pixel_Sizes(face, 0, pixel_size);
if (error) {
fprintf(stderr, "ERROR: could not set pixel size to %u\n", pixel_size);
- exit(1);
+ return 1;
}
const char *file_path = NULL;
@@ -198,13 +197,20 @@ int main(int argc, char **argv)
}
}
- scc(SDL_Init(SDL_INIT_VIDEO));
+ if (SDL_Init(SDL_INIT_VIDEO) < 0) {
+ fprintf(stderr, "ERROR: Could not initialize SDL: %s\n", SDL_GetError());
+ return 1;
+ }
SDL_Window *window =
- scp(SDL_CreateWindow("Text Editor",
- 0, 0,
- SCREEN_WIDTH, SCREEN_HEIGHT,
- SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL));
+ SDL_CreateWindow("Text Editor",
+ 0, 0,
+ SCREEN_WIDTH, SCREEN_HEIGHT,
+ SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
+ if (window == NULL) {
+ fprintf(stderr, "ERROR: Could not create SDL window: %s\n", SDL_GetError());
+ return 1;
+ }
{
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
@@ -218,21 +224,24 @@ int main(int argc, char **argv)
printf("GL version %d.%d\n", major, minor);
}
- scp(SDL_GL_CreateContext(window));
+ if (SDL_GL_CreateContext(window) == NULL) {
+ fprintf(stderr, "Could not create OpenGL context: %s\n", SDL_GetError());
+ return 1;
+ }
if (GLEW_OK != glewInit()) {
fprintf(stderr, "Could not initialize GLEW!");
- exit(1);
+ return 1;
}
if (!GLEW_ARB_draw_instanced) {
fprintf(stderr, "ARB_draw_instanced is not supported; game may not work properly!!\n");
- exit(1);
+ return 1;
}
if (!GLEW_ARB_instanced_arrays) {
fprintf(stderr, "ARB_instanced_arrays is not supported; game may not work properly!!\n");
- exit(1);
+ return 1;
}
glEnable(GL_BLEND);
diff --git a/src/sdl_extra.c b/src/sdl_extra.c
@@ -1,26 +0,0 @@
-#include "./sdl_extra.h"
-
-void scc(int code)
-{
- if (code < 0) {
- fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
- exit(1);
- }
-}
-
-void *scp(void *ptr)
-{
- if (ptr == NULL) {
- fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
- exit(1);
- }
-
- return ptr;
-}
-
-Vec2f window_size(SDL_Window *window)
-{
- int w, h;
- SDL_GetWindowSize(window, &w, &h);
- return vec2f((float) w, (float) h);
-}
diff --git a/src/sdl_extra.h b/src/sdl_extra.h
@@ -1,22 +0,0 @@
-#ifndef SDL_EXTRA_H_
-#define SDL_EXTRA_H_
-
-#include <SDL2/SDL.h>
-
-#include "./la.h"
-
-#define UNHEX(color) \
- ((color) >> (8 * 0)) & 0xFF, \
- ((color) >> (8 * 1)) & 0xFF, \
- ((color) >> (8 * 2)) & 0xFF, \
- ((color) >> (8 * 3)) & 0xFF
-
-// SDL Check Code
-void scc(int code);
-
-// SDL Check Pointer
-void *scp(void *ptr);
-
-Vec2f window_size(SDL_Window *window);
-
-#endif // SDL_EXTRA_H_