Home » Community » Forums » OpenGL » Textures distortion
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 Textures distortion
Post New Topic  Post Reply 
Hello!

CONTEXT: I'm finishing writing in Cpp a text rendering library based on FreeType2 and OpenGL, and a little problem raised when I was revising the text alignment code.

PROBLEM: When the text is vertically or horizontally centered (or even worse, both), the textures get distorted. Please take a look at the alignment code below:
// Adjust horizontal alignment
if ( (hAlign != 0) && (coord[0] != coord[1]) ) {
  if ( hAlign == 1 ) {
    // Centered
    glTranslatef( (coord[1] - coord[0] - width) / 2.0f, 0.0f, 0.0f );	// PROBLEM HERE
  } else {
    // Right
    glTranslatef( coord[1] - coord[0] - width, 0.0f, 0.0f );
  }
}

// Adjust vertical alignment
if ( (vAlign != 0) && (coord[2] != coord[3]) ) {
  if ( vAlign == 1 ) {
    // Centered
    glTranslatef( 0.0f, (coord[3] - coord[2] - font.height) / 2.0f, 0.0f );  // PROBLEM HERE
  } else {
    // Top
    glTranslatef( 0.0f, coord[3] - coord[2] - font.height, 0.0f );
  }
}




CAUSES: As far as I can imagine, the problem is in the second argument passed to glTranslatef. For some reason I can't understand, when this value is not an integer (what is most of time), the textures get distorted. Converting the value to an integer (and converting again to float to avoid compiler warnings) everything seems to work fine (with some precision loss):

glTranslatef( 0.0f, (float)((int)((coord[3] - coord[2] - font.height) / 2.0f)), 0.0f ); // UGLY!!!

And these are the screenshots for the UNROUNDED and ROUNDED values.

QUESTION: Is this an OpenGL "feature" relating to non-integer coordinates? Can you tell me what is going on? Any kind of help is very welcome!

Thanks a lot!

[Edited by - MajinMusashi on September 27, 2005 11:07:47 PM]

 User Rating: 1055   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

The links to the images didn't work for me. - nvm They work now :S

Okay, perhaps it is because when you do not use an interger value, you are not getting as good a pixel to pixel match as normal, and bilinear filtering does it's thing resulting in the blurry dot on the 'i's in the images supplied, for example.

For the sake of experimentation, try scrolling some text 0.1 units at a time across the screen, using a key to increment, and note whether the 'it looks right' and 'whole number' properties are in phase.

 User Rating: 1075   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Have you tried setting the texture magnification+minification filters to GL_NEAREST?


 User Rating: 1031   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Halma
Have you tried setting the texture magnification+minification filters to GL_NEAREST?

Hehehe, I was faster than you, Halma! This morning (here in Brazil) I tried replacing GL_LINEAR with GL_NEAREST and everything worked fine. Thanks anyway!

 User Rating: 1055   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: