1
\$\begingroup\$

I'm having problems with texturing in LWJGL. The texture is not being stretched to a quad. As you can see, the texture is not being sized to the quad, marked with pink border. The problem doesn't exist when using square quad and square texture. Scaling the texture to 960x320 px doesn't help The texture size is 96px width and 32px height.(1 tile is 32x32, this object is 3 by 1)

The problem

The code:

//rendering the textured quad. This method also renders everything else
public static void renderTile(Texture tex, int x, int y, int sizex, int sizey) {
    tex.bind();

    glBegin(GL_QUADS);
    glColor4f(1, 1, 1, 1);
    glTexCoord2f(0, 0);
    glVertex2f(x, y);

    glTexCoord2f(1, 0);
    glVertex2f(x + sizex, y);

    glTexCoord2f(1, 1);
    glVertex2f(x + sizex, y + sizey);

    glTexCoord2f(0, 1);
    glVertex2f(x, y + sizey);
    glEnd();
}

//opengl initialization code, called before any rendering
public static void initOGL(){
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, 800, 600, 0 , 1, -1);
    Log.info("Display W=" + Display.getWidth() + " H=" + Display.getHeight());
    glMatrixMode(GL_MODELVIEW);
    glEnable(GL_TEXTURE_2D);
    glEnable (GL_BLEND); 
    glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Yes!

I have figured it out. LWJGL texture files must have dimensions equal to powers of 2 (2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048 etc). Otherwise OpenGL will clamp them to nearest power.

\$\endgroup\$
1
  • \$\begingroup\$ Glad to see that you found a solution! Don't forget to mark it as accepted - it helps others who may run into the same or similar problems. \$\endgroup\$
    – Pikalek
    Commented Aug 30, 2018 at 21:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .