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 6 of 6

Thread: About querying texture coordinates

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    11

    Exclamation About querying texture coordinates

    I'm working with Qt 4.8 and its OpenGL module, with the fixed pipeline and I have a sphere that was cubemapped, with the tex coords for each cube face auto-generated by OpenGL via
    Code :
    glTexGenf
    (R, S and T coordinates), like this:

    Code :
    glEnableClientState(GL_NORMAL_ARRAY);
    const GLenum textgt = GL_TEXTURE_CUBE_MAP;
    const GLfloat param = GL_REFLECTION_MAP;
     
    glTexGenf( GL_S, GL_TEXTURE_GEN_MODE, param );
    GLenum error = glGetError();
    if(GL_NO_ERROR != error) { ... }
     
    glTexGenf( GL_T, GL_TEXTURE_GEN_MODE, param );
    error = glGetError();
    if(GL_NO_ERROR != error) { ... }
     
    glTexGenf( GL_R, GL_TEXTURE_GEN_MODE, param );
    error = glGetError();
    if(GL_NO_ERROR != error) { ... }
     
    glEnable( GL_TEXTURE_GEN_S );
    glEnable( GL_TEXTURE_GEN_T );
    glEnable( GL_TEXTURE_GEN_R );

    When clicking in the scene, I'm retrieving the vertex coordinates under the mouse cursor via
    Code :
    glReadPixels
    and
    Code :
    gluUnProject
    .

    What I'm looking for is a way to retrieve the texture coordinate associated to that position, instead of getting the vertex value.
    I didn't find anything regarding this topic, so I was wondering if there was a way to achieve this.

    Thanks for your time!

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    You can use the GL specification to source the formulas used for texcoord auto-generation and recalculate them yourself from the retrieved vertex position value.

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    11
    Thanks mhagain!

    I've downloaded the specification and I'm reading the texture generation part.

    I've also found this: https://www.opengl.org/wiki/Mathematics_of_glTexGen. But I'm not sure if the formulas in that link are "deprecated".

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,728
    They look fine; I wouldn't worry about deprecation in this case since glTexGen itself is also deprecated, so at least you've satisfied the condition that your calculations are going to be consistent.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    11
    Ok! Thanks a lot!

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2014
    Posts
    11
    Hi again!

    I've been using the formulas in https://www.opengl.org/wiki/Mathematics_of_glTexGen (also tried the formula in the specification in Octave. It gave the same result).

    The vertex is the value I got after calling gluUnProject and, since this is a sphere, I'm using the vertex as the normal.

    So after the computations, for a vertex V = {-0.577350 0.572447 0.577350}, the computed texels are STR = {0.572455 -0.567593 -0.572455}.

    I have some doubts with this.
    First, in every test I took, the texel coords were very close to the vertex coords and with the opposite sign. Is this expected?

    Second, I have this texture setup:

    Code :
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
        glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

    having negative texels, I'd expect to see some strange effects in the cube when clamping the values of the texel to the edge, yet the cubemap is (apparently) perfect.

    Do you have any thoughts on this?

Tags for this Thread

Posting Permissions

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