void Render::drawPolygonTexture(const Vertex *vertices, int verticesCount, int primitive, const uint8_t *te
ata, int texW, int texH, int16_t texKey) {
assert(te
ata && texW > 0 && texH > 0);
assert(vertices && verticesCount >= 4);
glEnable(GL_TEXTURE_2D);
Texture *t = _textureCache.getCachedTexture(te
ata, texW, texH, texKey);
const GLfloat tx = t->u;
const GLfloat ty = t->v;
switch (primitive) {
case 0:
case 2:
{
//
// 1:::2
// : :
// 4:::3
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx1[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z
};
GLfloat tex1[] = {
0., 0.,
tx, 0.,
tx, ty,
0., ty
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx1);
glTexCoordPointer(2, GL_FLOAT, 0, tex1);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_QUADS);
glTexCoord2f(0., 0.);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(tx, 0.);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z);
glEnd();
#endif
break;
}
case 1:
{
//
// 1
// : :
// 3:::2
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx2[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z
};
GLfloat tex2[] = {
tx / 2, 0.,
tx, ty,
0., ty
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx2);
glTexCoordPointer(2, GL_FLOAT, 0, tex2);
glDrawArrays(GL_TRIANGLES,0,3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_TRIANGLES);
glTexCoord2f(tx / 2, 0.);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glEnd();
#endif
break;
}
case 3:
case 5:
{
//
// 4:::1
// : :
// 3:::2
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx3[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z
};
GLfloat tex3[] = {
tx, 0.,
tx, ty,
0., ty,
0., 0.
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx3);
glTexCoordPointer(2, GL_FLOAT, 0, tex3);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_QUADS);
glTexCoord2f(tx, 0.);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glTexCoord2f(0., 0.);
glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z);
glEnd();
#endif
break;
}
case 4:
{
//
// 3
// : :
// 2:::1
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx4[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z
};
GLfloat tex4[] = {
tx, ty,
0., ty,
tx / 2, 0.
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx4);
glTexCoordPointer(2, GL_FLOAT, 0, tex4);
glDrawArrays(GL_TRIANGLES,0,3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_TRIANGLES);
glTexCoord2f(tx, ty);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(tx / 2, 0.);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glEnd();
#endif
break;
}
case 6:
case 8:
{
//
// 3:::4
// : :
// 2:::1
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx5[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z
};
GLfloat tex5[] = {
tx, ty,
0., ty,
0., 0.,
tx, ty
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx5);
glTexCoordPointer(2, GL_FLOAT, 0, tex5);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_QUADS);
glTexCoord2f(tx, ty);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(0., 0.);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z);
glEnd();
#endif
break;
}
case 7:
{
//
// 2
// : :
// 1:::3
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx6[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z
};
GLfloat tex6[] = {
.0, ty,
tx / 2, 0.,
tx, ty
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx6);
glTexCoordPointer(2, GL_FLOAT, 0, tex6);
glDrawArrays(GL_TRIANGLES,0,3);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_TRIANGLES);
glTexCoord2f(.0, ty);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(tx / 2, 0.);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glEnd();
#endif
break;
}
case 9:
case 10:
{
//
// 2:::3
// : :
// 1:::4
//
glBindTexture(GL_TEXTURE_2D, t->id);
#ifdef PANDORA
GLfloat vtx7[] = {
vertices[0].x, vertices[0].y, vertices[0].z,
vertices[1].x, vertices[1].y, vertices[1].z,
vertices[2].x, vertices[2].y, vertices[2].z,
vertices[3].x, vertices[3].y, vertices[3].z
};
GLfloat tex7[] = {
0., 0.,
0., ty,
tx, ty,
tx, 0.
};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vtx7);
glTexCoordPointer(2, GL_FLOAT, 0, tex7);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
#else
glBegin(GL_QUADS);
glTexCoord2f(0., 0.);
glVertex3f(vertices[0].x, vertices[0].y, vertices[0].z);
glTexCoord2f(0., ty);
glVertex3f(vertices[1].x, vertices[1].y, vertices[1].z);
glTexCoord2f(tx, ty);
glVertex3f(vertices[2].x, vertices[2].y, vertices[2].z);
glTexCoord2f(tx, 0.);
glVertex3f(vertices[3].x, vertices[3].y, vertices[3].z);
glEnd();
#endif
break;
}
default:
warning("Render::drawPolygonFlat() unhandled primitive %d", primitive);
break;
}
glDisable(GL_TEXTURE_2D);
}