PDA

View Full Version : Lines at the end of a texture



Jeroenvo
05-03-2015, 05:11 AM
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.

1780

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 :)

Yandersen
05-03-2015, 07:47 AM
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)?

Jeroenvo
05-04-2015, 01:05 AM
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);

hidefromkgb
05-04-2015, 01:40 AM
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 won`t 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 don`t accidentally include neighboring images.

Jeroenvo
05-04-2015, 04:56 AM
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

1790

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.

hidefromkgb
05-04-2015, 05:10 AM
The changes have to be made here:

try
{
tex = TextureLoader.getTexture(fileType, in);
}

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.

Jeroenvo
05-04-2015, 05:39 AM
It's not working, i'm not using an engine just eclipse with JWLGL and Slick2D (its for a school project)

hidefromkgb
05-04-2015, 05:54 AM
It's not working
Hm, strange… OK, try this:

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


Jeroenvo
05-04-2015, 06:38 AM
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.

1791

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

Other example
1792
32x32 50x50 100x100 128x128

Yandersen
05-04-2015, 07:52 AM
Seems like the target implementation does not support non-POT textures? Nowadays?! :O

Jeroenvo
05-04-2015, 09:12 AM
Seems like the target implementation does not support non-POT textures? Nowadays?! :O

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