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: using pixel textures in NV_texture_shader

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    10

    using pixel textures in NV_texture_shader

    Hello,

    I'm trying to use the pixel texturing function in NV_texture_shader. I'm trying to do something pretty basic - use the R and G channels of one texture as the texture coordinates for another. I have the following code snippet. What am I doing wrong?!?!

    // Pixel Texture Map. First texture used as
    // texture coordinates. R and G channels go
    // from 0.0 to 1.0. Alpha is set to 1.0.
    glEnable(GL_TEXTURE_SHADER_NV);
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexEnvi(GL_TEXTURE_ENV,
    GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexEnvi(GL_TEXTURE_SHADER_NV,
    GL_SHADER_OPERATION_NV, GL_TEXTURE_2D);

    // Texture that I'm trying to map.
    glEnable(GL_TEXTURE_SHADER_NV);
    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texture[1]);
    glTexEnvi(GL_TEXTURE_ENV,
    GL_TEXTURE_ENV_MODE, GL_REPLACE);

    // Drawing a square w/texture map.
    glBegin(GL_QUADS);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f,
    0.0f);
    glVertex3f(-1.0f, -1.0f, 1.05f);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f,
    0.0f);
    glVertex3f( 1.0f, -1.0f, 1.05f);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f,
    1.0f);
    glVertex3f( 1.0f, 1.0f, 1.05f);
    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f,
    1.0f);
    glVertex3f(-1.0f, 1.0f, 1.05f);
    glEnd();
    glDisable(GL_TEXTURE_SHADER_NV);
    glFlush();

    What I'm getting is the first texture mapped onto the square as a color texture instead of being used as texture coordinates. I've tried several combinations of these statements and still didn't get the right mapping. It seems to work if I use the DEPENDENT_GB_TEXTURE_2D_NV, but I wanted to avoid using that. Thanks in advance for any help!

    - Q.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    591

    Re: using pixel textures in NV_texture_shader

    You can't use the R and G channels of the first texture to index into the second. You must use the G and B, or the A and R channels.

    Once you have the appropriate texture coordinates in tex0, you need to set the shader operation of tex1 to DEPENDENT_GB_TEXTURE_2D_NV or DEPENDENT_AR_TEXTURE_2D_NV.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    10

    Re: using pixel textures in NV_texture_shader

    Thanks for your reply!

    Yes, what you suggest above works - using DEPENDENT_AR_TEXTURE_2D_NV. But, according to the specs, there's the option to use conventional textures. Here's what it says:
    "TEXTURE_2D - Accesses a 2D texture via (s/q,t/q)."

    where s and t is defined as the R and G channels. I've also seen examples (w/o code) that describe using the R and G channels as the pixel texture...

    I'm concerned about using G and B or A and R, because I'm not sure that the DEPENDENT_AR_TEXTURE_2D_NV specification will work w/3D textures (which I'll soon need to do). But, maybe it does?

    - Q.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Jan 2001
    Location
    NVIDIA, Austin, TX
    Posts
    591

    Re: using pixel textures in NV_texture_shader

    The TEXTURE_2D operation just does a standard 2D texture lookup on the texture unit its specified on, it's not a dependent texture lookup.

    Yes, you can use the DEPENDENT_RGB_TEXTURE_3D_NV operation if you want to fetch from a 3D texture. This is exposed in the GL_NV_texture_shader3 extension, which is only supported on GeForce4 (NV25) and higher.

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2003
    Posts
    10

    Re: using pixel textures in NV_texture_shader

    Ahh, ok great! Thanks for the info!

    - Q.

Posting Permissions

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