Advertisement Jump to content
Sign in to follow this  

Get my textures to stop "bleeding" in sdl/openGL?

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

Alright, so I'm moving my engine to openGL and When I try to draw the tilemap there are white lines through it, so I wanna know how to get rid of them (hopefully without doing the +/- 0.5 of a pixel thing).

This is my initGL

void InitGL(int Width, int Height) // We call this right after our OpenGL window is created.
glOrtho(0, 640, 0, 480, 0.0f, 100.0f);
glViewport(0, 0, Width, Height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // This Will Clear The Background Color To Black
glClearDepth(1.0); // Enables Clearing Of The Depth Buffer
glDepthFunc(GL_LESS); // The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
//glShadeModel(GL_SMOOTH); // Enables Smooth Color Shading
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )

glLoadIdentity(); // Reset The Projection Matrix

gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f); // Calculate The Aspect Ratio Of The Window


And my texture loading is:

GLuint load_texture(const char* file)
SDL_Surface* surface = IMG_Load(file);
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
SDL_PixelFormat *format = surface->format;
if (format->Amask)
gluBuild2DMipmaps(GL_TEXTURE_2D, 4,
surface->w, surface->h, GL_RGBA,GL_UNSIGNED_BYTE, surface->pixels);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3,
surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); // Linear Filtering
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); // Linear Filtering

return texture;

This is what I'm talking about for white lines, by the way:

Share this post

Link to post
Share on other sites
Have you tried setting texture clamping?



Share this post

Link to post
Share on other sites
oh sorry, I just copied that from somewhere, should be GL_TEXTURE_2D, not 2D_ARRAY.

Not sure why CLAMP_TO_EDGE is not supported, its in the spec for glTexParameter. Are you using OpenGL or some OpenGLES version?

You can try GL_CLAMP, but I'm not sure if that will totally fix your problem.

Share this post

Link to post
Share on other sites
clamp to edge didn''t help, so I gave up and did the -/+ 0.05px thing :( It works, but I don't like having hacks in my programs. :(

Share this post

Link to post
Share on other sites
What is "the -/+ 0.05px thing"? Sounds like you've just got a slight rounding error in your drawing code that you're covering up there.

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!