🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Blended and nonblended objects.

Started by
11 comments, last by Castor3d 24 years ago
I have modified the code from lesson 9 to the following. I have made the stars flow out like a fountain, and i have added a floor (quad) a bit below that. the stars happily bounce of the floor and finaly falling of, when they reach the side of the quad. The problem: The stars that fall of behind the floor shine through the floor, i can get this to stop if i enable GL_DEPTH_TEST, but that will only make the stars not become blended with eachother, they show up like a star mapped on a black polygon. I am not sure how to proceed with this.
Advertisement
It took me a while to figure that one out too, the problem with the blending when GL_DEPTH_TEST is enabled is that you are using (this is an educated guess) glBlendFunc( GL_SRC_ALPHA, GL_DST_ALPHA ), try using glBlendFunc( GL_SRC_ALPHA, GL_ONE ) it worked for me.

Morgan
I tried to do the change you suggested, but it did not help with solving the problem. The stars that bounce around still has the ''square'' that obscures the stars behind it.
You must disable zbuffer writing when you render your particles. I'm not sure how this is done with OGL, but it is probably something with glDisable().

Don't forget to enable it again as you render the floor.

- WitchLord

Edited by - WitchLord on May 23, 2000 8:58:19 AM

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

To disable Depth Test (Z Buffering) simply call
glDisable(GL_DEPTH_TEST);

This is used mainly when you want to draw something that have to be draw anyway in front of anything just like text or somethin like that.

To enable it againg simply call glEnable(GL_DEPTH_TEST);

If you disable the depth testing when rendering the particles you''re back where you started again with the stars showing through the quad. I got a sprite system to work where it draws the farthest sprites first and then the nearest and it works perfectly except when two sprites are so close to each other that they start clipping through each other when they rotate with the camera.
Can you not just disable blending while you render your floor?
EG:

glDisable(GL_BLEND);
glLoadIdentity();
glTranslatef(1.2f,0.0f,-5.0f);

glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();

glEnsable(GL_BLEND);
I tried to disable blendig for the floor and now the stars dont shine through the floor anymore, but the problem with the stars themselves still exist.

Is there a limit to the number of blended objects being on screen at the same time (i have 100 stars right now)? i am beginning to think that there is something very wrong woth the way i made this part of the code.

Is there any resource (except red and blue book) that describes blending and especially glBlendFunc fully?
Maybe the OpenGL superbible :o)
(you can find me on IRC : #opengl on undernet)
Castor3d:
LOL I went away after my post and tried that. I set up a cube with a blended star and could move the star behind or infront of the cube. I got as far as: At all times the star was properly blended( ie no black square), I could move it behind the box( blend off)and I could not see the star but could not see the star when moved in front of the box ( blending back on!). That was when the star had the box as a background. How odd, the blending still remained for the stars themselves but not the background.
All it'll be , I'm sure, is one dumb line needs to be shifted or something :-)

Edited by - stimpy on June 12, 2000 5:56:34 PM

This topic is closed to new replies.

Advertisement