Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


How do you blend the text image and the background?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 FireInDark   Members   -  Reputation: 148

Like
0Likes
Like

Posted 14 August 2012 - 09:05 PM

未命名.jpg

Now ,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?

Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS