Results 1 to 5 of 5

Thread: (Open GL, blit) Making a bitmap colour transparent

  1. #1
    Member Contributor
    Join Date
    May 2012
    Posts
    51

    (Open GL, blit) Making a bitmap colour transparent

    I'm creating a side-scroller and I need make a colour transparent within one of my layers. I'm guessing there should be function for this since it must be common.

    what are the Bit blit functions?

  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,678

    Re: (Open GL, blit) Making a bitmap colour transparent

    There aren't any "bit blit functions" (at least, not in the way you mean). That's not how transparency works in OpenGL, and that's not how you should use OpenGL to render 2D graphics.

    To use OpenGL to render 2D graphics, what you want to do is play to OpenGL's strengths. Namely, rendering textured polygons. A 2D image is just a texture. And if you position a quad (polygon with 4 vertices) correctly on the screen, with a proper texture, then you are effectively drawing that texture to the screen.

    So you need to upload all of your images to OpenGL as textures. Now, you should try to group images that get used together into the same texture. For example, if you have a sprite that has multiple animation frames, then they should all go in the same texture. You select which image to use based on your texture coordinates.

    Then you just draw quads to the proper location in order to make everything work.

    As for transparency, OpenGL doesn't really have a way to do precisely what you're talking about. You're talking about "color keying": having a specific color be considered transparent. OpenGL uses a much more flexible blending mechanism. Instead of color keying, colors are 4-dimensional components. They have red, green, blue, and alpha, which can be used to denote transparency. An alpha of 255 can be considered opaque, and an alpha of 0 can be considered transparent.

    If you want color keying, then you need to do it manually. When you load your image from wherever you get it, you need to convert it from an RGB image to an RGBA image. Every RGB value that doesn't match the color key gets an alpha of 255 (opaque) and every value that does gets an alpha of 0 (transparent).

    Then you just need to set up the OpenGL blend modes correctly, and everything should work.

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

    Re: (Open GL, blit) Making a bitmap colour transparent

    In fact no, there is no function for this.
    Bit blit and transparent color index do not exist in OpenGL.

    These techniques are maybe 30 years old, and as explained in the introduction of the wikipedia page, _as been replaced by alpha compositing_ :
    http://en.wikipedia.org/wiki/Bit_blit
    Search about blending, alpha channel, etc.

  4. #4
    Member Contributor
    Join Date
    May 2012
    Posts
    51

    Re: (Open GL, blit) Making a bitmap colour transparent

    RGBA

    So I will have to manually read each pixel and change its bit value. However, I did some research by talking to people and have been told that "png" are the best file format to use since they support RGBA unlike bitmaps.

    Do any of you know a function I can use to load "png" files? Or loading in any image file format that supports rgba?

  5. #5
    Member Contributor
    Join Date
    Oct 2010
    Location
    Portage, MI
    Posts
    83

    Re: (Open GL, blit) Making a bitmap colour transparent


Similar Threads

  1. I need to make a specific pixel colour transparent
    By dusty in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-18-2011, 06:02 AM
  2. Making transparent tga files
    By girish3110 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 01-08-2008, 10:52 PM
  3. texturing from 8-bbp bitmap with colour tables
    By simonskid in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 09-28-2006, 01:42 PM
  4. Making Background Transparent
    By Soulreaver in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-16-2003, 06:48 AM

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