draw strings
This commit is contained in:
parent
acd75c8cf0
commit
c8325da7ed
24
src/main.cc
24
src/main.cc
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user