iPhone multitexturing and lightmaping

Apprentice
Posts: 11
Joined: 2010.07
Post: #1
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You're not setting COMBINE_RGB, is it already set to what you want?
Quote this message in a reply
Apprentice
Posts: 11
Joined: 2010.07
Post: #3
(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.
Quote this message in a reply
Member
Posts: 269
Joined: 2005.04
Post: #4
(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);
Quote this message in a reply
Apprentice
Posts: 11
Joined: 2010.07
Post: #5
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];
Quote this message in a reply
Post Reply