Advertisement

Cross Quads and blend problems

Started by September 01, 2004 12:08 AM
6 comments, last by snisarenko 20 years, 3 months ago
I'm rendering two crossed quads (one polygon intersects another at the middle point) and applying a grass texture on them to simulate a field of grass in real time. like this image: Im using glEnable(GL_BLEND) and glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) for the blend func. But as they are at the same level on Z buffer, I think opengl cant know who's first and the second one doesnt get the trasparency correctly. Im using a TGA 32-bit with alpha channel as textures. Anyone knows a solution for this? Thnxs in advance, Bruce Sinner [Edited by - brucesinner on September 1, 2004 10:47:54 AM]
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
try this:

glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
glEnable(GL_BLEND);

Draw();

glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
Advertisement
use alphatesting, and no semi transparent stuff, it's a good way of getting it right.
or you could stop using crossed quads, it doesn't work well like that.
Or render 4 quads sorted back to front.
You should never let your fears become the boundaries of your dreams.
Thnxs b3s3rk but didnt work well too :-(

i thought on using 4 quads but i think it could be done with two since i read bout this on chapter 7 of gpu gems where the author teachs how to move grass with vertex shaders and he says that one way of doing a big field of grass is making three crossed quads, forming a 'star'. But he dont explain the ogl stuff, only the shader part. But if he can do it, i can too! (perhaps i can) :-)

Im putting a link to my project, it is based on nehe_glut basecode i made, it only needs glut. The main stuff is in glutDisplay function. If anyone is willing to take a look i will appreciate too much the help.

Theres 4 grass textures, only change the CreateTexture call with grass_1 ... grass_4.tga.

Today I managed to put it working but with Alpha_Test and Alpha_func set to GREATER than 0.5. But it leads me to some nasty visual artefacts on the texture.

Project Link

Thnxs for the help folks,
Bruce Sinner
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
Quote: Original post by b3rs3rk
try this:

glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
glEnable(GL_BLEND);

Draw();

glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);


try this here i think that worked fine in on of my former engines

in the redbook third edition on page 226 they do it the same way just for a tree texture

glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
Draw();
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
http://www.8ung.at/basiror/theironcross.html
Advertisement
Quote: Original post by Basiror
Quote: Original post by b3rs3rk
try this:

glDepthMask(GL_FALSE);
glDisable(GL_CULL_FACE);
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
glEnable(GL_BLEND);

Draw();

glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);


try this here i think that worked fine in on of my former engines

in the redbook third edition on page 226 they do it the same way just for a tree texture

glDepthMask(GL_FALSE);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
Draw();
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);


Not good too. It does the transparency well but the second poly goes over the first... thanks anyway.
"Steel and Fire,Spreading the Holy Word,Dirty Liars,The truth has never been told" - Primal Fear
I am not sure, but aren't you supposed to turn the depth mask on, glDepthMask(GL_TRUE);, before you render the transparent polygons, and then turn it off ?

In other words transparent polygons should test the depth buffer but never write into it.

So i guess what you should try is

glDepthMask(GL_TRUE); <----------- first turn it on
glDisable(GL_CULL_FACE);
glBlendFunc(GL_ONE_MINUS_DST_COLOR,GL_ONE);
glEnable(GL_BLEND);

Draw();

glEnable(GL_CULL_FACE);
glDisable(GL_BLEND);
glDepthMask(GL_FALSE); <------- then turn it off

This topic is closed to new replies.

Advertisement