Original Post
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: I then bind this texture and render it with the test code: In my init code I use: 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?
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 );
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( );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_WRAP_T, GL_CLAMP );
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?