Jump to content
  • Advertisement
Sign in to follow this  
kordova

OpenGL Texture wrapping

This topic is 4520 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

I am having an issue when drawing my terrain texture. Specifically, around the entire border I seem to get a clear wrapping of the texture. I am generating a texture for a heightmap using an SDL_surface. I then convert that surface to an OpenGL texture with:
  int textureByteMode;
  if ( surface->format->BytesPerPixel == 3 ) {
    textureByteMode = GL_RGB;
  }
  else if ( surface->format->BytesPerPixel == 4 ) {
    textureByteMode = GL_RGBA;
  }
  else {
    return;
  }
  
  glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
  glGenTextures( 1, &_textureID );
  glBindTexture( GL_TEXTURE_2D, _textureID );
  
  glTexImage2D( GL_TEXTURE_2D, 0, textureByteMode, surface->w, surface->h,                 0, textureByteMode, GL_UNSIGNED_BYTE, surface->pixels );
  
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
  glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  
  glBindTexture( GL_TEXTURE_2D, 0 );



I then bind this texture and render it with the test code:
glBegin( GL_QUADS );
  glTexCoord2f( 0.0f, 0.0f );
  glVertex3f( 0.0f + xOff, 0.0f + yOff, 0.0f );
  
  glTexCoord2f( 0.0f, 1.0f );
  glVertex3f( 0.0f + xOff, size + yOff, 0.0f );
  
  glTexCoord2f( 1.0f, 1.0f );
  glVertex3f( size + xOff, size + yOff, 0.0f );
  
  glTexCoord2f( 1.0f, 0.0f );
  glVertex3f( size + xOff, 0.0f + yOff, 0.0f );
  
  glEnd( );



In my init code I use:
  glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_S, GL_CLAMP );
  glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_T, GL_CLAMP );



When I save out the SDL_Image using SDL_SaveBMP I get (converted to PNG): When I render it I get: I use the SDL_Surface -> Texture code on surfaces loaded by SDL_image so I do not think that would be the issue. Might it be the filtering? And if so, how might it be corrected?

Share this post


Link to post
Share on other sites
Advertisement
Use 'GL_CLAMP_TO_EDGE' instead of 'GL_CLAMP', that should solve the wrapping issue.

Share this post


Link to post
Share on other sites
Hmm, thanks.

I tried

glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

to no avail.

Share this post


Link to post
Share on other sites
You should be able to set the wrapping per texture, so instead of setting it in your init code move the calls to the texture creation (before the glBindTexture(GL_TEXTURE_2D, 0); call).

Share this post


Link to post
Share on other sites
Ok, what I needed was:

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );


Not the glTexEnvi calls I had been using.

Thanks again.

[Edited by - kordova on July 5, 2006 12:09:25 PM]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!