Advertisement

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

Started by April 11, 2011 04:20 AM
5 comments, last by Hodgman 13 years, 7 months ago
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 )
glShadeModel(GL_FLAT);
glMatrixMode(GL_PROJECTION);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE , GL_ONE_MINUS_SRC_ALPHA);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

glLoadIdentity(); // Reset The Projection Matrix

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

glMatrixMode(GL_MODELVIEW);
}


And my texture loading is:

GLuint load_texture(const char* file)
{
SDL_Surface* surface = IMG_Load(file);
GLuint texture;
glPixelStorei(GL_UNPACK_ALIGNMENT,4);
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);
}
else
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 3,
surface->w, surface->h, GL_RGB, GL_UNSIGNED_BYTE, surface->pixels);
}
SDL_FreeSurface(surface);
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: http://i.imgur.com/GKztG.png
Have you tried setting texture clamping?


glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
[/quote]

(edited)
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Advertisement
'GL_TEXTURE_2D_ARRAY' was not declared in this scope
'GL_CLAMP_TO_EDGE' was not declared in this scope :(
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?

http://www.opengl.org/sdk/docs/man/xhtml/glTexParameter.xml

You can try GL_CLAMP, but I'm not sure if that will totally fix your problem.
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
How do you draw the tiles?
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. :(
Advertisement
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.

This topic is closed to new replies.

Advertisement