View Full Version : Transparent Polygon
05-30-2008, 03:00 PM
This is a more an OpenGL related question. I have a custom layer that renders polygons using OpenGL primitives. I´m trying to make this polygons semitransparent so terrain is visible. Anybody have a clue?
05-30-2008, 03:16 PM
// Enable transparency
Make sure your polygon is rendered after whatever is obscured by it.
Its transparency is based on the alpha value of the polygon's color.
05-30-2008, 03:25 PM
Note that for OGL textures, you should use GL.GL_ONE instead of GL.GL_SRC_ALPHA. This has to do with pre multiplied alpha blending - which is a source of confusion... See Texture's javadoc (http://download.java.net/media/jogl/builds/nightly/javadoc_public/com/sun/opengl/util/texture/Texture.html). Not sure how it impacts polygons though.
05-30-2008, 03:28 PM
I´ve already tried that.
I set the color this way:
gl.glColor4ub((byte)Color.RED.getRed(), (byte)Color.RED.getGreen(), (byte)Color.RED.getBlue(), (byte)100);
All I get is a darker red polygon, but no transparency.
05-30-2008, 03:50 PM
Are you sure your polygon isn't being drawn too early?
If it's drawn first and updates the depth buffer, anything underneath it will get culled.
You can try gl.glDisable(GL.GL_DEPTH_TEST) while drawing your polygons, though I don't know if that is a good final solution for you or not.
05-30-2008, 04:00 PM
You can also try:
// Apply the depth buffer but don't change it.
05-30-2008, 06:07 PM
You may know this, so I apologize if you do.
To get nice transparency you have to use "lighter" shades of colors as well. So like a red value of 10-50 will do a _much_ nicer transparency than a red of 255. Each color set behaves the same way, using dimmer colors results in better transparency.
Using high alpha, like 255 and dim colors like 10-50 for each of r g and b results in the best effects. Maxing out any one channel of r,g or b seems to ruin transparency somewhat.
05-30-2008, 06:09 PM
Doesn't SurfaceQuad support alpha? I have screen shots during my development using a transparent SurfaceQuad...
12-08-2008, 03:38 AM
Hi Nick, did the sufacequad shape turn out a little bit blurry on the outline, or was it with a perfectly sharp outline (border)?
12-08-2008, 09:57 AM
Be aware that the initial question for this thread is about polygon transparency/blending using gl primitives. The actual surface shape implementation uses textures - which become somewhat blurry when you zoom too close, but do support transparency too. This is a different issue.
vBulletin® v3.7.1, Copyright ©2000-2013, Jelsoft Enterprises Ltd.