PDA

View Full Version : Problem using Multi-Texturing



tabor25
06-20-2002, 10:48 AM
Hello,

i am trying to add multi-texture-support to my 3d-engine. I get pointers to the required functions by using "wglGetProcAddress". The pointers i recieve are all valid. Every object will be rendered by the following method :

void C3DViewGL::RenderObjectFlat(C3DObject *pObject)
{
long faceCount, index, colInd = 0, texInd = 0;
const float *pVertList = pObject->GetVertList();
const float *pVertColList = pObject->GetVertColList();
const UINT *pFaceList = pObject->GetFaceList(faceCount);
const float *pFaceNormList = pObject->GetFaceNormList();
const float *pTexCoordList = NULL;
COLORMODE colMode = pObject->GetColorMode();
CTextureGL *pTexList = (CTextureGL *)pObject->GetTexList();

if (m_useTextures && pTexList)
{
if (pTexList)
{
if (m_multiTexturing)
{
//Multi-Texture-Support
long texID = GL_TEXTURE0_ARB;
for(int i=0; i<pObject->GetTexCount(); i++)
{
CTextureGL &pTexture = pTexList[i];
if (pTexture.GetTexCoords())
{
glActiveTextureARB(texID);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, pTexture.GetTexture());

texID++;
}
}
}
else
{
//Normal Texture-Support
glBindTexture(GL_TEXTURE_2D, pTexList->GetTexture());
pTexCoordList = pTexList->GetTexCoords();
}
}
}

//
glBegin(GL_TRIANGLES);
for (long j=0; j < faceCount; j+=3)
{
//set normal of triangle
glNormal3fv(pFaceNormList+j);

//render Vertex 1
index = pFaceList[j]*3;
if (m_useTextures && pTexList)
{
texInd = index - (index / 3);
if (m_multiTexturing)
{
long texID = GL_TEXTURE0_ARB;
for(int i=0; i<pObject->GetTexCount(); i++)
{
CTextureGL &pTexture = pTexList[i];
if (pTexture.GetTexCoords())
glMultiTexCoord2fvARB(texID, pTexture.GetTexCoords()+texInd);
texID++;
}
}
else
{
if (pTexCoordList)
glTexCoord2fv(pTexCoordList+texInd);
}
}
glVertex3fv(pVertList+index);


//render Vertex 2
index = pFaceList[j+1]*3;
if (m_useTextures && pTexList)
{
texInd = index - (index / 3);
if (m_multiTexturing)
{
long texID = GL_TEXTURE0_ARB;
for(int i=0; i<pObject->GetTexCount(); i++)
{
CTextureGL &pTexture = pTexList[i];
if (pTexture.GetTexCoords())
glMultiTexCoord2fvARB(texID, pTexture.GetTexCoords()+texInd);
texID++;
}
}
else
{
if (pTexCoordList)
glTexCoord2fv(pTexCoordList+texInd);
}
}
glVertex3fv(pVertList+index);


//render Vertex 3
index = pFaceList[j+2]*3;
if (m_useTextures && pTexList)
{
texInd = index - (index / 3);
if (m_multiTexturing)
{
long texID = GL_TEXTURE0_ARB;
for(int i=0; i<pObject->GetTexCount(); i++)
{
CTextureGL &pTexture = pTexList[i];
if (pTexture.GetTexCoords())
glMultiTexCoord2fvARB(texID, pTexture.GetTexCoords()+texInd);
texID++;
}
}
else
{
if (pTexCoordList)
glTexCoord2fv(pTexCoordList+texInd);
}
}
glVertex3fv(pVertList+index);
}
glEnd();
}

The problem is, that only the last of all textures of an object will be seen on the object. After loading the bmp-file-data, i use the following methods to create a texture :

/* Create and bind a texture object */
glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);

/* Set texture parameters */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, m_magFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_minFilter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrap);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrap);
glTexEnvi(GL_TEXTURE_2D, GL_TEXTURE_ENV_MODE, GL_MODULATE);

if (m_minFilter == GL_LINEAR &#0124; &#0124; m_minFilter == GL_NEAREST)
{
glTexImage2D(GL_TEXTURE_2D, 0, 3, pBitmap->sizeX, pBitmap->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
}
else
{
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, pBitmap->sizeX, pBitmap->sizeY, GL_RGB, GL_UNSIGNED_BYTE, pBitmap->data);
}

Maybe someone can help me or knows whats wrong with my code. Please help !!!

Best regards

tabor25

dorbie
06-21-2002, 02:13 AM
The texture environment is not part of the object. You need to specify this for each of the textures you intend to use. When you load the texture and create the object you are probably only setting the texenv for the first unit. The default should be modulate so it's still a bit mysterious but you at least need to fix this. Also the gltexenv target is GL_TEXTURE_ENV, not GL_TEXTURE_2D.

That's all you get with that code sample :-).