successfully draw a letter

This commit is contained in:
Josh Holtrop 2014-06-10 14:44:35 -04:00
parent afd3cb56f1
commit 9f08819dc1

View File

@ -14,6 +14,7 @@ static FT_Library ft;
static FT_Face face;
static GLProgram program;
static GLint uniform_tex;
static GLint uniform_color;
const char vertex_shader[] =
"#version 120\n"
@ -24,7 +25,7 @@ const char vertex_shader[] =
"\n"
"void main(void)\n"
"{\n"
" gl_Position = vec4(coord.xy, 0, 1);\n"
" gl_Position = vec4(coord.xy * 2.0 / 500.0, 0, 1);\n"
" tex_coord_i = coord.zw;\n"
"}\n";
@ -44,9 +45,12 @@ void init(void)
glClearColor (0.0, 0.0, 0.0, 0.0);
program.create(vertex_shader, fragment_shader,
"coord", 0, NULL,
"tex", NULL);
"tex", "color", NULL);
uniform_tex = program.uniform("tex");
uniform_color = program.uniform("color");
program.use();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void display(SDL_Window * window)
@ -56,7 +60,6 @@ void display(SDL_Window * window)
{
cerr << "Failed to load character" << endl;
}
#if 0
GLuint texture_id;
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texture_id);
@ -80,8 +83,17 @@ void display(SDL_Window * window)
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
GLfloat color[4] = {1, 0.6, 0, 1.0};
glUniform1i(uniform_tex, 0);
#endif
glUniform4fv(uniform_color, 1, color);
GLfloat box[4][4] = {
{0, 0, 0, 0},
{face->glyph->bitmap.width, 0, 1, 0},
{0, -face->glyph->bitmap.rows, 0, 1},
{face->glyph->bitmap.width, -face->glyph->bitmap.rows, 1, 1}
};
glBufferData(GL_ARRAY_BUFFER, sizeof(box), box, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
SDL_GL_SwapWindow(window);
}