Image joglImage = null;
joglImage = (Image)image;
startPrimitive(Primitive.TEXTURED_TRIANGLE, joglImage);
TextureCoords coords = joglImage.texture.getImageTexCoords();
if(useColors) {
Color4f c;
for(int i = 0; i < triangles.length; i++) {
Triangle t = triangles[i];
if(t == null) continue;
Vector2f tc1 = t.getTextureCoordinate(0);
if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
Vector2f tc2 = t.getTextureCoordinate(1);
if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
Vector2f tc3 = t.getTextureCoordinate(2);
if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
p = t.getPoint(0);
c = t.getColor(0);
if(c == null) c = color;
gl.glColor4f(c.x, c.y, c.z, c.w);
float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
p = t.getPoint(1);
c = t.getColor(1);
if(c == null) c = color;
gl.glColor4f(c.x, c.y, c.z, c.w);
texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
p = t.getPoint(2);
c = t.getColor(2);
if(c == null) c = color;
gl.glColor4f(c.x, c.y, c.z, c.w);
texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
}
} else {
for(int i = 0; i < triangles.length; i++) {
Triangle t = triangles[i];
if(t == null) continue;
Vector2f tc1 = t.getTextureCoordinate(0);
if (tc1 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
Vector2f tc2 = t.getTextureCoordinate(1);
if (tc2 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
Vector2f tc3 = t.getTextureCoordinate(2);
if (tc3 == null) throw new IllegalArgumentException("Texture coordinate for triangle must not be null");
p = t.getPoint(0);
float texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc1.x;
float texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc1.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
p = t.getPoint(1);
texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc2.x;
texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc2.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
p = t.getPoint(2);
texX = coords.left() + (coords.right() - coords.left()) / joglImage.texture.getImageWidth() * tc3.x;
texY = coords.top() + (coords.bottom() - coords.top()) / joglImage.texture.getImageHeight() * tc3.y;
gl.glTexCoord2f(texX, texY);
gl.glVertex2f(p.x, p.y);
}
}