Lines at the end of a texture

Hello all,

I’m trying to make a simple 2d game and i’m new in openGL programming. Sometime when i try to draw an image i get black lines at the end of the texture.

[ATTACH=CONFIG]1780[/ATTACH]

I’m using lwjgl, this is the code that draws the textures:

public static void drawQuadTex(Texture tex, float x, float y, float width, float height)
{

	tex.bind();
	glTranslatef(x, y, 0);
	
	glBegin(GL_QUADS);
	
	glTexCoord2f(0, 0);
	glVertex2f(0, 0);
	
	glTexCoord2f(1, 0);
	glVertex2f(width, 0);
	
	glTexCoord2f(1, 1);
	glVertex2f(width, height);
	
	glTexCoord2f(0, 1);
	glVertex2f(0, height);
	
	glEnd();
	glLoadIdentity();
}

If you need more code, please ask so i can continue my game :slight_smile:

Check wrapping parameters (GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T) - maybe you see pixels from the opposite side of the image while you prefer edge clamping (GL_CLAMP_TO_EDGE)?

Where do i place that code, and what kind of methods should i use?

This is the code that makes the screen:

	Display.setTitle("2D Game");
	try 
	{
		Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
		Display.create();
		} 
		catch (LWJGLException e) 
	{
		e.printStackTrace();
	}
	
	glEnable(GL_TEXTURE_2D);
	glEnable(GL_BLEND);
	
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This is not the right place to insert texture wrapping =)
Where do you prepare your textures? Look there and insert

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

somewhere between binding and unbinding the texture in question.
In case you use other texture type than GL_TEXTURE_2D, you should replace GL_TEXTURE_2D with the right type in the invocations I posted. If the type is GL_TEXTURE_3D, you may also want to add GL_TEXTURE_WRAP_R which controls wrapping over depth axis.

It may happen so that wrapping wont help. For example, if you are using texture maps (textures where multiple images are stored edge-to-edge; [example of a texture map](https://www.opengl.org/discussion_boards/attachment.php?attachmentid=1787)) you might need to offset your texture coordinates so that they dont accidentally include neighboring images.

This is how i make the textures

First i use this method to get the texture

public static Texture loadTexture(String path, String fileType)
{
	Texture tex = null;
	InputStream in = ResourceLoader.getResourceAsStream(path);
	
	try 
	{
		tex = TextureLoader.getTexture(fileType, in);
	} 
	catch (IOException e)
	{
		System.err.println("Artist, loadTexture() error!");
	}
	
	
	return tex;
}

and then i use this method to draw it

public static void drawQuadTex(Texture tex, float x, float y, float width, float height)
{		
	
	tex.bind();
	
	glTranslatef(x, y, 0);
	
	glBegin(GL_QUADS);
	
	glTexCoord2f(0, 0);
	glVertex2f(0, 0);
	
	glTexCoord2f(1, 0);
	glVertex2f(width, 0);
	
	glTexCoord2f(1, 1);
	glVertex2f(width, height);
	
	glTexCoord2f(0, 1);
	glVertex2f(0, height);
	
	glEnd();
	glLoadIdentity();
	
}

When i make the transparent parts of the heart black, it’s clearly to see what openGL draws

[ATTACH=CONFIG]1048[/ATTACH]

When i print the texture.getWidth() * width and texture.getHeight * height than i get this awnser 37.265625 twice. The image width is 45px and height 53px.

The changes have to be made here:

[QUOTE=Jeroenvo;1266218]try
{
tex = TextureLoader.getTexture(fileType, in);
}[/QUOTE]

try {
    tex = TextureLoader.getTexture(fileType, in);
    tex.bind();
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    tex.unbind(); /// don`t know if such function exists; if not, just delete this line
}

However, the engine you`re using probably supports wrap mode changing via its own API.

It’s not working, i’m not using an engine just eclipse with JWLGL and Slick2D (its for a school project)

Hm, strange… OK, try this:

public static void drawQuadTex(Texture tex, float x, float y, float width, float height) {	
    tex.bind();
    tex.clampTexture();

…

The method clampTexture() doesn’t exist. But i think i found something. The game draws the tiles (64x64) normal. I changed the health images to a 32x32 and 50x50 white block. The 32x32 draws as it should but the 50x50 doesn’t fill its block. I’ve tried it and if a image size is not dividable by 8 than it doesn’t draw good.

[ATTACH=CONFIG]1049[/ATTACH]

I’ve tried to change glBegin(GL_QUADS) to glBegin(GL_POLYGON) but this doesn’t solve the problem.

Other example
[ATTACH=CONFIG]1050[/ATTACH]
32x32 50x50 100x100 128x128

Seems like the target implementation does not support non-POT textures? Nowadays?! :open_mouth:

Yes this is the problem. How do i implement it? Or should it work automatically?