Hello,
I’ve tried to update
http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01
to use 3.3 shaders. Can someone tell me if I translated them correctly?
old vert:
#version 120
attribute vec4 coord;
varying vec2 texcoord;
void main(void) {
gl_Position = vec4(coord.xy, 0, 1);
texcoord = coord.zw;
}
new vert:
#version 330 core
in vec4 coord;
out vec2 texcoord;
void main()
{
gl_Position = vec4(coord.xy, 0, 1);
texcoord=coord.zw;
}
old frag:
#version 120
varying vec2 texcoord;
uniform sampler2D tex;
uniform vec4 color;
void main(void) {
gl_FragColor = vec4(1, 1, 1, texture2D(tex, texcoord).a) * color;
}
new frag:
#version 330 core
in vec2 texcoord;
out vec4 color;
uniform sampler2D tex;
uniform vec4 c;
void main()
{
color = vec4(1, 1, 1, texture2D(tex, texcoord).a) * c;
}
Nothing is appearing for some reason the glyphs are transparent I’ve even tried hardcoding the color to vec4(1,1,1,1) and they show up black.
Here is the render text function updated to use GL_RGBA for format since apparently GL_ALPHA is deprecated ( note that
glGenBuffers(1, &vbo);
and
glGenTextures(1, &tex);
were done earlier in the
program so you don’t see them here.
void render_text(const char *text, float x, float y, float sx, float sy) {
{
FT_Set_Pixel_Sizes(face, 0, 48);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUniform1i(uniform_tex, 0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, (void*)0);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ZERO);
const char *p;
for(p = text; *p; p++) {
if(FT_Load_Char(face, *p, FT_LOAD_RENDER))
continue;
glTexImage2D(
GL_TEXTURE_2D,
0,
GL_RGBA, //GL_ALPHA
g->bitmap.width,
g->bitmap.rows,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
g->bitmap.buffer
);
float x2 = x + g->bitmap_left * sx;
float y2 = -y - g->bitmap_top * sy;
float w = g->bitmap.width * sx;
float h = g->bitmap.rows * sy;
GLfloat box[4][4] = {
{x2, -y2 , 0, 0},
{x2 + w, -y2 , 1, 0},
{x2, -y2 - h, 0, 1},
{x2 + w, -y2 - h, 1, 1},
};
glBufferData(GL_ARRAY_BUFFER, sizeof box, box, GL_DYNAMIC_DRAW);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
x += (g->advance.x >> 6) * sx;
y += (g->advance.y >> 6) * sy;
}
glDisable(GL_BLEND);
}
Any ideas on this?