views:

73

answers:

0

I've got two textures mapping to a surface, one is a checkerboard (the pattern on the floor) and one is a lightmap, both of which are blending and presenting just fine. What I'm having trouble with is making the lightmap texture translate prior to blending. I need to do this so I can simulate a flashlight scanning across the floor....

Code:

    //Floor - Checkerboard
  float fF = 3.0; //Floor Factor

  //Checkerboard texture
  glActiveTexture(GL_TEXTURE0);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, textures[0]);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);//turn on mipmapping
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  //Spotlight, modulate on checkerboard
  glActiveTexture(GL_TEXTURE1);
  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, textures[4]);
  **glPushMatrix();
    glMatrixMode(GL_TEXTURE);
    glLoadIdentity();
    glTranslatef(5.0, 5.0, 0.0);
    glMatrixMode(GL_MODELVIEW);
  glPopMatrix();**
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);

  float vals[4] = {0.0, 0.0, 0.0, 0.5};

  glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, vals);
  glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
  glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE); 
  glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
  glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
  glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);

  float spot_x = 1;
  float spot_y = 1;

  glBegin(GL_QUADS); 
  glNormal3d(0, 1, 0);
  glMultiTexCoord2f(GL_TEXTURE0, 0.0, fF); 
  glMultiTexCoord2f(GL_TEXTURE1, 0.0, spot_y); 
  glVertex3fv(d);
  glMultiTexCoord2f(GL_TEXTURE0, fF, fF); 
  glMultiTexCoord2f(GL_TEXTURE1, spot_x, spot_y); 
  glVertex3fv(c);
  glMultiTexCoord2f(GL_TEXTURE0, fF, 0.0); 
  glMultiTexCoord2f(GL_TEXTURE1, spot_x, 0.0); 
  glVertex3fv(e);
  glMultiTexCoord2f(GL_TEXTURE0, 0.0, 0.0); 
  glMultiTexCoord2f(GL_TEXTURE1, 0.0, 0.0); 
  glVertex3fv(g);

  glEnd();

I've tried putting the six lines of code inside the **'s in several locations, thinking maybe the OpenGL state machine needed it somewhere specific, but nothing seems to give me the effect I want.

Anyone done this before? I can't find any information in either of my OpenGL books, or online about translating AND blending textures. I might be looking for the wrong thing, but I've been beating my head against a wall for two days now. Any help at all would be awesome.

Thanks