iDevGames Forums
iPhone multitexturing and lightmaping - Printable Version

+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: iPhone, iPad & iPod Game Development (/forum-11.html)
+--- Thread: iPhone multitexturing and lightmaping (/thread-7965.html)



iPhone multitexturing and lightmaping - narpas - Aug 9, 2010 09:21 AM

Hey guys I am trying to do some simple lightmapping with static geometry but it does not seem to be multiplying the 2 textures. Here is my binding code

Code:
    glActiveTexture(GL_TEXTURE0);
    [lightmap bindTexture];
    glActiveTexture(GL_TEXTURE1);
    [texture bindTexture];
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);  
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);

    glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);  
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
    glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
    glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);

and I also use this for texture coords on the static geometry
Code:
    glClientActiveTexture(GL_TEXTURE1);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(textureCoords,...);
    
    
    glClientActiveTexture(GL_TEXTURE0);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glTexCoordPointer(textureCoords,...);

anybody know what I am doing wrong?


RE: iPhone multitexturing and lightmaping - OneSadCookie - Aug 9, 2010 11:10 AM

You're not setting COMBINE_RGB, is it already set to what you want?


RE: iPhone multitexturing and lightmaping - narpas - Aug 9, 2010 12:44 PM

(Aug 9, 2010 11:10 AM)OneSadCookie Wrote:  You're not setting COMBINE_RGB, is it already set to what you want?

Woops sorry I was in my code but not the post I fixed the post to show it.


RE: iPhone multitexturing and lightmaping - Bachus - Aug 9, 2010 05:11 PM

(Aug 9, 2010 12:44 PM)narpas Wrote:  
(Aug 9, 2010 11:10 AM)OneSadCookie Wrote:  You're not setting COMBINE_RGB, is it already set to what you want?

Woops sorry I was in my code but not the post I fixed the post to show it.

Does the lightmap just not show up? Only the lightmap show up? The texture combiners look okay, but it's hard to tell without knowing exactly what the problem is. Post a screenshot.

The default texture combiner settings should actually work fine for lightmaps.

Code:
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, &vertices[0]);
    
glActiveTexture(GL_TEXTURE1);
glClientActiveTexture(GL_TEXTURE1);

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, lightmapTex);
glTexCoordPointer(2, GL_FLOAT, 0, &texCoords2[0]);
        
glActiveTexture(GL_TEXTURE0);
glClientActiveTexture(GL_TEXTURE0);

glEnable(GL_TEXTURE_2D);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glBindTexture(GL_TEXTURE_2D, diffuseTex);
glTexCoordPointer(2, GL_FLOAT, 0, &texCoords[0]);
    
glDrawArrays(GL_TRIANGLES, 0, numIndices);

glActiveTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);



RE: iPhone multitexturing and lightmaping - narpas - Aug 9, 2010 05:50 PM

Thanks for the help everyone I figured it out.
I needed to enable texture 2d when I set the active texture to 0 and when I set it to 1. like so
Code:
    glActiveTexture(GL_TEXTURE0);
    glEnable(GL_TEXTURE_2D);
    [lightmap bindTexture];
    glActiveTexture(GL_TEXTURE1);
    glEnable(GL_TEXTURE_2D);
    [texture bindTexture];