problem about blending. need help...

Started by
15 comments, last by dimebolt 18 years, 8 months ago
Hello, i would like to draw a little picture under my models when they are selected. I render a terrain (based on a heightmap, triangle strip), then i draw a model. http://delfin.unideb.hu/~fazekaim/modelUnselected.jpg When I select the model with my mouse, i set the model selected, and i draw a little triangle strip (a little bit above the terrain). The result: http://delfin.unideb.hu/~fazekaim/modelSelected.jpg So, when i draw the selection triangle strip, with blending src_alpha, one_minus_src_alpha the terrain is blended to... What could be the reason of this problem? Thanks.
Advertisement
Could you clarify what the problem is, exactly? It doesn't seem like the image is blending with the terrain.
ok, when i draw the selection texture with it's triangle strip, i can see through the terrain (sky dome under the terrain). without the selection, the terrain is drawn well.
It sounds to me that you forget to disable blending again after drawing the selection strip. But without any code or screenshots of the problem, it is hard to tell...

Tom
i posted screenshots in the first post.
and code:

gl.glDisable( GL.GL_CULL_FACE);        gl.glEnable(GL.GL_TEXTURE_2D);        // binding texture        gl.glEnable( GL.GL_BLEND );        gl.glBlendFunc( GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA );                    gl.glBegin( GL.GL_TRIANGLE_STRIP );                // drawin triangle strip            gl.glEnd ();        gl.glDisable(GL.GL_BLEND);        gl.glDisable(GL.GL_TEXTURE_2D);        gl.glEnable( GL.GL_CULL_FACE);

Thanks.
I think I finally understand your problem. All translucent polygons must be rendered after all opaque polygons. What is happening currently is this:
  • Skybox is rendered.
    Depth testing & writing is probably disabled, so the depth buffer remains empty.

  • Model is rendered.
    The depth buffer is empty so the depth test passes for each pixel and values are written to the depth buffer.

  • Masked polygon is rendered
    The depth buffer contains nearer values in places, so the polygon is only rendered where it is nearer than the model. Values are written to the depth buffer.

  • Terrain is rendered
    The depth buffer contains nearer values is places, so the terrain is only rendered where it is nearer than both the model and the masked polygon. Values are written to the depth buffer.

If translucent polygons can overlap and you are not using additive blending then all translucent polygons must also be rendered in furthest-to-nearest order.

Enigma
Quote:Original post by fazekaim
i posted screenshots in the first post.


You indeed posted two screenshots, but no screenshot of the actual problem...

Quote:Original post by fazekaim
and code:
*** Source Snippet Removed ***
Thanks.


I do not believe the problem is in this part of the code. It seems perfectly fine. I don't have any experience with OpenGL in java though (assuming that this is java code).

Tom

Edit: Enigma is right. If your terrain is missing only under the triangle strip, then it is probably a sorting problem. I got the impression from your question that the entire terrain was blended (rather than missing).
thanks.
What does "additive blending" mean?
Quote:Original post by fazekaim
thanks.
What does "additive blending" mean?


That's when you use glBlendFunc(GL_SRC_ALPHA,GL_ONE) (i.e. in combination with glBlendEquation(GL_FUNC_ADD)).

It simply adds the color of a translucent object to the background. It is usually not a good way to represent translucent objects, but for highlights (such as your textured trianglestrip), it can actually be sufficient.

Tom
dimebolt, this posted pictures shows my problem: http://delfin.unideb.hu/~fazekaim/modelSelected.jpg

or if it's not good, what type of screenshot should i post?


my drawing order:

- sky - disabled depth as you wrote it well
- terrain - with depth and without blending
- model selection with blending
- model without blending

sorting problem? what can i do?

This topic is closed to new replies.

Advertisement