Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Sorry, again Multitexturing

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Sorry, again Multitexturing

    I want to make a texture of my current screen, including its depth and the RGBA values.

    //////////// my main program

    // Render to Texture

    glActiveTexture(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, depthToTexture);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);

    glActiveTexture(GL_TEXTURE1_ARB);
    glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);


    texLoc = glGetUniformLocationARB(p, "dTexture");
    glUniform1iARB(texLoc, 0);

    texLoc = glGetUniformLocationARB(p, "texture");
    glUniform1iARB(texLoc, 1);

    // Render Scene

    /************************************ depth ****************************************/
    glActiveTexture(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, depthToTexture);

    // and draw textured quad with our rendered texture
    glEnable(GL_TEXTURE_2D);

    /************************************ RGBA ****************************************/

    glActiveTexture(GL_TEXTURE1_ARB);
    glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);

    // and draw textured quad with our rendered texture
    glEnable(GL_TEXTURE_2D);

    glBegin( GL_QUADS );
    // glColor4fv(orgColor);
    glMultiTexCoord2f (GL_TEXTURE0_ARB, 0, 0);
    glMultiTexCoord2f (GL_TEXTURE1_ARB, 0, 0);
    glVertex2f(0, 0);
    glMultiTexCoord2f (GL_TEXTURE0_ARB, 0, 1);
    glMultiTexCoord2f (GL_TEXTURE1_ARB, 0, 1);
    glVertex2f(0, WIN_HEIGHT);
    glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 1);
    glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 1);
    glVertex2f(WIN_WIDTH, WIN_HEIGHT);
    glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 0);
    glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 0);
    glVertex2f(WIN_WIDTH, 0);
    glEnd();

    glDisable(GL_TEXTURE_2D);

    //////////////// Vertex Shader

    gl_TexCoord[0] = gl_MultiTexCoord0;
    gl_TexCoord[1] = gl_MultiTexCoord1;

    //////////////// Fragment Shader

    gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works

    but
    gl_FragColor = texture2D(texture, gl_TexCoord[1].st);
    works not.

    ____________________

    If switch the TEXTUREIndices the other texture works (here the RGBA would work then). Finally, I get only access to TEXTURE0.

    I tested different combinations. Nothing will work. What do I wrong?

    Thanx

  2. #2
    Senior Member OpenGL Guru zed's Avatar
    Join Date
    Jul 2000
    Location
    S41.16.25 E173.16.21
    Posts
    2,609

    Re: Sorry, again Multitexturing

    theres no need to specify the same info twice ie glMultiTexCoord2f (GL_TEXTURE0_ARB, 1, 1);
    glMultiTexCoord2f (GL_TEXTURE1_ARB, 1, 1);
    any texture unit can use any texture coordinates ie GL_TEXTURE7 doesnt have to use GL_TEXTURE7 texture coord

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    Ok, I have changed that in the main program and the shaders. But there is still the main problem that only the first texture unit (TEXTURE0) is accessable in the fragment shader. Any idea?

  4. #4
    Senior Member OpenGL Guru Relic's Avatar
    Join Date
    Apr 2000
    Posts
    2,527

    Re: Sorry, again Multitexturing

    What's the size of your RGBAtoTexture?
    What's the min filter? (mipmap is default!)
    You didn't say what HW you're running on. It might be that you're missing non-power-of-two texture support. Try power-of-two client window size or move to texture rectangles.
    You shouldn't need to enable texturing because fragment shaders work on texture image units.

  5. #5
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    RGBA texture: 512*512
    depth texture: 512*512
    client window: 512*512

    So it cannot be a power-of-2 problem. The texture just fits the screen, so you actually don't see that it's a texture. It is just for the purpose of multipassing.

    The min filter is GL_LINEAR.

    HW: NVIDIA GeForce 6800

    And finally:
    Although I am not really sure about the term texture image units, it also works without enabling. But it still results in the depth texture which is my TEXTURE0, regardless of which sampler I use in the frag shader.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    Actually both texures are 512*512*4*sizeof(unsigned char)

  7. #7
    Super Moderator OpenGL Guru
    Join Date
    Feb 2000
    Location
    Montreal, Canada
    Posts
    4,421

    Re: Sorry, again Multitexturing

    Are you doing

    //gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works
    gl_FragColor = texture2D(texture, gl_TexCoord[1].st);

    or this

    gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // works
    gl_FragColor = texture2D(texture, gl_TexCoord[1].st);

    Finally, inspect the assembly code dump for the shaders. Get NVemulate to turn this feature on if you haven't. If all else fails, make a GLUT sample and upload it somewhere.
    ------------------------------
    Sig: http://glhlib.sourceforge.net
    an open source GLU replacement library. Much more modern than GLU.
    float matrix[16], inverse_matrix[16];
    glhLoadIdentityf2(matrix);
    glhTranslatef2(matrix, 0.0, 0.0, 5.0);
    glhRotateAboutXf2(matrix, angleInRadians);
    glhScalef2(matrix, 1.0, 1.0, -1.0);
    glhQuickInvertMatrixf2(matrix, inverse_matrix);
    glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
    glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

  8. #8
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    I have only one assignment. I just wanted to show both relevant alternatives I have tested.
    And I don't use the gl_TexCoord[1] anymore, because both RGBA and depth have the same coordinates.

    So it's like that:

    //gl_FragColor = texture2D(dTexture, gl_TexCoord[0].st); // shows depth
    gl_FragColor = texture2D(texture, gl_TexCoord[0].st); // unforunately shows depth, too.

    Ok, I will try that with NVemulate.

    Thx

  9. #9
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    Ok. Seems as if there is no problem with the access of the different texture units in the frag shaders. So maybe both ones have the same content.

    My Code:

    glActiveTexture(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE_2D, depthToTexture);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);

    glActiveTexture(GL_TEXTURE1_ARB);
    glBindTexture(GL_TEXTURE_2D, RGBAtoTexture);
    glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0);


    texLoc = glGetUniformLocationARB(p, "dTexture");
    glUniform1iARB(texLoc, 0);

    texLoc = glGetUniformLocationARB(p, "cTexture");
    glUniform1iARB(texLoc, 1);

    Would it be possible that glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, 0, 0, WIN_WIDTH, WIN_HEIGHT, 0) changes des Buffer and writes the depth into it?

    Or do I have to deactivate Texture0 before activating Texture1 or something like this?

  10. #10
    Junior Member Newbie
    Join Date
    Apr 2005
    Posts
    14

    Re: Sorry, again Multitexturing

    Because I cannot find what's wrong in my program, please have a look at my code:

    http://www.informatik.fh-wiesbaden.de/~msiek001/
    or
    http://www.informatik.fh-wiesbaden.d...EasyShader.zip

    thx

Posting Permissions

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