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: Blending Problem

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Blending Problem

    I'm trying to use transparent textures in my application.
    I've used the required procedures:
    Code :
    glDisable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

    I'm using GL_RGBA texture formats, my glsl code is just a plain texture shader, and my objects are drawn in the right order. However I am still seeing two opaque objects. Have i missed anything out?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,792

    Re: Blending Problem

    So what happens if you force an alpha of 0.5 in your shader? That is, you just set the alpha component of the output color to 0.5, after you set the other three components with the value fetched from the texture.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Blending Problem

    I just changed my fragment shader code to this:
    Code :
    gl_FragColor = texture2D(tex, gl_TexCoord[0].st);		
    gl_FragColor.a = 0.5;

    And I get the same result.(Used the wrong shader :S)

    I now get transparency, but my texture is 32bit and i used this code to create it:
    glTexImage2D(GL_TEXTURE_2D, 0, 4, bmp->get_width(), bmp->get_height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, bmp->get_bytes());

    So i should be getting alpha values from the texture shouldn't I.

  4. #4
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,792

    Re: Blending Problem

    Then your problem has nothing to do with your texture. Blending isn't working for you for some reason. So put together a small test application that just draws two things, one on top of the other. Then get blending working so that the one on top is blended properly.

  5. #5
    Junior Member Newbie
    Join Date
    May 2011
    Location
    United Kingdom
    Posts
    12

    Re: Blending Problem

    Wow, I've been using my own texture file format (nothing special, just width, height, then 32bit pixel data) and I made a file converter. For some reason converting from a 32bit bitmap gives me a completely opaque texture, but converting from png gives me transparency. Anyway I have no problems with that.

    EDIT: It seems I've ran into another problem.
    All the triangles are oddly shaded. There's a picture attached. I'm almost certain that there are no problems with the normals.

Posting Permissions

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