|
|
@@ -32,10 +32,11 @@
|
|
|
#include "config.h"
|
|
|
#include "shader.h"
|
|
|
#include "tile_glyph.h"
|
|
|
+#include "gl_util.h"
|
|
|
+
|
|
|
+struct app handle_events(struct app app, int32_t resolution_uniform);
|
|
|
|
|
|
-struct app handle_events(struct app app);
|
|
|
|
|
|
-int32_t get_uniform(uint32_t prog, const char *name);
|
|
|
|
|
|
int32_t
|
|
|
main(int32_t argc, char **argv)
|
|
|
@@ -60,45 +61,11 @@ main(int32_t argc, char **argv)
|
|
|
exit(EXIT_FAILURE);
|
|
|
}
|
|
|
|
|
|
- struct tile_glyph_da glys = tile_glyph_da_create();
|
|
|
-
|
|
|
- uint32_t vert_shader;
|
|
|
- uint32_t frag_shader;
|
|
|
- uint32_t prog;
|
|
|
-
|
|
|
- /* Loading shaders and linking prog */
|
|
|
- {
|
|
|
- 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);
|
|
|
+ /* Getting the uniforms */
|
|
|
|
|
|
- uint32_t font_tex = tile_glyph_load_texture_atlas(font_path);
|
|
|
- (void) font_tex;
|
|
|
|
|
|
- /* Getting the uniforms */
|
|
|
- app.uniforms.time = get_uniform(prog, "time");
|
|
|
- app.uniforms.resolution = get_uniform(prog, "resolution");
|
|
|
- app.uniforms.scale = get_uniform(prog, "scale");
|
|
|
- app.uniforms.camera = get_uniform(prog, "camera");
|
|
|
- /* app.uniforms.cursor = get_uniform(prog, "cursor"); */
|
|
|
-
|
|
|
- uint32_t vao = 0;
|
|
|
- uint32_t vbo = 0;
|
|
|
-
|
|
|
- /* Initialized array */
|
|
|
- {
|
|
|
- glGenVertexArrays(1, &vao);
|
|
|
- glBindVertexArray(vao);
|
|
|
- vbo = tile_glyph_gen_buffer(glys);
|
|
|
- (void) vbo;
|
|
|
- }
|
|
|
+ struct tile_glyph_render tgr = tile_glyph_render_create(font_path);
|
|
|
|
|
|
- glUniform1f(app.uniforms.scale, (float)app.font.scale);
|
|
|
- glUniform2f(app.uniforms.scale, 5.0, 5.0);
|
|
|
|
|
|
double dt = (1.0 / (double)app.target_fps) * 3;
|
|
|
uint32_t frame_target_dur = (uint32_t)(1000 / app.target_fps);
|
|
|
@@ -112,8 +79,10 @@ main(int32_t argc, char **argv)
|
|
|
|
|
|
while ( app.running ) {
|
|
|
fr_start = SDL_GetTicks();
|
|
|
+ glUniform1f(tgr.uniforms.scale,(float) app.font.scale);
|
|
|
+
|
|
|
struct buffer *buf = &app.buf;
|
|
|
- app = handle_events(app);
|
|
|
+ app = handle_events(app, tgr.uniforms.resolution);
|
|
|
|
|
|
if ( app.show_fps == true ) {
|
|
|
fps_text_size = (size_t) snprintf(fps_text, 128,
|
|
|
@@ -133,17 +102,18 @@ main(int32_t argc, char **argv)
|
|
|
RET_UNWRAP2(app, cpos,
|
|
|
struct ret_app_vec2,
|
|
|
app_calc_buffer_cam(app, dt));
|
|
|
- glUniform2f(app.uniforms.camera,
|
|
|
+ glUniform2f(tgr.uniforms.camera,
|
|
|
(float)cpos.x,
|
|
|
(float)cpos.y);
|
|
|
}
|
|
|
|
|
|
- glys.size = 0;
|
|
|
- glys = tile_glyph_da_calc_buffer(app, glys, vec2is(0));
|
|
|
- tile_glyph_da_sync(app, glys);
|
|
|
+ tgr.glyphs.size = 0;
|
|
|
+ tgr.glyphs = tile_glyph_da_calc_buffer(app, tgr.glyphs,
|
|
|
+ vec2is(0));
|
|
|
+ tile_glyph_da_sync(app, tgr.glyphs);
|
|
|
glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
0, 4,
|
|
|
- (int32_t) glys.size);
|
|
|
+ (int32_t) tgr.glyphs.size);
|
|
|
|
|
|
{
|
|
|
size_t col = 0;
|
|
|
@@ -153,21 +123,21 @@ main(int32_t argc, char **argv)
|
|
|
buffer_calc_cur_pos(app.buf));
|
|
|
|
|
|
const char *c = buf->data.items + buf->cur;
|
|
|
- glys.size = 0;
|
|
|
- glys = tile_glyph_da_calc(app, glys,
|
|
|
- ( *c == '\n' ) ? " " : c, 1,
|
|
|
- vec2i((int32_t)col,
|
|
|
- -(int32_t)row),
|
|
|
- vec4fs(0), vec4fs(1));
|
|
|
- tile_glyph_da_sync(app, glys);
|
|
|
+ tgr.glyphs.size = 0;
|
|
|
+ tgr.glyphs = tile_glyph_da_calc(app, tgr.glyphs,
|
|
|
+ ( *c == '\n' ) ? " " : c, 1,
|
|
|
+ vec2i((int32_t)col,
|
|
|
+ -(int32_t)row),
|
|
|
+ vec4fs(0), vec4fs(1));
|
|
|
+ tile_glyph_da_sync(app, tgr.glyphs);
|
|
|
glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
0, 4,
|
|
|
- (int32_t) glys.size);
|
|
|
+ (int32_t) tgr.glyphs.size);
|
|
|
}
|
|
|
|
|
|
SDL_GL_SwapWindow(app.win.ptr);
|
|
|
|
|
|
- glUniform1f(app.uniforms.time,
|
|
|
+ glUniform1f(tgr.uniforms.time,
|
|
|
(float) (SDL_GetTicks() / 1000));
|
|
|
|
|
|
fr_end = SDL_GetTicks();
|
|
|
@@ -181,20 +151,8 @@ main(int32_t argc, char **argv)
|
|
|
exit(EXIT_SUCCESS);
|
|
|
}
|
|
|
|
|
|
-int32_t
|
|
|
-get_uniform(uint32_t prog, const char *name)
|
|
|
-{
|
|
|
- int32_t uni = glGetUniformLocation(prog, name);
|
|
|
- if ( uni == -1 ) {
|
|
|
- fprintf(stderr, "Failed getting %s uniform location\n", name);
|
|
|
- exit(EXIT_FAILURE);
|
|
|
- }
|
|
|
- printf("Got %s -> %d\n", name, uni);
|
|
|
- return uni;
|
|
|
-}
|
|
|
-
|
|
|
struct app
|
|
|
-handle_events(struct app app)
|
|
|
+handle_events(struct app app, int32_t resolution_uniform)
|
|
|
{
|
|
|
SDL_Event e = {0};
|
|
|
bool done = false;
|
|
|
@@ -233,7 +191,7 @@ handle_events(struct app app)
|
|
|
} break;
|
|
|
case SDL_WINDOWEVENT: {
|
|
|
WINDOW_UP_SIZE(app.win);
|
|
|
- glUniform2f(app.uniforms.resolution,
|
|
|
+ glUniform2f(resolution_uniform,
|
|
|
(float) app.win.w,
|
|
|
(float) app.win.h);
|
|
|
glViewport(0, 0 ,app.win.w, app.win.h);
|