Jump to content
  • Advertisement
Sign in to follow this  
mpledge52

Transparency, alpha?

This topic is 3787 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

I would like to make one of my objects on screen appear slightly transparent, I've had a quick look and it seems that you can do this using blending and alpha channels. Is it difficult to set up and make things transparent? I've already coded my solution but it uses simple RGB valaues without the 4th alpha value, will I need to change everything or is it a simple case of changing a few values? If it doesn't involve a horrendous amount of changes, could someone point me in the direction of a tutorial or something similar that explains how to acheive such effects (in novice speak lol)? Thanks very much.

Share this post


Link to post
Share on other sites
Advertisement
Well if you only want your texture to be transparent (everywhere the same transparency (uniform)) you can just use the blending function: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) and don't forget to put blending on: glEnable(GL_BLEND). Then before drawing your object you can adjust alpha with glColor4f(1.0,1.0,1.0,0.5), where the last value is used for alpha and in this case it would mean 50% transparency.
Also if you are using depth, you will need to draw objects that are in the back first and then advance forward.

You will need a 4th alpha value if you wish to map a texture on a quad for example, but want to have some parts of it fully transparent. Or when you wish to have different transparency values over your texture. I'm using TGA files for this and I quite like the TGATOOL2 program I found somewhere on the internet.

But again: if you only need uniform transparency then keep it easy and use glColor4f to set your transparency.

Hope that helped you.

Share this post


Link to post
Share on other sites
And don't forget: glutInitDisplayMode(GLUT_RGBA | ...);

During Init i do the following (as Kamos already mentioned)
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

Share this post


Link to post
Share on other sites
hi

you can use GL_EXT_blend_color extension, for transparent an object which dosnt have alpha channel ( sorry for bad en)

Share this post


Link to post
Share on other sites
Thanks very much for the help, I've got it working now. I have another question though, it's easier to see from the picture:

image

As you can see, what I am trying to do is make the plane (yes that is supposed to be a plane, I'm using a practice model atm!!) partly transparent so you can still see the terrain through it. The problem is that some parts are more transparent than others, despite having the same alpha values. I'm guessing this is because there are multiple layers in some places but not in others, i.e. the plane 'hull' is constucted of a cylinder so you look through 2 faces, whereas the wing is simply a 2d quad so it is twice as easy to see through.

I've tried making the wings twice as transparent as the hull which makes it the same colour, but there are still areas where, depeneding on the camera position, you can be looking through 1, 2, 3, 4 or evn 5 layers. So it never looks like it all has the same transparency.

Is there anyway I can get round this?

Thanks again.

Share this post


Link to post
Share on other sites
You should enable back-face culling to ensure only the side of the cylinder facing the viewer is drawn. That will work as long as your mesh does not have overlapping objects (but the "wings" should be double to be 2-sided). If it is a more complex mesh, you should first render the mesh with z-buffer writes enabled, but colour buffer writes disabled. This fills in the z-buffer with the depth information for the entire mesh. Then you render the mesh again with colour buffer writes enabled. This will makes sure that only the outside of the mesh is drawn (even if you have intersecting triangles, the inside part will not be drawn because it will be discarded at the z-test stage).

Edit: I can't spell.

[Edited by - Kippesoep on February 7, 2008 8:53:53 AM]

Share this post


Link to post
Share on other sites
Thanks Kippesoep. It looks better - it all has equal transparency now, one slight problem though is that it chops off one of my plane's wings!

I think this is probably to do with what you mentioned about using depth testing snoutmate, however if I set glDepthFunction to GL_EQUAL or any other valid parameter all I get is a blank screen. Any ideas why this is? I've enabled glEnable(GL_CULL_FACE) and glEnable(GL_DEPTH_TEST)???

Thanks again :)

Share this post


Link to post
Share on other sites
If a wing is simply missing then it's probably wound in the wrong direction for back-face culling, for the wing that's disappeared try reversing the order you specify its vertices.
Back-face culling (in GL at least) checks whether you've wound your polygon in a clockwise or anticlockwise direction from the camera's perspective and culls it accordingly.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!