Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


FireInDark

Member Since 11 Jul 2012
Offline Last Active Private

Topics I've Started

How do you blend the text image and the background?

14 August 2012 - 09:05 PM

Attached File  未命名.jpg   70.37KB   29 downloads

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?

About Multi-texture - glTexEnvi

10 August 2012 - 02:38 AM

Yes I render text with FreeType and it's goes well .

Attached File  未命名.jpg   38.08KB   19 downloads

Yes seems every thing all right..

But see here:
view.setFontColor(255,255,255,255);

Yes I do want to set the font_color be white,but it show me the black text..
It's quite sure that the color of the pixels rendered by FreeType are all right:
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;
paper_buffer[((pen_y + h) * paper_width + pen_x + w + char_advance)*4 + 3] = 255;
}
}

and when :

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);//first texture
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD); //text texture
view.setFontColor(255,255,255,255);
Attached File  未命名.jpg   36.75KB   24 downloads
seems well.
but then:
view.setFontColor(255,0,0,255);
Attached File  未命名.jpg   33.04KB   27 downloads

yes ,it's red but not pure red one..

then what I want to do is see the text color as what I set.

there must be the reason of glTexEnvi

Posted Image

I need to copy datas from a buffer to texture object

07 August 2012 - 04:18 AM

A FBO connect with a RenderTexture ,depth buffer,and other buffers..

Now I create a new Texture ,I want to copy the data from depth buffer to this texture.
Any way ?

About MRT

05 August 2012 - 10:43 PM

Think about that ,in case MRT,we have two render target (All are textures ): texture A and texture B.
Now the first element has been rendered ,texture A save the image and texture B save other datas..

then wen need to render another element ,but here , I need the datas in texture B to juge if the right pixel should be wirte or not..and the same time ,I also need to write texture B in some case when rendering the second element;

Any way ?

if i just bind the texture B as the GL_TEXTURE1 or GL_TEXTURE2 or somthing..

Question about GLEW.

01 August 2012 - 10:35 PM

I use GLEW on MS-Windows.
It's helpful and do many works ..
But ,till now,I can't find a way to init GLEW without creating a HGLRC and it also means I should create a window first..
Without the help of GLEW I can't use the the new functions newer than OpenGL 1.1 on MS-Windows such a glGenBuffers or others..
But I really don't want to create a window before I render to the FBOs,any way ?
May be we can find the functions from the driver's dll file of display card but I thinks it's not a right way to me..

PARTNERS