Sign in to follow this  
CyanPrime

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

Recommended Posts

CyanPrime    105
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
[code]
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);
}
[/code]

And my texture loading is:
[code]
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;
}
[/code]

This is what I'm talking about for white lines, by the way: http://i.imgur.com/GKztG.png

Share this post


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

[quote]
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)

Share this post


Link to post
Share on other sites
karwosts    840
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this