I am having some trouble with multitexturing a mesh with two textures (the first one is a 2D texture and the second is a 1D texture). While the first texture seems correctly applied, the coordinates of the second (the 1D texture) seems to be set arbitrary to 0 or 1 (a bit like instead of calling this function: glMultiTexCoord1fARB it was calling the integer version: glMultiTexCoord1iARB)
I have tried with rendering my mesh with one texture at a time (I just disable one of the texture) and it works fine in this case.
As I am new to multitexturing, I just put some of my code here (maybe the mistake come from here):
// Activate the cel-shader texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_1D);
glBindTexture(GL_TEXTURE_1D,shaderTexture[0]);
while(i<b)
{
// Get the current object that we are displaying
t3DObject *pObject = &g_3DModel.pObject[i];
// Check to see if this object has a texture map, if so bind the texture to it.
if(pObject->bHasTexture)
{
// Turn on texture mapping and turn off color
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
// Reset the color to normal again
glColor3ub(255, 255, 255);
// Bind the texture map to the object by it's materialID
glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
}
else
{
// Turn off texture mapping and turn on color
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
// Reset the color to normal again
glColor3ub(255, 255, 255);
}
glBegin(GL_TRIANGLES);//g_ViewMode); // Begin drawing with our selected mode (triangles or lines)
// Go through all of the faces (polygons) of the object and draw them
j ^= j;
while(j<pObject->numOfFaces)
{
// Go through each corner of the triangle and draw it.
whichVertex^=whichVertex;
while(whichVertex<3)
{
// Get the index for each point of the face
int index = pObject->pFaces[j].vertIndex[whichVertex];
// Use the normal for calculating the shade
TmpNormal.X = pObject->pNormals[ index ].x;
TmpNormal.Y = pObject->pNormals[ index ].y;
TmpNormal.Z = pObject->pNormals[ index ].z;
// Make sure the normals are rotated
RotateVector(TmpMatrix, TmpNormal, TmpVector);
// And normalized
Normalize(TmpVector);
// Get the percentage of light at that vector
TmpShade = DotProduct(TmpVector,lightAngle);
if (TmpShade < 0.0f) TmpShade = 0.0f; //cap off
// If the object has a texture associated with it, give it a texture coordinate.
if(pObject->bHasTexture)
{
// Make sure there was a UVW map applied to the object or else it won't have tex coords.
if(pObject->pTexVerts)
{
// Base Texture
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,pObject->pTexVerts[ index ].x, pObject->pTexVerts[ index ].y);
// Cell Texture
glMultiTexCoord1fARB(GL_TEXTURE1_ARB,TmpShade);
}
}
else
{
// Get and set the color that the object is, since it must not have a texture
BYTE *pColor = g_3DModel.pMaterials[pObject->materialID].color;
// Assign the current cell shade to this model
glMultiTexCoord1fARB(GL_TEXTURE1_ARB,TmpShade);
// Assign the material color
glColor3ub(pColor[0], pColor[1], pColor[2]);
}
// Pass in the current vertex of the object (Corner of current face)
glVertex3fv(&pObject->pVerts[ index ].x);//, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
whichVertex++;
}
j++;
}
glEnd(); // End the drawing
i++;
}
// Turn off all texturing
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_1D);
Hope this helps out. It is using the 3ds loader code from www.gametutorials.com and modified (to allow for textures and other colors) cel-shading tut from nehe.gamedev.net
edit: added code markers
[This message has been edited by chxfryer (edited 02-25-2003).]
[This message has been edited by chxfryer (edited 02-25-2003).]
without reseting the matrix like I should I have done like that
> glActiveTextureARB(GL_TEXTURE1_ARB);
> glDisable(GL_TEXTURE_2D);
> glMatrixMode(GL_TEXTURE);
> glLoadIdentity();
> glMatrixMode(GL_MODELVIEW);
and of course the coordinates of my second object were doing very weird things because
of that