Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: fragment shader multiple texcoords input

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    2

    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:

    Code :
    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

  2. #2
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: fragment shader multiple texcoords input

    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:

    Code :
    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.

  3. #3
    Senior Member OpenGL Guru
    Join Date
    Mar 2001
    Posts
    2,704

    Re: fragment shader multiple texcoords input

    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.
    "If you can't afford to do something right,
    you'd better make sure you can afford to do it wrong!"

  4. #4
    Advanced Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    750

    Re: fragment shader multiple texcoords input

    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.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2004
    Posts
    2

    Re: fragment shader multiple texcoords input

    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
    Code :
    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 :-))
    Code :
    glActiveTextureARB(GL_TEXTURE0_ARB );
    glBindTexture( GL_TEXTURE_RECTANGLE_NV, tex );
    glCopyTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0,0,0,0,0, IMGWIDTH, IMGHEIGHT);
    Greetz,

    Karel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •