Hi, EDIT: "The problem is i don't see anything, just black, and when i disable the combiner and use just glColor i see just a grey box."
I can't get my hands on the error in my code, after days of research i gave up and decided to seek your help guys so PLEASE don't disappoint me :
this is the main code:
glTranslatef(0.0f, 0.0f, z);
glRotatef(xrot, 1.0f, 0.0f, 0.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
// The Normal Map
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, normalMap);
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);
// The Base Texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glBindTexture(GL_TEXTURE_2D, decalTexture);
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);
Vector LightPosition = Vector(3.0f, 3.0f, 3.0f);
Matrix InverseModelMatrix;
glPushMatrix();
glLoadIdentity();
glRotatef(-xrot, 1.0f, 0.0f, 0.0f);
glRotatef(-yrot, 0.0f, 1.0f, 0.0f);
glGetFloatv(GL_MODELVIEW_MATRIX, InverseModelMatrix.matrix);
glPopMatrix();
GLfloat position[24][3] = {cube vertex coordinates}
GLfloat texcoords[24][2] = {cube texture coordinates}
GLfloat normals[6][3] = {normals for each face}
glBegin(GL_QUADS);
for(unsigned int i=0; i<6; i++)
{
int j = i * 4;
glNormal3f(normals[0], normals[1], normals[2]);
LightVector = LightPosition - Vector(position[j+0]);
LightVector.Normal();
VecXMat4x4(LightVector, InverseModelMatrix, ObjectLightVector);
ObjectLightVector.Normal();
CalculateTangentMatrix(Vector(position[j+0]), Vector(position[j+1]), Vector(position[j+2]), TexCoord(texcoords[j+0]),
TexCoord(texcoords[j+1]), TexCoord(texcoords[j+2]), TangentMatrix);
VecXMat3x3(ObjectLightVector, TangentMatrix, TangentLightVector);
lp[0] = TangentLightVector.x * 0.5f + 0.5f;
lp[1] = TangentLightVector.y * 0.5f + 0.5f;
lp[2] = TangentLightVector.z * 0.5f + 0.5f;
glColor3fv(lp);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texcoords[j+0][0], texcoords[j+0][1]);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, texcoords[j+0][0], texcoords[j+0][1]);
glVertex3f(position[j+0][0], position[j+0][1], position[j+0][2]);
}
glEnd();
There's also three copies of the previous code (with j=j+1) to draw a cube
and this is the relevant parts:
void CalculateTangentMatrix(Vector PointA, Vector PointB, Vector PointC,
TexCoord ATex, TexCoord BTex, TexCoord CTex, Matrix TangentMatrix)
{
// Get the vector between point A and point B.
Vector VectorAB = PointB - PointA;
// Get the vector between point A and point C.
Vector VectorAC = PointC - PointA;
Vector Normal;
Normal.CrossProduct(VectorAB, VectorAC);
Normal.Normal();
// Compute the components of the vectors to the vertex normal of the first point.
Vector ProjAB = VectorAB - (Normal * Normal.DotProduct(VectorAB));
Vector ProjAC = VectorAC - (Normal * Normal.DotProduct(VectorAC));
3 and 1.
float TexCoord_S_AB = BTex.s - ATex.s;
float TexCoord_S_AC = CTex.s - ATex.s;
point 3 and 1.
float TexCoord_T_AB = BTex.t - ATex.t;
float TexCoord_T_AC = CTex.t - ATex.t;
if((TexCoord_S_AC * TexCoord_T_AB) > (TexCoord_S_AB * TexCoord_T_AC))
{
TexCoord_S_AC = -TexCoord_S_AC;
TexCoord_S_AB = -TexCoord_S_AB;
}
Vector Tangent = (ProjAB * TexCoord_S_AC) - (ProjAC * TexCoord_S_AB);
Tangent.Normal();
Vector Binormal;
Binormal.CrossProduct(Tangent, Normal);
Binormal.Normal();
TangentMatrix.matrix[0] = Tangent.x;
TangentMatrix.matrix[1] = Tangent.y;
TangentMatrix.matrix[2] = Tangent.z;
TangentMatrix.matrix[4] = Binormal.x;
TangentMatrix.matrix[5] = Binormal.y;
TangentMatrix.matrix[6] = Binormal.z;
TangentMatrix.matrix[8] = Normal.x;
TangentMatrix.matrix[9] = Normal.y;
TangentMatrix.matrix[10]= Normal.z;
}
void VecXMat4x4(Vector sourceV, Matrix m, Vector resultV)
{
resultV.x = ((sourceV.x)*(m.matrix[0])) + ((sourceV.y)*(m.matrix[4])) + ((sourceV.z)*(m.matrix[8])) + m.matrix[12];
resultV.y = ((sourceV.x)*(m.matrix[1])) + ((sourceV.y)*(m.matrix[5])) + ((sourceV.z)*(m.matrix[9])) + m.matrix[13];
resultV.z = ((sourceV.x)*(m.matrix[2])) + ((sourceV.y)*(m.matrix[6])) + ((sourceV.z)*(m.matrix[10])) + m.matrix[14];
}
void VecXMat3x3(Vector sourceV, Matrix m, Vector resultV)
{
resultV.x = ((sourceV.x)*(m.matrix[0])) + ((sourceV.y)*(m.matrix[4])) + ((sourceV.z)*(m.matrix[8]));
resultV.y = ((sourceV.x)*(m.matrix[1])) + ((sourceV.y)*(m.matrix[5])) + ((sourceV.z)*(m.matrix[9]));
resultV.z = ((sourceV.x)*(m.matrix[2])) + ((sourceV.y)*(m.matrix[6])) + ((sourceV.z)*(m.matrix[10]));
}
[Edited by - L0rdDiabl0 on August 19, 2004 1:58:53 AM]