Results 1 to 9 of 9

Thread: Texture trouble

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    10

    Texture trouble

    I'm trying to texture a rectangle, easy enough. But the problem is: there's transparency in the image, and black, and other colours. What's black also becomes transparent.
    I use:

    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
    glEnable(GL_BLEND);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
    glTexParameteri(textureTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(textureTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);
    glTexParameteri(textureTarget, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    glTexParameteri(textureTarget, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glEnable(textureTarget);
    glBegin(GL_QUADS);
    glTexCoord2f(0, 0); glVertex2f(0, h);
    glTexCoord2f(0, im.imgh); glVertex2f(0, 0);
    glTexCoord2f(im.imgw, im.imgh); glVertex2f(w, 0);
    glTexCoord2f(im.imgw, 0); glVertex2f(w, h);
    glEnd();
    glDisable(textureTarget);
    glDisable(GL_BLEND);

    Thanks for helping out.

  2. #2
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Texture trouble

    That's happening because it's what you've told OpenGL to do, specifically in these lines:
    Code :
    glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
    glEnable(GL_BLEND);
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

  3. #3
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Texture trouble

    Fastjack, can you explain what results you want ?

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    10

    Re: Texture trouble

    I want the image completely displayed, except the parts that are transparent. Black should be displayed as black, transparent should be transparent, other colours should be other colours. I'm not sure what the right settings are for this effect.

  5. #5
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Texture trouble

    Then you need glBlendFunc(SRC_ALPHA, ONE_MINUS_SRC_ALPHA)

    or GL_ONE, ONE_MINUS_SRC_ALPHA if your textures have premultiplied alpha.

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    10

    Re: Texture trouble

    neither work, first turns transparent black, second turns black transparent

  7. #7
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Texture trouble

    Sorry for you then, because it means you are doing something else wrong.
    Are you certain you draw the translucent part last ? Otherwise the depth buffer can get in the way.
    Are you certain that alpha is 0 for transparent texels, and 255 for fully visible texels ?

  8. #8
    Junior Member Newbie
    Join Date
    Jun 2008
    Posts
    10

    Re: Texture trouble

    I am drawing the translucent part last.
    To my astounishment the alpha is not 0, but very low (0x01) for transparent texels, 255 for fully visible texels.

    I don't know what to do...

  9. #9
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: Texture trouble

    Reduce your code to the smaller compilable Glut program still showing your problem, and post it here.

Similar Threads

  1. Having Trouble texture mapping
    By choblocken in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-15-2018, 12:17 PM
  2. Trouble displaying texture
    By TheFearlessHobbit in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 03-22-2017, 07:52 AM
  3. Trouble Rendering Texture to FBO
    By DoubleJ in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-12-2010, 04:29 PM
  4. FBO texture rendering trouble
    By eldritch in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 04-17-2009, 09:35 AM
  5. Hello ! (trouble with Texture activation !)
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-13-2003, 02:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean