Black lines at edges of textures

So when I draw textures I get black lines underneath and to the right. I’m using textures for images, since I can’t find any other way with OpenGL.

Here’s my OpenGL initialisation code, if anything looks wrong please say, I’m very new to this. If anyone has any ideas what else might cause it, that would be very helpful.
Thanks :slight_smile:

private void initGL() {
		try {
			Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
			Display.setTitle("User Interface");
			Display.create();
			Display.setVSyncEnabled(true);
		} catch (LWJGLException e) {
			e.printStackTrace();
			System.exit(0);
		}
		
		glEnable(GL_TEXTURE_2D);
		
		glClearColor(0, 0, 0, 0);
		/*
		// enable alpha blending
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		*/
		glViewport(0, 0, WIDTH, HEIGHT);
		glMatrixMode(GL_MODELVIEW);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
		glMatrixMode(GL_MODELVIEW);
	}

Well, you didn’t really specify what are you rendering and how, thus it’s almost impossible to tell what’s wrong with your code. The initialization code doesn’t really help here.

What do you mean by using textures for images? What else would you like to use? Are you rendering a simple full-screen quad with an image stored in a texture?

We need more information to be able to figure out what’s the problem.

This seems like a blending artifact.

Try changing the texture envelope and see if this solves the problem:


glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

The default mode (3rd parameter) is GL_MODULATE. GL_REPLACE should make sure you only use the texture’s colors.

Also, make sure that your texture image is correct (I’m assuming it is), but it could have slightly transparent and/or black pixels on the bottom and right edges.

If you are displaying only one polygon, then you probably do not have a problem with depth testing and z-ordering. But if you are rendering multiple, make sure you call glEnable(GL_DEPTH_TEST), and modify your glClear() function to something like this:

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

If you have a non-opaque texture, then you should render your geometry by z-value order: Farthest first, and nearest last.

Hope this helps!