未命名.jpg 70.37K
19 downloadsNow ,I render text with FreeType and it goes well .
At last I got the RBGA data like this:
for(int h = 0;h < bitmap_height;h++)
{
for(int w = 0;w < bitmap_width; w++)
{
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 0] = buffer[bitmap_width * h + w] * color[0] / 256;
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 1] = buffer[bitmap_width * h + w] * color[1] / 256;
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 2] = buffer[bitmap_width * h + w] * color[2] / 256;
if( buffer[bitmap_width * h + w] == 0)
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 3] = 0;//if the gray data is zero set the alpha be zero
else
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 3] = 255;
}
}
paper_buffer save the RGBA data and buffer means the gray data in FT_Bitmap .
And I send the RGBA data to GPU as a texture.
And I code GLSL like this:
"void main()
{ gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = gl_ProjectionMatrix * gl_ModelViewMatrix * gl_Vertex;
}"
"uniform sampler2D normal_tex; uniform sampler2D text_tex;
void main()
{
vec4 text_color; vec4 normal_color;
normal_color = texture2D(normal_tex,gl_TexCoord[0].st);
text_color = texture2D(text_tex, gl_TexCoord[0].st);
if(text_color.w == 0) gl_FragColor = normal_color * 0.8 + text_color * 0.2;
else gl_FragColor = text_color * 0.8 + normal_color * 0.2;
}
so the result is the image above..seems not so smooth .
And I want to know how do you do when you do this thing?

Find content
Not Telling