Results 1 to 5 of 5

Thread: Loading an RGB bitmap with alpha?

  1. #1
    Member Contributor
    Join Date
    Dec 2010
    Posts
    57

    Loading an RGB bitmap with alpha?

    If I have a texture in 24-bit RGB format and I want to treat a color as 'transparent alpha', say magenta (ff00ff), is there a way to load into GL as an RGBA texture with an alpha channel? Or must I pre-convert the image into an RGBA format and then load the texture?

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2010
    Location
    Brazil, Rio de Janeiro
    Posts
    147

    Re: Loading an RGB bitmap with alpha?

    I guess you need to "pre-convert". I don't know anything about using an arbitrary color as transparency.

  3. #3
    Member Contributor
    Join Date
    Dec 2010
    Posts
    57

    Re: Loading an RGB bitmap with alpha?

    Hmm I still get solid black pixels. I wonder do I need to handle this in the fragment shader?

    If the color picked by the sampler2D() has an alpha value of 0.0, I suppose I must somehow blend with what is already there in the front buffer?

    Right now my basic fragment shader looks like:
    Code :
    #version 330
     
    uniform sampler2D tex;
     
    in vec2 texPos;
    in vec3 fragPos;
     
    out vec4 outFragColor;
     
    void main()
    {
    	vec4 tex_color;
    	tex_color = texture2D(tex, texPos);
     
    	outFragColor = tex_color;
    }

    Do I A) need to create my own framebuffer to do so?
    or B) can somehow blend with the default buffer?

    Right now it is very simple I am trying to draw bitmap font glyphs on the screen, obviously with transparency around the actual glyph itself.

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,675

    Re: Loading an RGB bitmap with alpha?


  5. #5
    Member Contributor
    Join Date
    Dec 2010
    Posts
    57

    Re: Loading an RGB bitmap with alpha?

    Oh goodie I thought it might have been deprecated for some reason.

    I added two lines to my GL init function and it works fine now.

    glEnable(GL_BLEND);
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

Similar Threads

  1. alpha value in bitmap
    By t3jem in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 09-09-2005, 04:53 PM
  2. Loading bitmap in C
    By Andrew Davey in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-17-2004, 01:35 AM
  3. loading .TGA and bitmap
    By kashif saeed in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-11-2003, 08:59 AM
  4. Loading A Bitmap
    By Stack Overflow in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 12-10-2002, 02:04 PM
  5. Monochrome bitmap as Alpha texture
    By imported_ben in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 08-14-2000, 09:08 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