Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

dmatter

blending w/ vertex array

This topic is 5233 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 have an object stored with rgb color in a vertex array so I can render it using a single call. Now I want to be able to control the transparency of the entire object without having to loop through all vertices and change their color properties. How would I do this?

Share this post


Link to post
Share on other sites
Advertisement
just make that rgb a rgba, that will add Alpha to all your vertices. and you can use blending with that.



...

glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_COLOR_ARRAY );

glEnable(GL_BLEND);
glBlendFunc(...);

glVertexPointer( 3, GL_FLOAT, 0, ... );
glColorPointer( 4, GL_FLOAT, 0, ... );

glDrawElements( ... ); // or what ever meathod you want to draw the Vertex arrays

...
// disable stuff and all that good stuff




Edit: thought I would elaborate.

"I seek knowledge and to help those who also seek it"

[edited by - Xero-X2 on March 18, 2004 4:25:42 PM]

Share this post


Link to post
Share on other sites
Yes but does that allow me to change the alpha of the entire object? I mean like through one call or something?

[edited by - dmatter on March 18, 2004 4:30:30 PM]

Share this post


Link to post
Share on other sites
R u shur, it doesn't seem to work!?
I can change the alpha of every vertex and it works, but this isnt much of an option for my code.

[edited by - dmatter on March 18, 2004 4:44:23 PM]

Share this post


Link to post
Share on other sites
On OpenGL, the easiest way to get both specified colors and vertex colors to work together is to use COLOR_MATERIAL, and put the alpha into the ambient lighting term. You can enable lighting even if you don''t have a normal, and only use the alpha term to control opacity and color in that case.

In DirectX, the easiest way to do that is probably to write a shader that uses a parameter that modulates alpha, and change the parameter. DirectX puts a few API restrictions in the way of doing it using the fixed pipe the OpenGL way, which is why I recommend shaders in that case.

Share this post


Link to post
Share on other sites
I retract my previous statements, I was thinking of using it with textures not colors, sorry, the only way I can see of doing it use using a simple loop to alter the alpha channel on all the vertices.

"I seek knowledge and to help those who also seek it"

[edited by - Xero-X2 on March 18, 2004 4:58:18 PM]

Share this post


Link to post
Share on other sites
ok I found another way to do it, as long as you have a free texture slot you can use it instead.


// global varible
UINT translusent;

// in Init Stage
glGenTextures( 1, &translusent );

BYTE Alpha[256];
for ( int x = 0; x < 256; x++ )
Alpha[x] = x;

glEnable( GL_TEXTURE_1D );
glBindTexture( GL_TEXTURE_1D, translusent );
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP );
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP );
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexImage1D( GL_TEXTURE_1D, 0, GL_ALPHA, 256, 0, GL_ALPHA, GL_UNSIGNED_BYTE, Alpha );


// right before you draw the object
glEnable( GL_TEXTURE_1D );
glBindTexture( GL_TEXTURE_1D, translusent );
glTexCoord1f( Alpha );



This one works, its easy to impliment, the only problem with it is that it uses a texture slot, but I guess its not bad if you can afford to use one, or even if you aren''t using any textures then it would work quite well.

"I seek knowledge and to help those who also seek it"

Share this post


Link to post
Share on other sites
Suppose I wanted to texture the object with a different texture aswell, does this technique still work?

Share this post


Link to post
Share on other sites
If you need to use it with another texture you will need to use multitextureing to do it. but yes, you can just as easily do so.

"I seek knowledge and to help those who also seek it"

Share this post


Link to post
Share on other sites
Out of using the multitexturing alpha texture method and the COLOR_MATERIAL method, which one of the two is fastest/most efficient/yeild best results? Or would it actually be faster to just change the alpha of every vertex?

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!