blending and textures

hi !

i am currently programming a kind of class for fonts to use with opengl … i load the font from a tga file with alpha channel (rgba) … i “put” this image as textures on my polygon … of course i do some calc to get the s and t coords for every char … but it doesn’t matter yet …

… those areas of the fontmap that should be blended are red … (255,0,0) … and those areas have full transparency (through the alpha channel) …

for testing i took the whole fontmap and put it on the poly … i did it the following way:

// first create and init the texobject
      glGenTextures(1, &TexName);
      glBindTexture(GL_TEXTURE_2D, TexName);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);


  // enable blending
  // set blendingfunc
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
  // enable texturing

  // bind texture
  glBindTexture(GL_TEXTURE_2D, TexName);
  // draw a rectangle ( for testing with the whole font map ...
     glColor4d(1.0, 1.0, 1.0, 1.0);

     glTexCoord2d(0.0, 0.0);
     glVertex2d(x, y);

     glTexCoord2d(1.0, 0.0);
     glVertex2d(x+CX, y); 

     glTexCoord2d(1.0, 1.0);
     glVertex2d(x+CX, y+CY);

     glTexCoord2d(0.0, 1.0);
     glVertex2d(x, y+CY); 

as you see i have used the gl_replace environment for the texture … i have read that this means that opengl uses the colorvalue of the texture directly … and i have used gl_nearest for filtering

ok now one picture of the result:

it looks good … as you can see there isn’t any artifact ore something …

… but if i use gl_linear as texture filter the following was the result:

as you can see some parts of the red background are blended with the white font … i think the reason is that opengl first smoothes the texture (cause of the filter) and that he blends … so i understand that there are those red artifacts … but how to solve ? …

is there anybody that knows how i can blend textures correctly or how i can make it better … any better ideas or solutions … you can also tell me some general thinks about blending textures that have nothing to do with fonts or stuff …

thanks !!!

[This message has been edited by Sebbi (edited 12-01-2001).]

For your particular problem, look into enabling alpha test (glEnable(GL_ALPHA_TEST) and glAlphaFunc()) to discard fragments with an interpolated alpha value <1.0 (you could also go for something like 0.95 to get a slightly antialiased font). Also, to make the font look better at different sizes, try using mipmaps and GL_LINEAR_MIPMAP_LINEAR filtering.


although i had already tried alphatesting i thank you for your hint …

but alphatesting is not the solutuion … because glAlphaTest with GL_GEQUAL and a reference value of 0.95 or something like that causes just some few pixel to be drawn that means that just some few parts of the chars can be seen and the rest is black … alphatesting doesn’t have the desired effect …

but mipmaping for resizing is a good hint … thank you