Skip to main content
gamedev.net
🔒 Locked

perspective/blending problem

Started by whuu 2 replies 700+ views
Original Post
whuu
whuu
Hi, i have problem with alpha blending & particles in my scene (i've created plane with smoke coming out from two side of its engine) so i start with this piece of code to init my scene init() { glEnable(GL_DEPTH_TEST); glPolygonMode (GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_TEXTURE_2D); //Load models, textures etc. } then i've got two functions: displaymodel() { glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glBindTexture(GL_TEXTURE_2D, obj.id_texture); glBegin(GL_TRIANGLES); //Display textured model glEnd(); } and displayParticle() { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glDisable(GL_DEPTH_TEST); glDisable(GL_COLOR_MATERIAL); glEnable(GL_BLEND); glBindTexture(GL_TEXTURE_2D,parid); glColor4f(0.5f,0.5f,0.5f,particle[loop].life); glBegin(GL_QUADS); //display particle glEnd(); glEnable(GL_COLOR_MATERIAL); glDisable(GL_BLEND); glEnable(GL_DEPTH_TEST); } and finally i render scene with: display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); displaymodel(); //move first particles emiter ot the right side of the model glTranslatef(-6.0,-9,6.5); displayParticle(); //move second particles emiter ot the left side glTranslatef(0.0,17,0); displayParticle(); //Rotate whole scene with glRotate(); glFlush(); glutSwapBuffers(); } My problem is when i render model first both particles emiters are above the model (despite one of them should be beneath it). When i render particles first and then i render the model when i rotate the scene i see particles only when they aren't on the model. I've read that i should render more transparent textures in the end and don't turn off GL_DEPTH_TEST (i do it in displayParticle() function) but if i do that particles aren't transparent and still aren't display correct. I know problem is with depth buffer but don't know how to solve it. Please help
Nitrogenycs
Nitrogenycs
Try adding a glDepthMask(GL_FALSE); somewhere in there. This will prevent writes to the depth buffer.
Nitrogenycs
Nitrogenycs
Basically it goes like this:

1. render model with depth write + test enabled
2. render particles with depth write disabled glDepthMask(GL_FALSE); and depth test enabled


whuu
whuu
thanks both of you i will try

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.