Multitexturing issues

This topic is 4619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I am trying to multitexture a lightmap and a base map. However when I try doing it , it gives me a black image. Seems like it just doesn't like to multitexture. However if I apply the lightmap seperately it does, it does light up fine. It also does the base map texturing correctly. However it fails to do it correctly when used together. The following code is what I am using to multitexture. Could anyone please point what I am doing wrong.
void CModel::Render()
{

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(vector3), (float *)&m_Vertices[0]);

glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer(GL_FLOAT, sizeof(vector3), (float *)&m_Normals);

glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnable(GL_TEXTURE_2D);

if(this->m_lightmapCoords.size() > 0)
{
glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexCoordPointer(2, GL_FLOAT, sizeof(vector2), (float *)&m_lightmapCoords[0]);
glEnable(GL_TEXTURE_2D);

glClientActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexCoordPointer(3, GL_FLOAT, sizeof(vector3), (float *)&m_TexCoords[0]);
glEnable(GL_TEXTURE_2D);
}
else
{
glTexCoordPointer(2, GL_FLOAT, sizeof(vector2), (float *)&m_TexCoords[0]);
}

for(int i = 0; i < m_Model.m_numGroups; i++)
{
Groups *g = &m_Model.pGroups;

std::string name = g->m_Materials.m_materialName;
MaterialInfo mat = CMaterialManager::GetInstance().GetMaterial(name);

glMaterialfv(GL_FRONT, GL_AMBIENT, (float *)&mat.m_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, (float *)&mat.m_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, (float *)&mat.m_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, (float *)&mat.m_shininess);

std::string texture = g->m_Materials.m_textureMapName;

if(this->m_lightmapCoords.size() > 0)
{
glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
CTextureManager::GetInstance().Bind(texture);

glClientActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
CTextureManager::GetInstance().Bind("lightmap.jpg");
}
else
{
CTextureManager::GetInstance().Bind(texture);
}

if(m_Model.isNormalRecalculated)
{
glNormalPointer(GL_FLOAT, sizeof(vector3), (float *)&m_NormalVBO[0]);
}

// render octree only if octrees are built else
// do  dumb rendering of the model on a material
// basis
if(g->m_pOctree != NULL)
{
g->m_pOctree->Render();
}
else
{
glDrawElements(GL_TRIANGLES, static_cast<GLsizei>(g->m_Faces.size()), GL_UNSIGNED_INT, &g->m_Faces[0]);
}
}

glClientActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);

glClientActiveTexture(GL_TEXTURE0);
glActiveTexture(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
}


Thanks

Share on other sites
I noticed for the lightmap you are using GL_REPLACE. When I used lightmaps, I used GL_MODULATE. I also placed the base texture on first and then the lightmap. I'm not sure if the order has alot to do with it, but you might try the things I mentioned to see if it changes the outcome. Good luck!

EDIT:

I also noticed this block of code:
if(this->m_lightmapCoords.size() > 0){	glClientActiveTexture(GL_TEXTURE0);	glActiveTexture(GL_TEXTURE0);	CTextureManager::GetInstance().Bind(texture);					glClientActiveTexture(GL_TEXTURE1);	glActiveTexture(GL_TEXTURE1);	CTextureManager::GetInstance().Bind("lightmap.jpg");}

The code before the above block uses texture0 for the lightmap and texture1 for the base texture. But in the above block, youre using texture0 for the base and texture1 for the lightmap... was this intentional? it might also be affecting your rendering process.

-DavidR-

Share on other sites
I modified it with basemap as texture0 and lightmap as texture1. I still get the same effect.

Share on other sites
Now I have got it working better - To illustrate the problem better I have taken some screenshots.

BaseMap

Lightmap

Combination of the two

Now the basemap + lightmap doesn't seem to be equal to what I get. I just seem to get a darker version of the basemap ? Plus places where its black, it doesn't seem to go black.

Any ideas ?

Thanks

Share on other sites
Did you try using GL_MODULATE?

cheers
sam

Share on other sites
Yes I tried GL_MODULATE. This is my current setup. Texture 0 is the basemap so I am using GL_REPLACE and texture1 is lightmap so its et to GL_MODULATE.

glClientActiveTexture(GL_TEXTURE0);glActiveTexture(GL_TEXTURE0);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);glTexCoordPointer(2, GL_FLOAT, sizeof(vector2), &this->m_TexCoords[0]);glEnable(GL_TEXTURE_2D);	glClientActiveTexture(GL_TEXTURE1);glActiveTexture(GL_TEXTURE1);glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);glTexCoordPointer(3, GL_FLOAT, sizeof(vector3), &this->m_lightmapCoords[0]);glEnable(GL_TEXTURE_2D);

Share on other sites
Did you enable GL_TEXTURE_COORD_ARRAY for the second texture unit as well? I don't see a call for that in any code you posted so far.

Share on other sites
Quote:
 Original post by ForfaoxDid you enable GL_TEXTURE_COORD_ARRAY for the second texture unit as well? I don't see a call for that in any code you posted so far.

Cool it works. I had enabled GL_TEXTURE_COORD_ARRAY globally only once when I was enabling all the arrays. I didn't know I had to enable for each texture unit. I guess it makes sense as I am using different texture coordinates for the base map and the lightmap.

Thanks.