Results 1 to 5 of 5

Thread: how to make texture background transparent?

  1. #1
    Member Contributor
    Join Date
    Feb 2003
    Location
    china
    Posts
    60

    how to make texture background transparent?

    Hi,
    i have a question about the message below regarding how to draw a tree posted long time ago. After loading Bmp into my own structure allocated in mem and making changes to it, how do i bind this Bmp (to assign its ID)? anyone be so kind as to give me some detial? I only know assign ID with auxDIBImageLoad(Filename);
    Thanks


    ************************************
    generate an alpha channel to the tree.bmp so when the color is black the alpha value is 0 and else 255, then use blending with glBlendfunc(gl_src_alpha, gl_one_minus_src_alpha) or glAlphaFunc(GL_Greater,0.5)
    there are other ways, but try this first.

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: how to make texture background transparent?

    glGenTextures for id
    glBindTexture to bind the texture id with a target
    glTexImage to load the texture data to a target
    glTexParameter to change texture parameters
    glTexEnv to change texture environment parameters

  3. #3
    Member Contributor
    Join Date
    Feb 2003
    Location
    china
    Posts
    60

    Re: how to make texture background transparent?

    hi
    thanks for reply. But i didn't get what i wanted. Below is my code to convert RGB to RGBA. My question is after calling this, what should I do? I know how to load and bind a BMP without making any change to it.(now the converted "file" is in the memory).

    If anyone be so kind to answer, please give me such an answer/instruction that i know how to follow.
    Thanks

    typedef struct
    {
    GLubyte* colors;
    int width;
    int height;

    } Texture;

    void loadBitmap(char* filename, Texture* tex, int trans_color[3])
    {
    FILE* bmpfile;
    BITMAPFILEHEADER bmfileheader;
    BITMAPINFOHEADER bminfoheader;
    RGBTRIPLE rgb;

    int i,j,texpos = 0;

    bmpfile = fopen(filename, "rb");

    if (!bmpfile)
    exit(1);

    fread(&bmfileheader, sizeof(BITMAPFILEHEADER), 1, bmpfile);
    fread(&bminfoheader, sizeof(BITMAPINFOHEADER), 1, bmpfile);


    tex->width = bminfoheader.biWidth;
    tex->height = bminfoheader.biHeight;


    tex->colors = (GLubyte*)malloc(tex->width * tex->height *4);

    // read color
    for (i = 0; i < tex->width; i++)
    {
    for(j = tex->height - 1; j>=0 ; j--)
    { // is coord (1.0).
    fread(&rgb, sizeof(RGBTRIPLE),1,bmpfile);
    tex->colors[texpos] = rgb.rgbtRed ;
    tex->colors[texpos+1] = rgb.rgbtGreen;
    tex->colors[texpos+2] = rgb.rgbtBlue;

    //test if color should be transparent
    if ((rgb.rgbtRed==trans_color[0])&&(rgb.rgbtGreen==trans_color[1])&&(rgb.rgbtGreen==trans_color[2]))
    tex->colors[texpos+3] = 0;
    else
    tex->colors[texpos+3] = 255;

    texpos += 4;
    }

    }
    fclose(bmpfile);
    }

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Jan 2003
    Location
    Virginia
    Posts
    586

    Re: how to make texture background transparent?

    There isn't much difference. If you converted from GL_RGB to GL_RGBA then the format parameter you pass to glTexImage will be GL_RGBA instead of GL_RGB, and your internal format should also be GL_RGBA. Everythng else should probably be the same.

  5. #5
    Member Contributor
    Join Date
    Feb 2003
    Location
    china
    Posts
    60

    Re: how to make texture background transparent?

    hi

    I had just fixed it by searching some old message here before reading your reply. you are right, it's because my poor understanding of glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tex->colors);
    Thank you all

Similar Threads

  1. Blending - Make part of texture transparent?
    By SneakyArab in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 11-11-2010, 05:53 PM
  2. how to make background of opengl window transparent
    By aditya.sen in forum OpenGL ES
    Replies: 3
    Last Post: 11-30-2009, 02:55 AM
  3. Making black background transparent in RGB texture
    By alan e in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 06-29-2004, 02:57 PM
  4. Transparent background for texture mapped fonts
    By imported_sansan in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 12-09-2003, 01:08 AM
  5. How to make some color in texture transparent ?
    By jirkamelich in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-27-2002, 05:46 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