draw strings

This commit is contained in:
Josh Holtrop 2018-01-23 16:20:26 -05:00
parent acd75c8cf0
commit c8325da7ed

View File

@ -60,6 +60,22 @@ bool init(void)
return true;
}
static void draw_string(int row)
{
static const char message[] = "Hello World! 0123456789_g*^#";
float color = row / 9.0;
text_shader->set_color(color, color, color, 1.0);
int x = 0;
int y = font.get_line_height() * row + font.get_baseline_offset();
for (size_t i = 0; i < sizeof(message) - 1; i++)
{
auto g = font.get_glyph(message[i]);
text_shader->set_position(x, y);
g->render();
x += g->get_advance();
}
}
void display(SDL_Window * window)
{
glClear(GL_COLOR_BUFFER_BIT);
@ -68,6 +84,12 @@ void display(SDL_Window * window)
rect_shader->use();
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
text_shader->use();
for (int i = 0; i < 10; i++)
{
draw_string(i);
}
SDL_GL_SwapWindow(window);
}
@ -126,7 +148,7 @@ int main(int argc, char *argv[])
return 2;
}
if (!font.load(argv[1], HEIGHT / 10))
if (!font.load(argv[1], HEIGHT / 10 * 7 / 10))
{
fprintf(stderr, "Error loading font from %s\n", argv[1]);
return 2;