Jump to content
  • Advertisement
Sign in to follow this  
MajinMusashi

OpenGL Textures distortion

This topic is 4823 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!