When running my game in opengl, I have a texture that's mostly transparent and is mapped to a quad with alpha testing, and when jumping in game, a small black line flashs visibility on the top edge of the texture. Anyone know what the issue could be? The black line is definitely not in the image and it only flashs up when changing y coordinates.
using orthographic if that helps
[SOLVED]Opengl small black line on the edge of a texture
Moderator: Coders of Rage
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
[SOLVED]Opengl small black line on the edge of a texture
Last edited by like80ninjas on Sun Apr 10, 2011 9:29 pm, edited 1 time in total.
Re: Opengl small black line on the edge of a texture
Without a screen-shot it could be anything. My guess is it's frame bleeding, are you animating something with multiple frames from the same image? Because when using the GL_LINEAR texture filter frames can leak into each other.
Just a guess though, could be anything without a screen-shot or some code.
Just a guess though, could be anything without a screen-shot or some code.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Opengl small black line on the edge of a texture
I don't even have animation in yet, but I am using GL_LINEAR, should I not?
SETUP
TEXTURE LOADING
SETUP
Code: Select all
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 32);
SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
SDL_Surface* screen = SDL_SetVideoMode( width, height, 32, SDL_OPENGL );
glViewport( 0, 0, width, height );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glOrtho(0.0f, width*1.5, height*1.5, 0.0f, -100.0f, 100.0f);
glMatrixMode( GL_MODELVIEW );
glEnable(GL_ALPHA_TEST);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glAlphaFunc(GL_GREATER, 0.1f);
glClearColor(0.0f, 0.4f, 0.3f, 0.0f);
glClearDepth(1.0f);
glDepthMask(GL_TRUE);
glDepthFunc(GL_LEQUAL);
Code: Select all
//Return the optimized image
texture_image[current_image] = loadedImage;
// Have OpenGL generate a texture object handle for us
glGenTextures( 1, &texture[current_image] );
// Bind the texture object
glBindTexture( GL_TEXTURE_2D, texture[current_image] );
// Set the texture's stretching properties
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
// Edit the texture object's image data using the information SDL_Surface gives us
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, loadedImage->w, loadedImage->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, loadedImage->pixels );
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Opengl small black line on the edge of a texture
Try using point sampling (GL_NEAREST). The interpolation can cause problems on edges when minifying or magnifying.
Re: Opengl small black line on the edge of a texture
I'm not too familiar with the way you've set up your blending. If your image has transparency or a color key then I guess that might have something to do with it. Although I doubt it.
Also I see at one point you return a optimized image, that's clearly not a function so what is it?
And one more thing, what's the array?
Maybe it's just me but I'm a little confused by your code but try out what qp said and try point sampling.
Also I see at one point you return a optimized image, that's clearly not a function so what is it?
And one more thing, what's the array?
Maybe it's just me but I'm a little confused by your code but try out what qp said and try point sampling.
-
- Chaos Rift Regular
- Posts: 101
- Joined: Thu Dec 09, 2010 2:13 am
Re: Opengl small black line on the edge of a texture
QP's suggesting worked flawlessly, thanks! SOLVED
- ibly31
- Chaos Rift Junior
- Posts: 312
- Joined: Thu Feb 19, 2009 8:47 pm
- Current Project: Like... seven different ones
- Favorite Gaming Platforms: Xbox 360, Gamecube
- Programming Language of Choice: C++, ObjC
- Location: New Jersey.
Re: Opengl small black line on the edge of a texture
Yes! Finally someone found a solution. I always seem to have this bug in the tests but never in the final version, so I never really tried too hard to figure out what was wrong. Thanks!
Website/Tumblr
My Projects
The best thing about UDP jokes is that I don’t care if you get them or not.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Opengl small black line on the edge of a texture
The reason this happens is because you are using an alpha TEST as opposed to an alpha BLEND.
When you have a source image that's lest say 256x256, and it's to be sampled across a polygon that stretches 512x512 real pixels (magnification). With linear sampling it means that you have 1 pixel to be sampled for a 2x2 set. The color values are not simply "invented" for the pixels around the centroid of the sample...they're linearly interpolated in the case of linear sampling. So if you had a 2x2 texture and a 6x6 destination sample, you have one pixel of source for 9 pixels of destination. The center pixel of the destination is directly sampled and the remaining pixels are interpolated across the value that is known. So if you're going from 0 alpha to 1 alpha, then you have a line on the edges that are interpolated between 0 and 1 (Around 0.5). In an alpha TEST...these pixels are just completely rejected. So you get this hard black line.
With proper alpha blending, you'd get a blending across the pixels into the backbuffer. So you would not see the effects of the linear upsampling, which is why point sampling works. It simply takes the value of the source pixel and splats it across the 3x3 destination range. With alpha blending regardless of texture filtering, it would simply appear as a nice smooth transition between pixel boundaries. So in this case, I'd suggest alpha blending as opposed to alpha testing.
When you have a source image that's lest say 256x256, and it's to be sampled across a polygon that stretches 512x512 real pixels (magnification). With linear sampling it means that you have 1 pixel to be sampled for a 2x2 set. The color values are not simply "invented" for the pixels around the centroid of the sample...they're linearly interpolated in the case of linear sampling. So if you had a 2x2 texture and a 6x6 destination sample, you have one pixel of source for 9 pixels of destination. The center pixel of the destination is directly sampled and the remaining pixels are interpolated across the value that is known. So if you're going from 0 alpha to 1 alpha, then you have a line on the edges that are interpolated between 0 and 1 (Around 0.5). In an alpha TEST...these pixels are just completely rejected. So you get this hard black line.
With proper alpha blending, you'd get a blending across the pixels into the backbuffer. So you would not see the effects of the linear upsampling, which is why point sampling works. It simply takes the value of the source pixel and splats it across the 3x3 destination range. With alpha blending regardless of texture filtering, it would simply appear as a nice smooth transition between pixel boundaries. So in this case, I'd suggest alpha blending as opposed to alpha testing.