Red background and gaps between tiles are still white. It seems that there is something wrong with texture coordinates.
This is my texture preloading from sprite sheet code:
private Tex preloadSymSprite(SpriteSheet source, float regX, float regY, float rect) {
regX--;
regY--;
bind=new Tex();
bind.ID = source.ID;
bind.width = (int) rect;
bind.height = (int) rect;
float height = source.height;
float width = source.width;
bind.minBindX=(regX*rect)/width;
bind.minBindY=(regY*rect)/height;
bind.maxBindX=((regX*rect)+rect)/width;
bind.maxBindY=((regY*rect)+rect)/height;
return bind;
}
Example execution:
private void roads() {
LT.road.upDown = preloadSymSprite(LT.road.roads, 1, 1, 20);
LT.road.leftRight = preloadSymSprite(LT.road.roads, 2, 1, 20);
LT.road.none = preloadSymSprite(LT.road.roads, 3, 1, 20);
LT.road.all = preloadSymSprite(LT.road.roads, 4, 1, 20);
LT.road.downRight = preloadSymSprite(LT.road.roads, 1, 2, 20);
LT.road.downLeft = preloadSymSprite(LT.road.roads, 2, 2, 20);
LT.road.upRight = preloadSymSprite(LT.road.roads, 1, 3, 20);
LT.road.upLeft = preloadSymSprite(LT.road.roads, 2, 3, 20);
LT.road.up = preloadSymSprite(LT.road.roads, 1, 4, 20);
LT.road.right = preloadSymSprite(LT.road.roads, 2, 4, 20);
LT.road.down = preloadSymSprite(LT.road.roads, 3, 4, 20);
LT.road.left = preloadSymSprite(LT.road.roads, 4, 4, 20);
LT.road.upDownLeft = preloadSymSprite(LT.road.roads, 4, 2, 20);
LT.road.downLeftRight = preloadSymSprite(LT.road.roads, 3, 2, 20);
LT.road.upDownRight = preloadSymSprite(LT.road.roads, 3, 3, 20);
LT.road.upLeftRight = preloadSymSprite(LT.road.roads, 4, 3, 20);
}
Can be something wrong in there? I checked sprite sheet .png, it seems that there is nothing wrong with it (everything is pixel perfect).
EDIT: It MUST be problem with texture coordinates. Debug drawing code below is perfect. Now question what is the cause of the problem…
public static void draw(Tex tex, float x, float y, float angle) {
glBindTexture(GL_TEXTURE_2D, tex.ID);
glPushMatrix();
glTranslatef(x, y, 0);
glRotated(angle/(Math.PI/180), 0, 0, 1);
glBegin(GL_QUADS);
glColor4f(1,1,1,1);
glTexCoord2f(tex.minBindX+0.0001f,tex.maxBindY-0.0001f); glVertex2f(-tex.width/2, -tex.height/2);
glTexCoord2f(tex.minBindX+0.0001f,tex.minBindY+0.0001f); glVertex2f(-tex.width/2, tex.height/2);
glTexCoord2f(tex.maxBindX-0.0001f,tex.minBindY+0.0001f); glVertex2f(tex.width/2, tex.height/2);
glTexCoord2f(tex.maxBindX-0.0001f,tex.maxBindY-0.0001f); glVertex2f(tex.width/2, -tex.height/2);
glEnd();
glPopMatrix();
}