Kevin Jensen Petersen
Kevin Jensen Petersen

Reputation: 513

Texture gets blackness and whitelines added to it

I've tried to add a Texture to my OpenGL Display. Rendering a texture like normal.

Getting the Texture:

try {
        mainTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(texturePath));
        width = mainTexture.getTextureWidth();
        height = mainTexture.getTextureHeight();
    } catch(IOException e) {
        e.printStackTrace();
    }

Rendering the Texture:

mainTexture.bind();
    glColor3f(1.0f,1.0f,1.0f);

    glBegin(GL_QUADS);
        glTexCoord2f(0,0);
        glVertex2f(x,y);
        glTexCoord2f(1,0);
        glVertex2f(x + width,y);
        glTexCoord2f(1,1);
        glVertex2f(x + width,y + height);
        glTexCoord2f(0,1);
        glVertex2f(x,y + height);
    glEnd();

Using this in Initilization code:

glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

This is the result of the code:

The Texture/Image is 50x50 pixels, which is inside the Blue box, but the Texture is getting rendered until the White lines, with Black just before the lines. Can't find the reason why it's doing it. It should ONLY render the 50x50 pixels, which is the width and height of the image/texture.

enter image description here

Upvotes: 0

Views: 88

Answers (1)

Christophe Roussy
Christophe Roussy

Reputation: 16999

I think there was some problem with images size/dimension not being a power of two... Read this: http://factor-language.blogspot.com/2009/04/opengl-textures-and-power-of-two-size.html

Upvotes: 1

Related Questions