Archived

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

dmatter

blending w/ vertex array

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
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
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
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
well

Using Color_Material mode would probobly be quite hefty because of invoking lighting, I think, anyone know if this would be just like using standard lighting as far as preformance hit? causing the GPU to have a heavier load in any case. worse case, would prolly be High vertice count.

Textureing with a 1d texture is pretty light load I would belive, multitextureing is usually very quick in my experiences. That will increase the load on the Gpu the same as option 1. worst case would be, if it where to take up a large number of pixels being drawn. the more pixels the wrose

Changing the alpha per vertex is the duty of cpu, it could get pretty hefty if you need to do tons of vertices and or multiple models. Also this would prevent faster VBO's if you where to use them or Compiled vertex arrays, that is if you wanted to use. worse case would be High vertice count.

I can't say for certain whihc would be the best, as far as over all speed goes.

If I would make the desision I would use the texture meathod, but thats just me. Perhapes some one else has an opinion?

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

Edit: Typos and such

[edited by - Xero-X2 on March 19, 2004 9:48:20 PM]

Share this post


Link to post
Share on other sites