• Advertisement
Sign in to follow this  

problem about blending. need help...

This topic is 4589 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Could you clarify what the problem is, exactly? It doesn't seem like the image is blending with the terrain.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
OK, some more questions:
  1. Do you clear the depth buffer at the start of each frame?

  2. Does your "selected unit" texture actually have an alpha layer?

Enigma

Share this post


Link to post
Share on other sites
1. Do you clear the depth buffer at the start of each frame?
yes.
using this: gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT );


2. Does your "selected unit" texture actually have an alpha layer?
yes. i created with gimp2.
the rgb layer is a white/black picture. The alpha is the same, created with "adding alpha layer from colors.

Share this post


Link to post
Share on other sites
Can you post glTexImage2D call where you upload the texture to OpenGL?

Enigma

Share this post


Link to post
Share on other sites
gl.glGenTextures( 1, tmp );
gl.glBindTexture( GL.GL_TEXTURE_2D, tmp[0] );
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR);

glu.gluBuild2DMipmaps(
GL.GL_TEXTURE_2D,
GL.GL_COMPRESSED_RGBA_ARB,
loader.getImageWidth(), loader.getImageHeight(),
GL.GL_RGBA,
GL.GL_UNSIGNED_BYTE,
loader.getTexture()
);

I cut the terrain into fragments. it's a tree actually. I draw a terrain piece then every object on the terrain.
Could be te reason of the problem, that i draw the model before the neighbour terrain piece is drawn?

Share this post


Link to post
Share on other sites
Can you try hacking your code, something like:
int pass = 0;

void yourRenderingFunction()
{
// some code
if (pass == 0)
{
// draw your skybox, terrain & models
}
else
{
// draw your selection triangle strip
}
// some code
}

void yourRenderLoop()
{
// some code
pass = 0;
// do your rendering
pass = 1;
// do your rendering again
// some code
}


That should tell you for certain whether it's a draw order problem or not.

Enigma

Share this post


Link to post
Share on other sites
It was a tree rendering problem.
I rendered a terrain piece and the models on it before the terrain pieces in the neighbour area. So, it was depth problem.

I rewritten the tree rendering code, now the rendering method pass from level to level.

I'm very grateful to Enigma, and dimebolt. Thanks a lot!

Share this post


Link to post
Share on other sites
Quote:
Original post by fazekaim
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?

Sorry, man. I really should start reading posts better. You did post the right screenshot... I thought the one you posted was the textured triangle strip without blending: Confusion++

Tom

Edit: good thing you solved it anyway :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement