Archived

This topic is now archived and is closed to further replies.

Texture mapping probs

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m still working on my lightmap implementation and there is one more problem. For testing the lightmaps I disable the texture stage 0 (normal textures) and only activate the texture 1 (lightmap). The created lightmap looks really cool: for example: http://www.husser.de/lightmap.jpg The uv coords for the tris look ok, too: for example the uv-coords from one tri (3 points): (0.000000, 1.000000) (1.000000, 1.000000) (1.000000, 0.000000) But when I map the textures with those uv-coords to the tris, I get something like this: http://www.husser.de/sceen.jpg What could be the problem? Do I have to do some settings for the second texture stage to work correctly? The uv-coords are stored in a VAR, like this:
m_ExtGL.glClientActiveTextureARB(GL_TEXTURE0_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(CVertexArray), &vaScene->u);
m_ExtGL.glClientActiveTextureARB(GL_TEXTURE1_ARB);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(CVertexArray), &vaScene->lmu);
 
Thx for any advice! fallen

Share this post


Link to post
Share on other sites
you still need 4 texture coords per tri
see, then the texture isnt forced to be clamped, know what i mean?

hope that helps.
BTW, you waat to go
// base texture
glActiveTextureARB(GL_TEXTURE0)
glDisable(GL_TEXTURE_2D);
...
// lightmap
glActiveTextureARB(GL_TEXTURE1)
glEnable(GL_TEXTURE_2D);

(0,0)(1,0)(1,1)(0,1);

  
+----+
\ |
\ |
\ |
\|
+ +
(0,0)

(stupid tahoma)

[edited by - silvermace on June 5, 2002 7:04:32 AM]

Share this post


Link to post
Share on other sites
are you sure you set the lightmap coordinates correct??

looks to me you only set the u/v coordinates only once per face...

and as silvermace stated you should also disable the other texture...


mfg Phreak

--
"Input... need input!" - Johnny Five, Short Circuit.

Share this post


Link to post
Share on other sites
Thx for help.

@ silvermace: Why should there be a fourth uv coord? For my primary texture there are only 3 uv coords per triangle, too. And how would I set the coords, when there is no corresponding vertex?

@ LousyPhreak: Yeah, the uv coords should be allright.

If someone is interested, I could mail my lightmap code, it''s not very long.

Share this post


Link to post
Share on other sites
ok, here are some code snippets:

Here is the code for calculating the lightmap uv coords (lmu and lmv):

  
double nx = abs(m_Polygons[i].normal.x);
double ny = abs(m_Polygons[i].normal.y);
double nz = abs(m_Polygons[i].normal.z);

// Planar mapping

if ((nx > ny) && (nx > nz)) // Normal''s x coord greatest

{
for (j=0; j<m_Polygons[i].numvertices; j++)
{
m_Polygons[i].vertices[j].lmu = m_Polygons[i].vertices[j].coord.z;
m_Polygons[i].vertices[j].lmv = m_Polygons[i].vertices[j].coord.y;
}
}
else if ((ny > nx) && (ny > nz)) // Normal''s y coord greatest

{
for (j=0; j<m_Polygons[i].numvertices; j++)
{
m_Polygons[i].vertices[j].lmu = m_Polygons[i].vertices[j].coord.x;
m_Polygons[i].vertices[j].lmv = m_Polygons[i].vertices[j].coord.z;
}
}
else // Normal''s z coord greatest

{
for (j=0; j<m_Polygons[i].numvertices; j++)
{
m_Polygons[i].vertices[j].lmu = m_Polygons[i].vertices[j].coord.x;
m_Polygons[i].vertices[j].lmv = m_Polygons[i].vertices[j].coord.y;
}
}

// get min and max uv-coords

double uvMinU = m_Polygons[i].vertices[0].lmu;
double uvMinV = m_Polygons[i].vertices[0].lmv;
double uvMaxU = m_Polygons[i].vertices[0].lmu;
double uvMaxV = m_Polygons[i].vertices[0].lmv;
for (j=0; j<m_Polygons[i].numvertices; j++)
{
if (m_Polygons[i].vertices[j].lmu < uvMinU)
uvMinU = m_Polygons[i].vertices[j].lmu;
if (m_Polygons[i].vertices[j].lmv < uvMinV)
uvMinV = m_Polygons[i].vertices[j].lmv;

if (m_Polygons[i].vertices[j].lmu > uvMaxU)
uvMaxU = m_Polygons[i].vertices[j].lmu;
if (m_Polygons[i].vertices[j].lmv > uvMaxV)
uvMaxV = m_Polygons[i].vertices[j].lmv;
}

// calculate bounding box

double uvDeltaU = uvMaxU - uvMinU;
double uvDeltaV = uvMaxV - uvMinV;
for (j=0; j<m_Polygons[i].numvertices; j++)
{
m_Polygons[i].vertices[j].lmu -= uvMinU;
m_Polygons[i].vertices[j].lmv -= uvMinV;
m_Polygons[i].vertices[j].lmu /= uvDeltaU;
m_Polygons[i].vertices[j].lmv /= uvDeltaV;
}


The lightmaps is created correctly, so the problem must be somewhere within this code, I think...
Any idea, what''s wrong?

Share this post


Link to post
Share on other sites