Forum > OpenGL
32bit (transparent) color in OpenGL control component?
Peiman:
Hi,
I am a newbie in OpenGL. I have started with TOpenGLControl component. I wonder whether I can draw "transparent" surfaces with it similar to 2D gdi+ by changing the 4th byte of the color (alpha)?
Carver413:
yes it is possible. how you go about it depends on whether you are using old opengl or new. most likely you are using old since lazarus doesn't implement any new code. check out
http://nehe.gamedev.net/
http://www.pascalgamedevelopment.com/
Lazarus doesn't do much in the way of opengl.
I am working on some modern code but haven't got a real transparency shader yet. just one that clips transparent bits from view. if your planing to display a bunch of 3d objects with transparency this can get quite difficult do to the limitations of opengl. I guess it messes up the Z buffer and things might not turn out the way you would expect.
Carver413:
digging through some of my old code I think this is what your looking for
--- Code: --- glBindTexture(GL_TEXTURE_2D, Font.Texture);// bind the texture
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);// set the blend mode
glEnable(GL_DEPTH_TEST);//turn on depth testing
glEnable(GL_BLEND);// turn on blending
--- End code ---
you must use a RGBA texture and this code is useless if your using a shader. if your not using a texture then I guess you would set the alpha in
--- Code: ---glColor4f(1.0,0.7,0.3,0.5);
--- End code ---
Peiman:
Thanks all,
I found this on http://www.opengl.org/resources/faq/technical/transparency.htm:
--- Code: ---glEnable (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
--- End code ---
The only important thing is that after this you should never use glcolor3* function.
User137:
You can still use glColor3* functions, they will work normally. It is basically exactly same thing as glColor4f(r, g, b, 1). As you see it will always set color alpha to fully visible, but it doesn't disable transparency from the texture alpha channel itself.
Navigation
[0] Message Index
[#] Next page