Jump to content
  • Advertisement
Sign in to follow this  
bballmitch

OpenGL White space in a .bmp

This topic is 4439 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

A friend of mine made an aimer for my FPS and its saved as a .bmp file. It looks great and everything, but there's one problem. It's 64x64 and the aimer is in the middle, but there is a bunch of white space that fills up the rest of the bitmap. So when I load and draw the bitmap in OpenGL, the aimer gets drawn, but unfortunatly, so does the white space. I want just the aimer itself, and no white space out side of the aimer, or on the inside of the aimer. How do I take care of this?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
go in photoshop
make 1 layer that is black.
and the other layer should be the white bitmap.
set the layer which holds the aimer then switch the blending mode to either darken or multiply. what this will do is remove the white and let the black show. the results may not be great but what you want is a black background bitmap and the aimer any other color then you would render it with additive blending mode. another thing you can do is in photoshop create an alpha mask by opening up the bitmap and making a new document then paste the bitmap into a layer then in the channels tab create a new channel. white is solid, black is invisible in the alpha channel and you would then create a mask.

Share this post


Link to post
Share on other sites
i think he wants to know how to draw aimer in OpenGL using alpha ... i dont know :D

Share this post


Link to post
Share on other sites
You're going to want to add an alpha channel to the aimer image. With this alpha channel, you can set the OpenGL blending equation to get the desired effect. Look up the manpage for glBlendFunc or (probably better) the Red book for more detailed info.

Share this post


Link to post
Share on other sites

BITMAPINFOHEADER bitmapInfoHeader2;
unsigned char *bitmapData2;

int InitGL(GLvoid)
{
.
.
.
bitmapData2 = LoadBitmapFile("MitchReticle.bmp", &bitmapInfoHeader2);
.
.
.
}

int DrawGLScene(GLvoid)
{
.
.
.
glPushMatrix();
glColor3f(1.0,1.0,1.0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 6);
glRasterPos3f(0,0,-2);
glDrawPixels(bitmapInfoHeader2.biWidth, bitmapInfoHeader2.biHeight, GL_RGB, GL_UNSIGNED_BYTE, bitmapData2);
glPopMatrix();
.
.
.
}




There's the code relevant to the .bmp file. He changed the alpha value in photoshop so that it would be transparent, but it didn't do anything. What should I add to this code so that only the relevant area in the .bmp file is shown?

Share this post


Link to post
Share on other sites
If you want to use a bitmap, you can write your own bitmap loader and for every white pixel you encounter, set the opacity of the texture to 0x00. Set it to 0xFF for any other.

Then just do an alpha test.

Share this post


Link to post
Share on other sites
Hey check out this tutorial from nehe. I think it has what you need
clickey

this is just the page for the tutorial, if you look at the screen shot you should see if it fits your needs. BTW, it tutorial 20 - masking
screen #20

I've used this technique before so if you need any specific help just ask

Share this post


Link to post
Share on other sites
Quote:
Original post by bballmitch
*** Source Snippet Removed ***

There's the code relevant to the .bmp file. He changed the alpha value in photoshop so that it would be transparent, but it didn't do anything. What should I add to this code so that only the relevant area in the .bmp file is shown?
I think the part that's really relevant to the BMP file loading is the code for the LoadBitmapFile function.

Aside from that, BMP files don't support images with an alpha channel so you will either have to use a format that does (such as TGA or PNG) or use color-key transparency, which is what RuneLancer suggested.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!