Archived

This topic is now archived and is closed to further replies.

ratt1233

Drawing a BMP but not a certain color.

Recommended Posts

ratt1233    148
What was the command for telling OpenGL NOT to draw a certain color? I saw it in the forums A long time ago, and without the search up I''m not paging throught the forums, I forget where it was posted as well....

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
Set the alpha of that portion to 0 and alpha test it

Share this post


Link to post
Share on other sites
Zorodius    259
Here''s some sample code that will process a texture to add in alpha channels and set them to zero wherever the texture has the color magenta. Do this before binding the texture with OpenGL, and turn on alpha testing when you go to draw with it.

  
// Insert an alpha channel into a 24-bit RGB color array.

unsigned char * InsertAlpha(unsigned char * image, BITMAPINFOHEADER * info)
{
int bytes, srcImageIndex;
unsigned char * newImage;
newImage = new unsigned char[info->biWidth * info->biHeight * 4];

bytes = info->biWidth * info->biHeight * 4;

srcImageIndex = 0;

// Copy the image data and insert an alpha byte.

for(int counter = 0; counter < bytes; counter += 4)
{
newImage[counter] = image[srcImageIndex];
newImage[counter + 1] = image[srcImageIndex + 1];
newImage[counter + 2] = image[srcImageIndex + 2];

srcImageIndex += 3;

// Use magenta for full transparency (because, well, who would EVER want to use magenta?)

if( newImage[counter] == 255 &&
newImage[counter + 1] == 0 &&
newImage[counter + 2] == 255)
{
newImage[counter + 3] = 0;
}
else
{
newImage[counter + 3] = 0xFF;
}
}

// Delete the old image and return the new one.

delete [] image;
return newImage;
}

Share this post


Link to post
Share on other sites
hansi pirman    122
If you mean to not draw the Red,Green or Blue Color Parts you may use glColorMask:

void glColorMask(
GLboolean red,
GLboolean green,
GLboolean blue,
GLboolean alpha
);

Set the Color you dant wanna draw do false, draw the BMP and then re-enable it

Share this post


Link to post
Share on other sites
Billy Lee    122
Zorodius''s function isn''t compatible with the NeHe texture loading routine. NeHe''s uses AUX_RGBImageRec but this one uses an array of chars. Is there a way to convert between the two?

Share this post


Link to post
Share on other sites
davepermen    1047
quote:
Original post by Billy Lee
Zorodius''s function isn''t compatible with the NeHe texture loading routine. NeHe''s uses AUX_RGBImageRec but this one uses an array of chars. Is there a way to convert between the two?


yes, use the array of chars in the AUX_RGBImageRec..

you should know programming before you start opengl..

but i remember i was in sort of the same situation.. not even able to go trough an array but coding triangles and all the shit..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites