I tried to render some impacts on my walls. I use an image with an alpha channel for the texture of the impacts.I want to use blending to draw the impacts onto the walls. I tried to do it as below:
public final void init(GLAutoDrawable drawable){
…
gl.glBlendFunc(GL.GL_ONE,GL.GL_ZERO);
}
public final void display(GLAutoDrawable drawable){
…
//bind the texture of the walls
//draw the walls
gl.glEnable(GL.GL_BLEND);
//bind the texture of the impacts
//draw the impacts
gl.glDisable(GL.GL_BLEND);
}
It doesn’t work very good. Sometimes, the effect is fine and often the impact is flickering. erikd told me that it comes from a problem called Z-Fighting. How can I do to solve this? I would like an impact on a wall to have the same value in the z-buffer than the wall itself and then use blend functions to replace all the wall texture pixels by the opaque texture pixels of the impact. I looked at glPolygonOffset, glTexEnvf, glBlend but I don’t know what to do now. Does anyone have an idea?