Jump to content
  • Advertisement
Sign in to follow this  
deffer

Texture projection - setting up

This topic is 4875 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

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

Share this post


Link to post
Share on other sites
Advertisement
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...

Share this post


Link to post
Share on other sites
Try this, don't use the combiner functions just modulate it for now and see if you see a green square.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!