fragment shader multiple texcoords input

Hi,

is it possible to generate more than 1 TEXCOORD’s as input for a cg fragment shader program, with glTexGen?

And if it’s possible, how exactly can it be done? I was trying to do it with multitexturing but I don’t seem to get it to work. This is how I’m trying to do it:

for(i = 0; i < m_nrImgs; i++)
{
  glActiveTextureARB(GL_TEXTURE0_ARB + i);
  glMatrixMode(GL_TEXTURE);
  glLoadIdentity();
  loadTextureProjection(m_imgs[i]);
}
renderQuad();

For each of my images, I want to load a different projective texture matrix. That’s what the “loadTextureProjection” routine does. It also enables GL_TEXTURE_GEN_S etc…

I would appreciate any comments or hints.

Thanks,

Karel

Karel, this can indeed be done. You need to check the limitations on the number of texture coordinates your card supports. There are three flavors in the glGetIntegerv(): MAX_TEXTURE_COORDS, MAX_TEXTURE_UNITS, MAX_TEXTURE_IMAGE_UNITS ( in case you didn’t know…)

You might try this:

for(i = 0; i < m_nrImgs; i++){  

glActiveTextureARB(GL_TEXTURE0_ARB + i);  

glMatrixMode(GL_TEXTURE);  
glLoadIdentity();  
loadTextureProjection(m_imgs[i]);

// set the tex gen mode
glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, mode );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, mode );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, mode );

// where mode is one of the enums: EYE_LINEAR, OBJECT_LINEAR, ...

// set the tex gen planes
glTexGenfv( GL_S, type, s_plane );
glTexGenfv( GL_T, type, t_plane );
glTexGenfv( GL_R, type, t_plane );
// where type is one of the enums: EYE_PLANE, OBJECT_PLANE, ...

}
renderQuad();

I hope this answers your question.

That ought to do the right thing, from a quick reading.

Perhaps the Cg runtime is somehow getting in the way of you doing this?

Anyway, when you’re using fragment programs, you already know that vertex programs are available, so you could always write a vertex program that outputs the texture coordinates you want.

That’s a good point, if you use a vertex program, you could put 'er in manual. Although, the texture gen planes could still be usefull if using arbvp1.

Thanks for the replies guys, I got it working now without a vertex program.
So the cg runtime doesn’t seem to be a problem at all.

The actual problem was somewhat further in my code. I need to copy the rendered image to a texture so I could use that image later on. Well, to do this I just had these two lines of code which worked fine without multitexturing

glBindTexture( GL_TEXTURE_RECTANGLE_NV, tex );
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,0,0,0,0, IMGWIDTH, IMGHEIGHT);

However, I found out now that the active texture unit must be set the GL_TEXTURE0_ARB in order to let it work.
So now I 've just put in one extra line of code and it works perfect :-))

glActiveTextureARB(GL_TEXTURE0_ARB );
glBindTexture( GL_TEXTURE_RECTANGLE_NV, tex );
glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,0,0,0,0, IMGWIDTH, IMGHEIGHT);

Greetz,

Karel