Procházet zdrojové kódy

Moving more stuff to font file

Vinicius Teshima před 1 rokem
rodič
revize
65d1a53e71
4 změnil soubory, kde provedl 32 přidání a 24 odebrání
  1. 0 0
      shaders/tile_font.frag
  2. 0 0
      shaders/tile_font.vert
  3. 5 24
      src/main.c
  4. 27 0
      src/tile_glyph.h

+ 0 - 0
shaders/font.frag → shaders/tile_font.frag


+ 0 - 0
shaders/font.vert → shaders/tile_font.vert


+ 5 - 24
src/main.c

@@ -41,7 +41,6 @@ int32_t
 main(int32_t argc, char **argv)
 {
 	enum buffer_err buffer_err;
-	enum shader_err shader_err;
 
 	if ( argc != 2 ) {
 		fprintf(stderr, "MUST pass file to open\n");
@@ -63,34 +62,16 @@ main(int32_t argc, char **argv)
 
 	struct tile_glyph_da glys = tile_glyph_da_create();
 
-	uint32_t prog;
 	uint32_t vert_shader;
 	uint32_t frag_shader;
+	uint32_t prog;
 
 	/* Loading shaders and linking prog */
 	{
-		RET_UNWRAP2(vert_shader, shader_err, struct ret_uint32_t_err,
-			    shader_compile_file("./shaders/font.vert",
-						GL_VERTEX_SHADER));
-		if ( shader_err != SHADER_ERR_OK ) {
-			fprintf(stderr, "Failed to compile shader font.vert\n");
-			exit(EXIT_FAILURE);
-		}
-
-		RET_UNWRAP2(frag_shader, shader_err, struct ret_uint32_t_err,
-			    shader_compile_file("./shaders/font.frag",
-						GL_FRAGMENT_SHADER));
-		if ( shader_err != SHADER_ERR_OK ) {
-			fprintf(stderr, "Failed to compile shader font.frag\n");
-			exit(EXIT_FAILURE);
-		}
-
-		RET_UNWRAP2(prog, shader_err, struct ret_uint32_t_err,
-			    program_link(vert_shader, frag_shader));
-		if ( shader_err != SHADER_ERR_OK ) {
-			fprintf(stderr, "Failed to link program\n");
-			exit(EXIT_FAILURE);
-		}
+		RET_UNWRAP2(vert_shader, frag_shader,
+			   struct ret_uint32_t_uint32_t,
+			   tile_glyph_compile_shaders_or_exit());
+		prog = program_link_or_exit(vert_shader, frag_shader);
 	}
 
 	glUseProgram(prog);

+ 27 - 0
src/tile_glyph.h

@@ -20,6 +20,11 @@ enum tile_glyph_attr_enum {
 	TILE_GLYPH_ATTR_TOTAL
 };
 
+struct ret_uint32_t_uint32_t {
+	uint32_t f1;
+	uint32_t f2;
+};
+
 struct tile_glyph_da tile_glyph_da_create(void);
 const struct glyph_attr* tile_glyph_get_attrs(void);
 
@@ -35,9 +40,20 @@ struct tile_glyph_da tile_glyph_da_calc_buffer(struct app app,
 void tile_glyph_da_sync(struct app app, struct tile_glyph_da glys);
 uint32_t tile_glyph_gen_buffer(struct tile_glyph_da glys);
 uint32_t tile_glyph_load_texture_atlas(const char *filepath);
+struct ret_uint32_t_uint32_t tile_glyph_compile_shaders_or_exit(void);
 
 #if defined(TILE_GLYPH_IMP) || defined(IMP)
 
+#ifdef STB_IMAGE_IMPLEMENTATION
+  #undef STB_IMAGE_IMPLEMENTATION
+  #include "stb_image.h"
+  #define STB_IMAGE_IMPLEMENTATION
+#else
+  #include "stb_image.h"
+#endif
+
+#include "unwrap.h"
+
 struct tile_glyph_da
 tile_glyph_da_create(void)
 {
@@ -179,6 +195,17 @@ tile_glyph_load_texture_atlas(const char *filepath)
 	return id;
 }
 
+struct ret_uint32_t_uint32_t
+tile_glyph_compile_shaders_or_exit(void)
+{
+	return (struct ret_uint32_t_uint32_t) {
+		.f1 = shader_compile_file_or_exit("./shaders/tile_font.vert",
+						  GL_VERTEX_SHADER),
+		.f2 = shader_compile_file_or_exit("./shaders/tile_font.frag",
+						  GL_FRAGMENT_SHADER),
+	};
+}
+
 #endif /* defined(TILE_GLYPH_IMP) || defined(IMP) */
 
 #endif