Skip to main content
gamedev.net
🔒 Locked

Texture wrapping

Started by kordova Jul 5, 2006 at 11:05 AM 3 replies 500+ views
Original Post
kordova
kordova
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?
nts
nts
Use 'GL_CLAMP_TO_EDGE' instead of 'GL_CLAMP', that should solve the wrapping issue.
kordova
kordova
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.
nts
nts
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).

kordova
kordova
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.