// dot3 bump map
glActiveTextureARB (GL_TEXTURE0_ARB);
glBindTexture (GL_TEXTURE_2D, texture[polygon.texindex[1]]);
glEnable (GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
// base texture
glActiveTextureARB (GL_TEXTURE1_ARB);
glBindTexture (GL_TEXTURE_2D, texture[polygon.texindex[0]]);
glEnable (GL_TEXTURE_2D);
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_MODULATE);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvf (GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);
static float lpes[3]; // light position in eye space
static float lpos[3]; // light position in object space
static float lv[3]; // vector from vertex to light
static float lvts[3]; // light vector in tangent space
static float modelViewMatrix[16];
static float modelViewMatrixInverse[16];
glGetFloatv (GL_MODELVIEW_MATRIX, modelViewMatrix);
matrixInvert (modelViewMatrix, modelViewMatrixInverse);
lpes[0] = light[1].position[0];
lpes[1] = light[1].position[1];
lpes[2] = light[1].position[2];
vectorMultMatrix (lpes, modelViewMatrixInverse, lpos);
for (int i = 0; i < polygon.vertices; i++)
{
lv[0] = lpes[0] - polygonlist.vertlist[polygon.vertindex].x;
lv[1] = lpes[1] - polygonlist.vertlist[polygon.vertindex].y;
lv[2] = lpes[2] - polygonlist.vertlist[polygon.vertindex].z;
vectorNormalize (lv);
vectorMult3x3Matrix (lv, tangentMatrix, lvts);
lvts[0] = lvts[0] * 0.5f + 0.5f;
lvts[1] = lvts[1] * 0.5f + 0.5f;
lvts[2] = lvts[2] * 0.5f + 0.5f;
polygonlist.vertlist[polygon.vertindex].r = lvts[0];
polygonlist.vertlist[polygon.vertindex].g = lvts[1];
polygonlist.vertlist[polygon.vertindex].b = lvts[2];
int offset = sizeof (VERTEXDATA) * polygon.vertindex;
glUpdateObjectBufferATI (gluiVertexObject, offset, sizeof (VERTEXDATA), &polygonlist.vertlist[polygon.vertindex], GL_PRESERVE_ATI);
}
glDrawElements (GetDrawType (polygon.shape), polygon.vertices, GL_UNSIGNED_INT, polygon.vertindex);