Skip to main content
gamedev.net
🔒 Locked

Multitexture + VA = Problem

Started by FDan 5 replies 650+ views
Original Post
FDan
FDan
Hey everyone, I tried to add multitexturing to my little engine.. with success. for testing, a rendered 2 quads with same textures, and added a lightmap to the second. this still works fine, but when i add a third texture to the second quad, the first quad seems to be "darker", as if its affected by the color of the 3 multitextures of the second quad. i think it has something to do with enabling and disabling my texcoord array, so i post my code:
void	cGPOpenGL::RenderFace(Ptr<cGPFace> p_pFace)
{
	glPushMatrix();

	if (!p_pFace->IsValid()) return;

	p_pFace->OnUpdate();

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(Vec3), &p_pFace->m_lVertices[0].x);		

	if( p_pFace->UseTextures() )
	{
		for(Int i=0; i<(Int)p_pFace->m_lTextures.size(); i++)
		{
			glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(2, GL_FLOAT, sizeof(Vec3), &p_pFace->m_lTextures[i]->m_lCoords[0].x);

			Texture()->Activate(p_pFace->m_lTextures[i]->m_nTexId, i);
		}

	}

	glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei)p_pFace->m_lVertices.size());

	for(Int i=0; i<(Int)p_pFace->m_lTextures.size(); i++)
	{
		glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		glDisable(GL_TEXTURE_2D);
	}

	glPopMatrix();
}
important to know: each "face" got 1 list with vertices and a vector with variable amount of lists with texcoords (depends on how many textures you want to use). "Texture()->Activate(..)" perfoms this (in fact, the texture manager passes the tex data to the renderer:
   
void	cGPOpenGL::ActivateTexture(UInt p_pTexData, Int p_nMulti)
{
	glActiveTextureARB(GL_TEXTURE0_ARB+p_nMulti);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, p_pTexData);
}
I hope someone of you can help me - FDan [edited by - FDan on January 2, 2004 11:24:05 PM] [edited by - FDan on January 2, 2004 11:25:06 PM]
JotDot
JotDot
Might you be missing a glActiveTextureARB(GL_TEXTURE0_ARB+i) just before the glDisable(GL_TEXTURE_2D) ?
FDan
FDan
no i already tried that...
FDan
FDan
well, i disable them not before i draw another face, i disable them after i had drawn the face with this (i think theres no real difference in that) ... you find this after glDrawArrays(..):



// loop through textures

for(Int i=0; i<(Int)p_pFace->m_lTextures.size(); i++)
{
// activate texture

glClientActiveTextureARB(GL_TEXTURE0_ARB+i);
// disable texture

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_TEXTURE_2D);
}
FDan
FDan
when i remove the glDisable(TEX2D) from my last post the texturs get even darker (i nearly cant see them now)
FDan
FDan
bah! this is strange, maybe someone can explain it to me... first: i got it! it works now... crazy: i don''t know why, i changed exactly one thing:

in the code above, when i loop through all textures to disable them after drawing, i changed this:


glDrawArrays(GL_TRIANGLE_FAN, 0, (GLsizei)p_pFace->m_lVertices.size());

for(Int i=0; i<(Int)p_pFace->m_lTextures.size(); i++)
{
DisableTexture(i);
}


DisableTexture is a method i used before, which looks like this (p_nMulti = which multitex to disable):

void cGPOpenGL::DisableTexture(Int p_nMulti)
{
glActiveTextureARB(GL_TEXTURE0_ARB+p_nMulti);
glDisable(GL_TEXTURE_2D);
}


maybe you notice, the function do the same like what i did before (without glDisableClientState(..) .. but with glDisableClientState(..) it works fine too.)

now, someone know why? id like to understand this, but it cant be when calling the same code in another function all this works...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.