Texture projection - setting up

Started by
3 comments, last by deffer 18 years, 9 months ago
So apparently I have no idea how to do this right, even after searching a whole day on google and so. Based on some chunks I have found, I wrote this:
[source lang="cpp]
#define VERTEX(x,y,z) glVertex3f(x,y,z)
//#define VERTEX(x,y,z) glTexCoord3f(x,y,z); glVertex3f(x,y,z)

void RenderProjection(void)
{
   glEnable(GL_TEXTURE_2D);
   glBindTexture( GL_TEXTURE_2D, g_ProjTexture );
   {
      glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
      // color
      glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
      glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR );
      glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_REPLACE );
      // alpha
      glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_TEXTURE );
      glTexEnvi( GL_TEXTURE_ENV, GL_OPERAND0_ALPHA_ARB, GL_SRC_ALPHA );
      glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE );
   };

   // Enable projector.
   const mat objOrient = identityMat(); // For now only.
   g_TexProjector.EnableProjectiveTexturing(objOrient);

   // DRAW!
   glBegin(GL_QUADS);
   {  // 12
      // 03
      glColor3f(1.0f, 1.0f, 1.0f);
      VERTEX( 0, 0, 0 );
      VERTEX( 0, 2, 0 );
      VERTEX( 2, 2, 0 );
      VERTEX( 2, 0, 0 );
   };
   glEnd();

   // Restore settings.
   g_TexProjector.DisableProjectiveTexturing();
}


Where I enable/disable projection with:

void CTexProjector::EnableProjectiveTexturing(const mat& texMat)
{
   //Set up texture coordinate generation.
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_S, GL_EYE_PLANE, (float*)&texMat.k0); // 4-component column.
   glEnable(GL_TEXTURE_GEN_S);

   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_T, GL_EYE_PLANE, (float*)&texMat.k1);
   glEnable(GL_TEXTURE_GEN_T);

   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_R, GL_EYE_PLANE, (float*)&texMat.k2);
   glEnable(GL_TEXTURE_GEN_R);

   glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_Q, GL_EYE_PLANE, (float*)&texMat.k3);
   glEnable(GL_TEXTURE_GEN_Q);
};

void CTexProjector::DisableProjectiveTexturing(void)
{
   glDisable(GL_TEXTURE_GEN_S);
   glDisable(GL_TEXTURE_GEN_T);
   glDisable(GL_TEXTURE_GEN_R);
   glDisable(GL_TEXTURE_GEN_Q);
};


And what I see, is just a dark-grey square. My texture is pure-green. For now, i just set identity as my projection matrix, not to complicate things. But it shouldn't matter anyway. There should be a texture coordinate assigned to each vertex, any value should be good. But it behaves as there wasn't any. Maybe there's just something missing, or am I doing it all wrong? Any help appreciated. /def
Advertisement
idea, try setting the texture wrapping to GL_REPEAT
Quote:Original post by zedzeek
idea, try setting the texture wrapping to GL_REPEAT


Neah, I already did that, by default.
I wonder what other settings may affect that, as I tried numerous combinations, not to get to te conclussion...
Try this, don't use the combiner functions just modulate it for now and see if you see a green square.
Thanks, but I've already found out what I screwed.

I was using GL_OBJECT_LINEAR, but setting matrix for GL_EYE_PLANE, instead of GL_OBJECT_PLANE.
All the tutorials on the web were using GL_EYE_LINEAR, which was of no use to me, but none ever mentioned that second parameter - GL_OBJECT_PLANE - ever existed.

Anyway, cheers.
/def

This topic is closed to new replies.

Advertisement