Sign in to follow this  
clearly

OpenGL blending problem

Recommended Posts

Go to Photoshop and open the tank texture u load from in it, anyway if the tank texture u are loading from is of jpg format, u definitely don't have an alpha channel. Look at the channels, you should see RGBA, where in the A u will see the alpha channel, if u don't see a tank shape in white in the A channel, u don't have a mask of the tank.

Only file formats like PNG, TGA can contain alpha channels.

Share this post


Link to post
Share on other sites
If you are using .bmp then you dont have an alpha channel. they are RGB only.

.TGA or .png are good image formats, both have lossless compression and support for alpha channels. I recommend you get yourself a copy of the Gimp, this allows you to create images with transparency and to save them in a wide range of formats.

There is alot of .tga and .png file loading code out there. Search the forums and you'll find what you need!

- Al

Share this post


Link to post
Share on other sites
As for the mask method, what that does is draws your tank in black (just the tank, not the rest of the texture), then you need to draw your tank over the top with additive blending. That will make it look like you tank is solid, and ontop of the grass. And is probably the simpler approach if you are new to coding and graphics apps.

As for the code I gave you all the code there, the blending functions are the important bit, you just needed to combine that with your existing code and create the mask image like I said.

This is what you (should) have ended up with.


glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

glLoadIdentity(); // background
glBindTexture(GL_TEXTURE_2D, texture[7]);
glColor3f(1.0f,1.0f,1.5f);
glTranslatef(0.0f,0.0f,-98.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-50.0f, -50.0f, -2.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f( 50.0f, -50.0f, -2.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f( 50.0f, 50.0f, -2.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-50.0f, 50.0f, -2.0f);
glEnd();

glEnable(GL_BLEND);

// Set the blending mode to Masking, all black pixels on the image
// will appear black on the image, all white will appear transparent
glBlendFunc(GL_DST_COLOR,GL_ZERO);

glLoadIdentity(); // the tank mask
glBindTexture(GL_TEXTURE_2D, texture[XXXXXXX]); <--- you need to load the mask image with your other ones and use that here
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(x2rot,y2rot,-49.0f); //-39
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-7.0f, -7.0f, 5.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f( 7.0f, -7.0f, 5.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f( 7.0f, 7.0f, 5.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-7.0f, 7.0f, 5.0f);
glEnd();

// Set blending to additive mode
// This adds the incoming colour to the current colour, so the pixels
// of the tank will be added to the black area created by the mask
// and the black pixels in the tank texture (0,0,0) when added cause
// no effect!
glBlendFunc(GL_ONE, GL_ONE);
glLoadIdentity(); // the tank
glBindTexture(GL_TEXTURE_2D, texture[4]);
glColor3f(1.0f,1.0f,1.0f);
glTranslatef(x2rot,y2rot,-49.0f); //-39
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex3f(-7.0f, -7.0f, 5.0f);
glTexCoord2f(1.0f, 0.0f);glVertex3f( 7.0f, -7.0f, 5.0f);
glTexCoord2f(1.0f, 1.0f);glVertex3f( 7.0f, 7.0f, 5.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-7.0f, 7.0f, 5.0f);
glEnd();

As I said before you will need to create yourself a mask texture. Just copy the tank texture and make all the pixels you want to see, black, and all the pixels you dont white.

- Al

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this