Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Lines at the end of a texture

  1. #1
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    6

    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.

    Attachment 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
    Attached Images Attached Images

  2. #2
    Senior Member Regular Contributor
    Join Date
    Dec 2010
    Location
    Oakville, ON, CA
    Posts
    165
    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)?

  3. #3
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    6
    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);

  4. #4
    Member Newbie
    Join Date
    May 2015
    Posts
    37
    This is not the right place to insert texture wrapping =)
    Where do you prepare your textures? Look there and insert
    Code :
    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) you might need to offset your texture coordinates so that they don`t accidentally include neighboring images.
    Attached Images Attached Images

  5. #5
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    6
    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

    HealthZwart.png

    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.

  6. #6
    Member Newbie
    Join Date
    May 2015
    Posts
    37
    The changes have to be made here:
    Quote Originally Posted by Jeroenvo View Post
    try
    {
    tex = TextureLoader.getTexture(fileType, in);
    }
    Code :
    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.

  7. #7
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    6
    It's not working, i'm not using an engine just eclipse with JWLGL and Slick2D (its for a school project)

  8. #8
    Member Newbie
    Join Date
    May 2015
    Posts
    37
    Quote Originally Posted by Jeroenvo View Post
    It's not working
    Hm, strange… OK, try this:
    Code :
    public static void drawQuadTex(Texture tex, float x, float y, float width, float height) {	
        tex.bind();
        tex.clampTexture();
     
    …

  9. #9
    Junior Member Newbie
    Join Date
    May 2015
    Posts
    6
    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.

    32 50 test.png

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

    Other example
    moar.png
    32x32 50x50 100x100 128x128

  10. #10
    Senior Member Regular Contributor
    Join Date
    Dec 2010
    Location
    Oakville, ON, CA
    Posts
    165
    Seems like the target implementation does not support non-POT textures? Nowadays?! :O

Page 1 of 2 12 LastLast

Similar Threads

  1. Drawing lines on top of a texture
    By Legento in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 01-11-2012, 04:46 PM
  2. Replies: 4
    Last Post: 07-08-2006, 04:14 AM
  3. glVertex*f lines not working over a 2D texture
    By acerb in forum OpenGL: Basic Coding
    Replies: 21
    Last Post: 03-14-2003, 12:35 AM
  4. Using 2x2 RGB texture creates red lines?
    By ToolChest in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 02-10-2003, 08:57 AM
  5. TEXTURE in LINES
    By JOSE ML in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 09-06-2002, 05:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean