|
|
@@ -90,6 +90,10 @@ static const struct glyph_attr glyph_attr[GLYPH_ATTR_TOTAL] = {
|
|
|
},
|
|
|
};
|
|
|
|
|
|
+struct glyphs _gl_render_text(struct app app, struct glyphs glys,
|
|
|
+ const char *cstr, size_t cstr_size,
|
|
|
+ struct vec2i tile,
|
|
|
+ struct vec4f fg_color, struct vec4f bg_color);
|
|
|
struct glyphs gl_render_text(struct app app, struct glyphs glys,
|
|
|
struct vec2i tile);
|
|
|
void glyphs_sync(struct app app, struct glyphs glys);
|
|
|
@@ -258,14 +262,10 @@ main(int32_t argc, char **argv)
|
|
|
/* vec2s(0), 0xFF00FFFF, 5); */
|
|
|
}
|
|
|
|
|
|
- glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
|
|
|
+ glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
- glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
- 0, 4,
|
|
|
- (int32_t) glys.size);
|
|
|
-
|
|
|
- /* glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); */
|
|
|
+ /* Calc Camera */
|
|
|
{
|
|
|
struct vec2 cur_pos = app_calc_cur_pos(app);
|
|
|
struct vec2 cpos = buf->cam.pos;
|
|
|
@@ -276,17 +276,40 @@ main(int32_t argc, char **argv)
|
|
|
buf->cam.vel = cvel;
|
|
|
glUniform2f(app.uniforms.camera,
|
|
|
(float)cpos.x,
|
|
|
- (float)-cpos.y);
|
|
|
+ (float)cpos.y);
|
|
|
}
|
|
|
|
|
|
- SDL_GL_SwapWindow(app.win.ptr);
|
|
|
- glUniform1f(app.uniforms.time,
|
|
|
- (float) (SDL_GetTicks() / 1000));
|
|
|
- /* cur = app_calc_cursor(app); */
|
|
|
- /* glUniform2i(app.uniforms.cursor, cur.x, cur.y); */
|
|
|
glys.size = 0;
|
|
|
glys = gl_render_text(app, glys, vec2is(0));
|
|
|
glyphs_sync(app, glys);
|
|
|
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
+ 0, 4,
|
|
|
+ (int32_t) glys.size);
|
|
|
+
|
|
|
+ {
|
|
|
+ size_t col = 0;
|
|
|
+ size_t row = 0;
|
|
|
+ RET_UNWRAP2(col, row,
|
|
|
+ struct ret_size_t_size_t,
|
|
|
+ buffer_calc_cur_pos(app.buf));
|
|
|
+
|
|
|
+ const char *c = buf->data.items + buf->cur;
|
|
|
+ glys.size = 0;
|
|
|
+ glys = _gl_render_text(app, glys,
|
|
|
+ ( *c == '\n' ) ? " " : c, 1,
|
|
|
+ vec2i((int32_t)col,
|
|
|
+ -(int32_t)row),
|
|
|
+ vec4fs(0), vec4fs(1));
|
|
|
+ glyphs_sync(app, glys);
|
|
|
+ glDrawArraysInstanced(GL_TRIANGLE_STRIP,
|
|
|
+ 0, 4,
|
|
|
+ (int32_t) glys.size);
|
|
|
+ }
|
|
|
+
|
|
|
+ SDL_GL_SwapWindow(app.win.ptr);
|
|
|
+
|
|
|
+ glUniform1f(app.uniforms.time,
|
|
|
+ (float) (SDL_GetTicks() / 1000));
|
|
|
|
|
|
fr_end = SDL_GetTicks();
|
|
|
fr_dur = (fr_end - fr_start);
|
|
|
@@ -300,12 +323,16 @@ main(int32_t argc, char **argv)
|
|
|
}
|
|
|
|
|
|
struct glyphs
|
|
|
-gl_render_text(struct app app, struct glyphs glys, struct vec2i tile)
|
|
|
+_gl_render_text(struct app app, struct glyphs glys,
|
|
|
+ const char *cstr, size_t cstr_size,
|
|
|
+ struct vec2i tile,
|
|
|
+ struct vec4f fg_color, struct vec4f bg_color)
|
|
|
{
|
|
|
+ (void) app;
|
|
|
struct vec2i pen = tile;
|
|
|
int32_t row = 0;
|
|
|
- for ( size_t i = 0; i < app.buf.data.size; ++i ) {
|
|
|
- char c = app.buf.data.items[i];
|
|
|
+ for ( size_t i = 0; i < cstr_size; ++i ) {
|
|
|
+ char c = cstr[i];
|
|
|
if ( c == '\n' ) {
|
|
|
pen.y -= 1;
|
|
|
row = 0;
|
|
|
@@ -314,8 +341,8 @@ gl_render_text(struct app app, struct glyphs glys, struct vec2i tile)
|
|
|
struct glyph gly = {
|
|
|
.tile = vec2i_add(pen, vec2i(row, 0)),
|
|
|
.c = c,
|
|
|
- .fg_color = vec4fs(1),
|
|
|
- .bg_color = vec4fs(0)
|
|
|
+ .fg_color = fg_color,
|
|
|
+ .bg_color = bg_color
|
|
|
};
|
|
|
DA_APPEND(glys, gly);
|
|
|
++row;
|
|
|
@@ -323,6 +350,14 @@ gl_render_text(struct app app, struct glyphs glys, struct vec2i tile)
|
|
|
return glys;
|
|
|
}
|
|
|
|
|
|
+struct glyphs
|
|
|
+gl_render_text(struct app app, struct glyphs glys, struct vec2i tile)
|
|
|
+{
|
|
|
+ return _gl_render_text(app, glys,
|
|
|
+ app.buf.data.items, app.buf.data.size,
|
|
|
+ tile, vec4fs(1), vec4fs(0));
|
|
|
+}
|
|
|
+
|
|
|
void
|
|
|
glyphs_sync(struct app app, struct glyphs glys)
|
|
|
{
|