Transparency blending with color - glBlend()

Started by
11 comments, last by okonomiyaki 20 years, 3 months ago
I have my clouds stored in the alpha channel of a texture. I have the shading of the clouds stored in the color (RGB) channels. In my skydome, each vertex has a color to color the sky. I want the texture to blend with the sky so that when the cloud texture's alpha is 0 full sky color is used but when it is 255 the cloud texture color channels are fully shown, and in between blends the color channels of the texture with the vertex color. Is there any way to do this with glBlendFunc()? I stared at all the parameters you could give it for a while but I'm afraid I don't quite understand how many of them work. [edited by - okonomiyaki on January 10, 2004 4:10:32 PM]
Advertisement
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
That doesn''t work. What that does is makes the skydome totally transparent when the texture''s alpha channel is 0, and when it''s 255 the texture blends with the vertex color. I want it so that when it''s 0 the skydome''s color is the vertex color and when it''s 255 the texture is totally opaque (doesn''t blend with the vertex color).
Imaging a skydome with sky coloring through vertices. Now I map a cloud texture onto it. That''s what I want it to look like.
I'm confused, which is drawn first, the skydome or the cloud texture? For alpha blending to work properly, the cloud texture must be drawn after the background sky has been put down.

Also, check to see if glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); doesn't do what you want. If it does, then your alpha channel is inverted from the norm.

A little pseudo-code couldn't hurt.

______________________________________________________________
The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ
MySite
______________________________________________________________

[edited by - Thunder_Hawk on January 10, 2004 4:35:39 PM]
______________________________________________________________________________________The Phoenix shall arise from the ashes... ThunderHawk -- ¦þ"So. Any n00bs need some pointers? I have a std::vector<n00b*> right here..." - ZahlmanMySite | Forum FAQ | File Formats______________________________________________________________________________________
If you''re trying to do what I think you are, you don''t want glBlendFunc. You want to use glTexEnv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) and you should set the texture''s internal format to GL_RGBA. You''ll also want to do glBlendFunc(GL_ONE, GL_ZERO) if you call glBlendFunc anywhere else.

Just to check, you are trying to texture your skydome with the cloud texture, while using the sky color as the vertex color, right?

For reference:
the color from the texture is Rt, Gt, Bt, At
the color from the polygon itself is Rf, Gf, Bf, Af
the color written to the frame buffer is Rv, Gv, Bv, Av
Using the settings above,
Rv = (1 - At) * Rf + At * Rt
Gv = (1 - At) * Gf + At * Gt
Bv = (1 - At) * Bf + At * Bt
Av = Af

quote:Original post by Thunder_Hawk
I'm confused, which is drawn first, the skydome or the cloud texture? For alpha blending to work properly, the cloud texture must be drawn after the background sky has been put down.

Also, check to see if glBlendFunc(GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA); doesn't do what you want. If it does, then your alpha channel is inverted from the norm.

A little pseudo-code couldn't hurt.




The skydome is drawn with vertices that have color and u,v texture mapping. So it's all drawn at once.
I'm wondering what parts of my code would be best to show. Here is my drawing code:
void sky::Draw() {	glTranslatef(0.0f,0.0f,-15.0f);	glRotatef(rot,-1.0f,0.0f,0.0f);	rot += 0.7f;	glBindTexture(GL_TEXTURE_2D, texture[0]);	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );	glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );	glBegin(GL_TRIANGLE_STRIP);	for (int i=0; i < NumVertices; i++)	{		glColor3f(Vertices[i].color&&0xFF0000>>16, Vertices[i].color&&0x00FF00>>8, Vertices[i].color&&0x0000FF);		glTexCoord2f(Vertices[i].u, Vertices[i].v);		glVertex3f(Vertices[i].x, Vertices[i].y, Vertices[i].z);	}	glEnd();}

And my blending setup as of now:
   	glEnable(GL_BLEND);	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


I appreciate your help Thunder Hawk! but I think Anthony is getting at what I want.

quote:
Just to check, you are trying to texture your skydome with the cloud texture, while using the sky color as the vertex color, right?

Yep!

Your equations look correct (at least what I want to happen).
I'm new to OpenGL (I have extensive DX experience though). When I try to use the function glTexEnv, I get a compilation error saying that it doesn't recognize the function. Is there another library I have to link to/include?
Currently I'm including:
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

and linking to:
opengl32.lib glu32.lib glaux.lib

I know I glaux is getting a little outdated
Any reason why it can't find the function? I couldn't find much around the internet.. or do I have old OpenGL libraries?
Thanks a lot!

[edited by - okonomiyaki on January 11, 2004 2:23:04 PM]

[edited by - okonomiyaki on January 11, 2004 2:23:53 PM]
http://www.3dlabs.com/support/developer/GLmanpages/gltexenv.htm

----------------
Amusing quote deleted at request of owner
----------------Amusing quote deleted at request of owner
I saw that, but I couldn''t find a place that helped me to find where/in what library it existed.
Oh, I''m an idiot. I had to add an ''i'' or ''f'' to glTexEnv. So it''s glTexEnvf(),
Thanks a lot ! That seems to do what I wanted. Though I don''t quite understand why, I''ll be doing some more research into glTexEnv. Thanks!
No problem. Glad I could help!

This topic is closed to new replies.

Advertisement