text rendering woiks
This commit is contained in:
parent
8552d6a1df
commit
7fc02062c0
|
@ -74,7 +74,7 @@ void font_init(struct shader *textshader) {
|
||||||
.fs.source = slurp_text("shaders/textfrag.glsl"),
|
.fs.source = slurp_text("shaders/textfrag.glsl"),
|
||||||
.vs.uniform_blocks[0] = {
|
.vs.uniform_blocks[0] = {
|
||||||
.size = sizeof(float)*16,
|
.size = sizeof(float)*16,
|
||||||
.layout = SG_UNIFORMLAYOUT_STD140,
|
// .layout = SG_UNIFORMLAYOUT_STD140,
|
||||||
.uniforms = {
|
.uniforms = {
|
||||||
[0] = { .name = "projection", .type = SG_UNIFORMTYPE_MAT4 }
|
[0] = { .name = "projection", .type = SG_UNIFORMTYPE_MAT4 }
|
||||||
}
|
}
|
||||||
|
@ -99,12 +99,12 @@ void font_init(struct shader *textshader) {
|
||||||
[2].buffer_index = 1},
|
[2].buffer_index = 1},
|
||||||
.buffers[2].step_func = SG_VERTEXSTEP_PER_INSTANCE,
|
.buffers[2].step_func = SG_VERTEXSTEP_PER_INSTANCE,
|
||||||
},
|
},
|
||||||
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
// .primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||||
.label = "text pipeline"
|
.label = "text pipeline"
|
||||||
});
|
});
|
||||||
|
|
||||||
bind_text.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
bind_text.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||||
.size = sizeof(float)*16*40000,
|
.size = sizeof(float)*24*3*1024*1024,
|
||||||
.type = SG_BUFFERTYPE_VERTEXBUFFER,
|
.type = SG_BUFFERTYPE_VERTEXBUFFER,
|
||||||
.usage = SG_USAGE_STREAM,
|
.usage = SG_USAGE_STREAM,
|
||||||
.label = "text buffer"
|
.label = "text buffer"
|
||||||
|
@ -215,9 +215,7 @@ void text_flush()
|
||||||
sg_apply_bindings(&bind_text);
|
sg_apply_bindings(&bind_text);
|
||||||
sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(projection));
|
sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(projection));
|
||||||
|
|
||||||
YughWarn("Chars: %d", curchar);
|
sg_draw(0,6*curchar,1);
|
||||||
|
|
||||||
sg_draw(0,4*curchar,1);
|
|
||||||
curchar = 0;
|
curchar = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,14 +227,16 @@ void fill_charverts(float *verts, float cursor[2], float scale, struct Character
|
||||||
float xpos = cursor[0] + (c.Bearing[0]+offset[0]) * scale;
|
float xpos = cursor[0] + (c.Bearing[0]+offset[0]) * scale;
|
||||||
float ypos = cursor[1] - (c.Bearing[1]+offset[1]) * scale;
|
float ypos = cursor[1] - (c.Bearing[1]+offset[1]) * scale;
|
||||||
|
|
||||||
float v[16] = {
|
float v[24] = {
|
||||||
xpos, ypos, c.rect.s0, c.rect.t1,
|
xpos, ypos, c.rect.s0, c.rect.t1,
|
||||||
xpos+w, ypos, c.rect.s1, c.rect.t1,
|
xpos+w, ypos, c.rect.s1, c.rect.t1,
|
||||||
xpos, ypos + h, c.rect.s0, c.rect.t0,
|
xpos, ypos + h, c.rect.s0, c.rect.t0,
|
||||||
|
xpos, ypos + h, c.rect.s0, c.rect.t0,
|
||||||
|
xpos+w, ypos, c.rect.s1, c.rect.t1,
|
||||||
xpos + w, ypos + h, c.rect.s1, c.rect.t0
|
xpos + w, ypos + h, c.rect.s1, c.rect.t0
|
||||||
};
|
};
|
||||||
|
|
||||||
memcpy(verts, v, sizeof(float)*16);
|
memcpy(verts, v, sizeof(float)*24);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int drawcaret = 0;
|
static int drawcaret = 0;
|
||||||
|
@ -246,7 +246,7 @@ void sdrawCharacter(struct Character c, mfloat_t cursor[2], float scale, struct
|
||||||
float shadowcolor[3] = {0.f, 0.f, 0.f};
|
float shadowcolor[3] = {0.f, 0.f, 0.f};
|
||||||
float shadowcursor[2];
|
float shadowcursor[2];
|
||||||
|
|
||||||
float verts[16];
|
float verts[24];
|
||||||
float offset[2] = {-1, 1};
|
float offset[2] = {-1, 1};
|
||||||
|
|
||||||
fill_charverts(verts, cursor, scale, c, offset);
|
fill_charverts(verts, cursor, scale, c, offset);
|
||||||
|
|
|
@ -54,6 +54,8 @@ char objectName[200] = { '\0' }; // object name buffer
|
||||||
|
|
||||||
struct sprite *tsprite = NULL;
|
struct sprite *tsprite = NULL;
|
||||||
|
|
||||||
|
const char *donquixote;
|
||||||
|
|
||||||
void debug_draw_phys(int draw) {
|
void debug_draw_phys(int draw) {
|
||||||
debugDrawPhysics = draw;
|
debugDrawPhysics = draw;
|
||||||
}
|
}
|
||||||
|
@ -73,6 +75,8 @@ void openglInit()
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
donquixote = slurp_text("quixote.txt");
|
||||||
|
|
||||||
////// MAKE SHADERS
|
////// MAKE SHADERS
|
||||||
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
spriteShader = MakeShader("spritevert.glsl", "spritefrag.glsl");
|
||||||
wireframeShader = MakeShader("spritevert.glsl", "spritewireframefrag.glsl");
|
wireframeShader = MakeShader("spritevert.glsl", "spritewireframefrag.glsl");
|
||||||
|
@ -142,10 +146,10 @@ void openglRender(struct window *window)
|
||||||
// gui_draw_img("pill1.png", 200, 200);
|
// gui_draw_img("pill1.png", 200, 200);
|
||||||
float a[2] = {100,100};
|
float a[2] = {100,100};
|
||||||
float w[3] = {1.f,1.f,1.f};
|
float w[3] = {1.f,1.f,1.f};
|
||||||
renderText("TEST RENDER", a, 1.f, w, 0,-1);
|
// renderText("TEST RENDER", a, 1.f, w, 0,-1);
|
||||||
|
|
||||||
float b[2] = {50,50};
|
float b[2] = {50,50};
|
||||||
renderText("TEST 2 RENDER", b, 1.f, w, 0,-1);
|
// renderText(donquixote, b, 1.f, w, 0,-1);
|
||||||
|
|
||||||
/* UI Elements & Debug elements */
|
/* UI Elements & Debug elements */
|
||||||
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
// glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||||
|
|
|
@ -8,6 +8,7 @@ uniform sampler2D text;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
||||||
// color = vec4(fColor.xyz, texture(text, TexCoords).r);
|
// color = vec4(fColor.xyz, texture(text, TexCoords).r);
|
||||||
color = vec4(1.f,1.f,1.f, texture(text, TexCoords).r);
|
color = vec4(1.f,1.f,1.f, texture(text, TexCoords).r);
|
||||||
if (color.a <= 0.1f)
|
if (color.a <= 0.1f)
|
||||||
|
|
Loading…
Reference in a new issue