PDA

View Full Version : prob texture coordinates when multitexturing



kissi
02-25-2003, 10:01 AM
Hi,

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):

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1_id);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_1D);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glBindTexture(GL_TEXTURE_1D, shader_id);

//
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, texture1_coord_u, texture1_coord_v);
glMultiTexCoord1fARB(GL_TEXTURE1_ARB, shade_coord);

glBegin(GL_TRIANGLES)
glVertex3f(vertex.x, vertex.y, vertex.z);
glEnd();
//

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_1D);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

do you see anything incorrect?
anyone who also had problem with texture coordinates?

I hope you will understand my problem and I hope that my english is not too rubbish

kissi

chxfryer
02-25-2003, 04:57 PM
thats weird. I just (as in an hour ago) did this same thing for cel-shading.

my code looks like that but I dont use
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
and it works find




void buildcar(void)
{
// car=glGenLists(1);
// glNewList(car,GL_COMPILE);

int i = 0;
int j = 0;
int whichVertex = 0;

float TmpShade;

MATRIX TmpMatrix;
VECTOR TmpVector, TmpNormal;

// Set The Blend Mode ( NEW )


glHint(GL_LINE_SMOOTH_HINT,GL_NICEST);
glEnable(GL_LINE_SMOOTH);

glGetFloatv(GL_MODELVIEW_MATRIX,TmpMatrix.Data);

int b = g_3DModel.numOfObjects;

// 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 = &amp;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(&amp;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 (http://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).]

kissi
02-26-2003, 12:22 PM
oups sorry,
I have just found my mistake
just have two objects in my scene that was using multitexturing
with the first one I was doing sthg like this

> glActiveTextureARB(GL_TEXTURE1_ARB);
> glEnable(GL_TEXTURE_2D);
> glBindTexture(GL_TEXTURE_2D, _text2->get_id());
> glMatrixMode(GL_TEXTURE);
> glLoadIdentity();
> glScalef(50.0f, 50.0f, 1.0f);
> glMatrixMode(GL_MODELVIEW);

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

but thanks for your hep chxfryer