Sign in to follow this  

[OpenGL] Draw transparent objects

This topic is 2549 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 am trying to draw transparent sphere and something inside it (obj model) but I cannot render it properly. I can do it in 2 ways :
a) disable depth test but then i see inside "walls" from my objects
renderSphere_convenient(0, 0, 0, 11, 10);
glDisable(GL_DEPTH_TEST);
DrawOBJ(head->m_iMeshID);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);

b)just render it normally but then nothing is rendered inside the sphere
renderSphere_convenient(0, 0, 0, 11, 10);
DrawOBJ(head->m_iMeshID);

any ideas how to do it properly ?

*void renderSphere_convenient(float x, float y, float z, float radius, int subdivisions)
that's prototype of funciton I use

Share this post


Link to post
Share on other sites
For transparency, mainly the order of drawing is important. Make sure you are drawing the sphere after the object you wish to have inside of it. This will work if you do not disable depth testing, since then only the side of the sphere in front of the object inside is drawn, as you would expect.

Also make sure you are using a blending function using the source alpha when drawing the sphere.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ignifex
Make sure you are drawing the sphere after the object you wish to have inside of it.

I have done that.

Quote:
Original post by Ignifex
This will work if you do not disable depth testing, since then only the side of the sphere in front of the object inside is drawn, as you would expect.

I've done that and now in the sphere's volume, objects rendered after the sphere are just cut ( they disappear in this area )


Quote:
Original post by Ignifex
Also make sure you are using a blending function using the source alpha when drawing the sphere.

Can you be more specific ? Maybe show me some code if you can ?

Share this post


Link to post
Share on other sites
First, draw all opaque objects. After that, start drawing transparent objects. If transparent triangles overlap other transparent triangles, you have to draw them sorted by distance. If one triangle intersects another, you might have to split those triangles and then draw them sorted by distance.

Share this post


Link to post
Share on other sites
Ok, but when I first draw opaque object, then my transparent sphere I can only see the opaque object and in the volume of sphere opaque objects drawn after that are cut.
Maybe I am using some kind of wrong blending-transparent functions, parameters ?

Share this post


Link to post
Share on other sites

This topic is 2549 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this