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: 2D texture is not mapped; constantly getting black quadrangle

  1. #1
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Nizhny Novgorod, RUSSIA
    Posts
    71

    2D texture is not mapped; constantly getting black quadrangle

    I use the code below (really standard one):

    ...

    glGenTextures(1, &texname);
    glBindTexture(GL_TEXTURE_2D, texname);
    makeTexture(); // here pixel colors are calculated
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
    GL_REPEAT);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
    GL_LINEAR);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
    GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height,
    0, GL_RGB, GL_UNSIGNED_BYTE,
    &image[0][0][0]); //
    glEnable(GL_TEXTURE_2D);

    ...

    glBindTexture(GL_TEXTURE_2D, texname);
    drawPolygon(); // glTexCoord2 is used here in conjunction with glVertex

    This code was inserted into a large visualization library. And it doesn't work there. While it works well in a small standalone application. I checked the following possible problems:
    1) Incorrect texture dimensions
    2) Errors after texture-related GL function calls (glGetError says it's OK).
    3) Incorrect texture coordinates

    It seems that everything is OK except that texture is not mapped!!! OpenGL monsters, do you have any ideas why? I work on TNT2 Pro under Win2k+SP3.

  2. #2
    Intern Contributor
    Join Date
    Mar 2003
    Posts
    95

    Re: 2D texture is not mapped; constantly getting black quadrangle

    1-Checked the UV coordinates for the textures ?
    they are correctly placed into the vertex they should ?

    2-Are you enabling the texture unit insida a glBegin(),glEnd() pair ? if yes , it wonīt work , so take it from from there.

    3-Check if any crazy bug is occuring while creating the texture.
    As shadows into darkness, the Ninja fades away

  3. #3
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Nizhny Novgorod, RUSSIA
    Posts
    71

    Re: 2D texture is not mapped; constantly getting black quadrangle

    Originally posted by raverbach:
    1-Checked the UV coordinates for the textures ?
    they are correctly placed into the vertex they should ?
    I did. It's OK.


    2-Are you enabling the texture unit insida a glBegin(),glEnd() pair ? if yes , it wonīt work , so take it from from there.
    Enabling it outside glBegin/glEnd...


    3-Check if any crazy bug is occuring while creating the texture.

    I use simple for-loop to create the test texture. Colors are properly computed and put into it.

  4. #4
    Intern Contributor
    Join Date
    Mar 2003
    Posts
    95

    Re: 2D texture is not mapped; constantly getting black quadrangle

    Ohhh ...i see , itīs working well alone ....
    check if youīre not gatting into conflict with another texture unit ,that itīs not disabled and is not beeing used ...for example

    if someone used a

    Code :
    glActiveTextureARB(GL_TEXTURE0_ARB);
    glBindTexture(GL_TEXTURE-2D,GtEX[i]);
    glEnable(GL_TEXTURE_2D);  
     
    glActiveTextureARB(GL_TEXTURE1_ARB)
    glBindTexture(GL_TEXTURE-2D,GtEX[i]);
    glEnable(GL_TEXTURE_2D);  
    .
    .
    .
    and did not disable one of the texture units
    then glTexCoord will not work properly

    you must check all texture unit calls , disable them like that
    Code :
    glActiveTextureARB(GL_TEXTURE0_ARB)
    glDisable(GL_TEXTURE_2D);
    Or if they use arrays , just disable the texure array

    glDisableClientState();

    then use your code
    As shadows into darkness, the Ninja fades away

  5. #5
    Advanced Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Melbourne,Victoria,Australia
    Posts
    767

    Re: 2D texture is not mapped; constantly getting black quadrangle

    Try using gluBuild2DMipmaps() instead of glTexImage2D() OR don't use mip maps (If you are only specifying Lvl 0 of your mip maps and any other level is used when drawing your geometry will result in the texture not being drawn.

  6. #6
    Junior Member Newbie
    Join Date
    Apr 2003
    Posts
    8

    Re: 2D texture is not mapped; constantly getting black quadrangle

    Other strange things that could affect it are lighting and blending.

    Before calling drawPolygon() try,
    glDisable( GL_LIGHTING )
    glDisable( GL_BLEND )
    and even
    glDisable( GL_TEXTURE_2D )

    See what happens. Maybe something strange, maybe nothing at all.

Posting Permissions

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