Jump to content
  • Advertisement
Sign in to follow this  
CyanPrime

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

This topic is 2746 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 )
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

Share this post


Link to post
Share on other sites
Advertisement
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)

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?

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!