Search code examples
opengltexturestexture-mapping

Drawing adjacent texture mapped rectangles in OpenGL


I'm drawing a number of texture-mapped rectangles which are sat on top of each other using the following code:

glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex3f(x, y, 0);
glTexCoord2f(0.0, 0.0); glVertex3f(x, y + dy, 0);
glTexCoord2f(1.0, 0.0); glVertex3f(x + dx, y + dy, 0);
glTexCoord2f(1.0, 1.0); glVertex3f(x + dx, y, 0);
glEnd();

This renders correctly at full size, but when I resize it with glScale, single-pixel gaps appear in between some of the rectangles.

However, if I remove the texture map, the rectangles always abut each other correctly.

What's going wrong, and how can I fix this?


Solution

  • I'm an idiot. The images I was using actually had a transparent row of pixels along the top and bottom.

    The original "full-size" rendering was already resizing the texture, and it was a pure fluke that resizing artifacts caused the transparent rows not to be displayed in this case.

    Then when I resized the whole lot again with glScale some of the artifacts must have disappeared, and the transparent pixels appeared as gaps.