   Freetype font rendering issues (texture artifacts)
  I've been having some problems rendering texts lately. I switched to FreeType2 and a hacked version of SDL_ttf's demo (glfont.c) I found here (by swinchen?). I chose this because it was clear enough for me and worked pretty well with some modifications. The problem is, this method doesn't always give a useful result. Here's what I mean:  #1 is my current output. The charaters !|(){}ij etc. aren't being handled quite right.#2 is the NeHe #43 output. (looks alright)#3 is the output of the modified glfont.c I was talking about (same problems)#4 is lazyfoo code that blits the output of TTF_RenderGlyph_Blended right onto the screen surface (beautiful).The problem I'm guessing is with narrow characters. They don't get processed right. I think NeHe #43 looks OK because the output from FT_Glyph_To_Bitmap gets "padded" before a texture is made whereas the code I'm using does no such thing. Sometimes the characters look stretched wide so I'm guessing this "filler data" is required here. Any ideas?PS: I'm pretty sure it's got nothing to do with magnification filters or something like that (GL_NEAREST/GL_LINEAR).   
  The problem actually lies in the hinting method FreeType2 uses by default when rendering the glyphs.  In FreeType1, a better method was used, but since it was patented by Apple, they removed it in FreeType2.  You can reenable it by recompiling the source code.  You need to find a source code file called "src.ftoption.h", or something along those lines, and modify a #define statement.  It will either be something that states to use the PATENTED version of hinting, or to use the UNPATENTED version.  In either case, you'll need to comment out or uncomment the #define statement.  It should be obvious when you open the source file.   ;  Thanks. I was looking into it but there doesn't seem to be a lot on this stuff. Maybe that's a little advanced for what I need right now.If you take a look at the pic, they all use FreeType2 but some look better than others. I'm looking for something along the lines of #2 and #4 without having to modify the library.This is the code I'm currently using that turns a glyph into an OpenGL texture:GLuint SDL_GL_LoadTexture(SDL_Surface *surface, GLfloat *texcoord){GLuint texture;int w, h;SDL_Surface *image;SDL_Rect area;Uint32 saved_flags;Uint8  saved_alpha;/* Use the surface width and height expanded to powers of 2 */w = power_of_two(surface->w);h = power_of_two(surface->h);texcoord[0] = 0.0f;/* Min X */texcoord[1] = 0.0f;/* Min Y */texcoord[2] = (GLfloat)surface->w / w;/* Max X */texcoord[3] = (GLfloat)surface->h / h;/* Max Y */image = SDL_CreateRGBSurface(SDL_SWSURFACE,w, h,32,#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000#else0xFF000000,0x00FF0000, 0x0000FF00, 0x000000FF#endif  );if ( image == NULL ) {return 0;}/* Save the alpha blending attributes */saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);saved_alpha = surface->format->alpha;if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {SDL_SetAlpha(surface, 0, 0);}/* Copy the surface into the GL texture image */area.x = 0;area.y = 0;area.w = surface->w;area.h = surface->h;SDL_BlitSurface(surface, &area, image, &area);/* Restore the alpha blending attributes */if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA ) {SDL_SetAlpha(surface, saved_flags, saved_alpha);}/* Create an OpenGL texture for the image */glGenTextures(1, &texture);glBindTexture(GL_TEXTURE_2D, texture);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,w, h,0,GL_RGBA,GL_UNSIGNED_BYTE,image->pixels);SDL_FreeSurface(image);return texture;}Seems to be the general approach.   ;  Okay, the problem is somewhat sorted:I changed the four vertices of the quad from this:left   = x + glyph->minx;   right  = x + glyph->maxx - g->minx;   top    = y - glyph->maxy;   bottom = y - glyph->miny;to this:left   = x;   right  = x + glyph->maxx - glyph->minx;   top    = y - glyph->maxy;   bottom = y - glyph->miny;with somex += glyph->advance + (glyph->maxx - glyph->minx)/2; //<without it the spacing isn't quite rightfor advancing. Bit hacky but will do for now, I guess. Anyone can suggest a better way?   