Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: bitmap: adding alpha channel

  1. #1

    bitmap: adding alpha channel

    hi, i want to load a bitmap and then
    add an alpha channel to enable blending later.
    heres my code:

    Code :
    isize = timage[0]->sizeX * timage[0]->sizeY; //get size
    *timage[1] = (struct _AUX_RGBImageRec*)malloc(sizeof(struct _AUX_RGBImageRec)); //reserver memory
    timage[1]->sizeX = timage[0]->sizeX; //copy width and height
    timage[1]->sizeY = timage[0]->sizeY;
    timage[1]->data = (unsigned char*)malloc((isize + (isize/3))); //reserve memory for data, old size + 1 channel
    	for(i=0, h=0 ; i<=isize ; i+=3, h+=4) //loop for copying and adding bytes
    	timage[1]->data[h] = timage[0]->data[i];
    	timage[1]->data[h+1] = timage[0]->data[i+1];
    	timage[1]->data[h+2] = timage[0]->data[i+2];
    		if(timage[0]->data[i]==0 &amp;&amp; timage[0]->data[i+1]==0 &amp;&amp; timage[0]->data[i+2]==255) //if color is blue
    		timage[1]->data[h+3] = 0; //set alpha to zero
    		timage[1]->data[h+3] = 255;
    glGenTextures(1, &amp;texture[0]);
    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, timage[1]->sizeX, timage[1]->sizeY, 0, GL_RGBA, GL_UNSIGNED_BYTE, timage[1]->data); //here it crashes :(((
    but it crashes at the glTexImage2D call and i dont know why ? if i load the RGB bitmap it works perfectly, where is my mistake ?

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2004
    Altheim, Germany

    Re: bitmap: adding alpha channel

    the third parameter of glTexImage2D has to be 1,2,3 or 4. In your case, try to change it to 4.

  3. #3

    Re: bitmap: adding alpha channel

    that doesnt change anything.
    did anybody do this before and could give me his code ?

  4. #4
    Member Regular Contributor CrazyButcher's Avatar
    Join Date
    Jan 2004

    Re: bitmap: adding alpha channel

    did it crash without you adding alpha ?

    btw the 1,2,3,4 thing is obsolete (still working so), GL since 1.2 allows quite some more internal formats.

  5. #5

    Re: bitmap: adding alpha channel

    yes it does

  6. #6

    Re: bitmap: adding alpha channel

    i think i located the error
    isize = timage[0]->sizeX * timage[0]->sizeY * 3;

    i forgot the "* 3", but there are 3 bytes per pixel so its necessary (sorry please dont kill me im new to opengl and programming)

    thanks for all who posted

Posting Permissions

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