Results 1 to 6 of 6

Thread: Alpha Channel of texture

  1. #1
    Senior Member Regular Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    138

    Alpha Channel of texture

    Hi there,

    for 2 days i am trying to get a texture with aplha channel loaded, but i am not familiar enough with file formats to get it done.
    i tryed .raw, .bmp, .png but could never get my load_img() function work right.

    The best i could get was a whith spot where transparency should be... but i guess its because the .raw format does not support alpha channes ...



    i know there are libs out there that offer easy load of texture, but i wanne understand it...

    has anyone a example code that loads a .png file and uses alpha channes ... so i can use:
    Code :
     
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, png_data);

    thanx a lot
    uwi2k2
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    The OpenGL and VULKAN Podcast ( OpenGL2GO ) : OpenGL & Vulkan Podcast
    ---------------------------------------------------------
    timbling.com - Indie TeamUp

  2. #2
    V-man
    Guest

    Re: Alpha Channel of texture

    I would just use DevIL unless you have something against using a open source library. DevIL handles a lot of formats including png. It uses libpng under the hood.

    You can use libpng directly if you want but the API is ugly and requires a LOT of function calls. On the plus side, they have code examples so you can almost copy and paste. It is also a open source library.

  3. #3
    Senior Member Regular Contributor uwi2k2's Avatar
    Join Date
    Mar 2011
    Posts
    138

    Re: Alpha Channel of texture

    Thanx for the answer,

    but has nobody here done a texture with alpha channes ?
    or how does the 'data' need to look like that i pass to
    glTexImage2D() as the last parameter when i use GL_RGBA ?

    can someone give me a hint pls

    thx
    uwi2k2
    uwi2k2 - OpenGL Trainer: www.opengl-trainer.com
    ---------------------------------------------------------
    The OpenGL and VULKAN Podcast ( OpenGL2GO ) : OpenGL & Vulkan Podcast
    ---------------------------------------------------------
    timbling.com - Indie TeamUp

  4. #4
    Member Contributor
    Join Date
    May 2008
    Location
    USA
    Posts
    99

    Re: Alpha Channel of texture

    OpenGL doesn't have any functions to load textures from compressed formats. You could in theory open a raw RGBA type format - look for the NeHe tutorials, I think one does that.

    For something like PNG, you are best to use a library - especially if you may need multiple formats.

    But - was your initial code maybe OK? What should be showing through, if those are transparent objects, maybe it's white behind? Do you also have blending enabled properly?

    Bruce

  5. #5
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,676

    Re: Alpha Channel of texture

    OpenGL can read compressed formats. Just not typical image compression formats like PNG or JPEG. It uses S3TC/RGTC/BPTC.

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Alpha Channel of texture

    The simplest way to load a texture with alpha is to load .TGA files. HeNe give tutorials that show how to load such a file (which is basically a 12-byte header, followed by the raw data).
    glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data).

Similar Threads

  1. How to use single channel alpha texture?
    By hyppoo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-20-2017, 01:51 AM
  2. Last Try: Texture with alpha channel
    By uwi2k2 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 01-15-2012, 12:12 PM
  3. Update Texture Alpha channel
    By imported_clint3112 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-13-2011, 07:50 AM
  4. problem - texture with alpha channel
    By m3xican in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-10-2007, 04:55 AM
  5. Texture mapping with alpha channel on
    By in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-29-2003, 03:02 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