[OpenGL/MFC/C++] backface transparency...
-
(OpenGL on vs2008) I'm drawing surfaces, not volumes. the issue is corruption (or maybe PEBKAC) when displaying "blended" (transparent) I don't seem to understand how the surface must be "setup" to obtain full surface transparency on both the front side and back side. I have something like :
::glReadBuffer( GL_BACK );
::glDrawBuffer( GL_BACK );
::glDepthFunc( GL_LESS );
::glEnable( GL_DEPTH_TEST );// init.
glPolygonMode ( GL_FRONT, GL_FILL );
glPolygonMode ( GL_BACK, GL_FILL );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
glDepthMask( GL_FALSE );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );glColor4ub( red, green, blue, alpha ); //valid values.
// draw the cone (render triangles)...// cleanup...
glDisable( GL_BLEND );
glDepthMask( GL_TRUE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );When using this code, there are some corruption in the display, surface "patches" are not rendered appropriately when displaying against "itself", for example a front facing polygon of a cone or cylinder which is displayed against a back" face of the same cone or cylinder. see images showing the issue: simple cylinder : http://www.flickr.com/photos/thesorus/5346534862/in/photostream/[^] and a cone, a sphere and a plane. http://www.flickr.com/photos/thesorus/5345924155/in/photostream/[^] Max. Thanks.
Watched code never compiles.
-
(OpenGL on vs2008) I'm drawing surfaces, not volumes. the issue is corruption (or maybe PEBKAC) when displaying "blended" (transparent) I don't seem to understand how the surface must be "setup" to obtain full surface transparency on both the front side and back side. I have something like :
::glReadBuffer( GL_BACK );
::glDrawBuffer( GL_BACK );
::glDepthFunc( GL_LESS );
::glEnable( GL_DEPTH_TEST );// init.
glPolygonMode ( GL_FRONT, GL_FILL );
glPolygonMode ( GL_BACK, GL_FILL );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
glDepthMask( GL_FALSE );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );glColor4ub( red, green, blue, alpha ); //valid values.
// draw the cone (render triangles)...// cleanup...
glDisable( GL_BLEND );
glDepthMask( GL_TRUE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );When using this code, there are some corruption in the display, surface "patches" are not rendered appropriately when displaying against "itself", for example a front facing polygon of a cone or cylinder which is displayed against a back" face of the same cone or cylinder. see images showing the issue: simple cylinder : http://www.flickr.com/photos/thesorus/5346534862/in/photostream/[^] and a cone, a sphere and a plane. http://www.flickr.com/photos/thesorus/5345924155/in/photostream/[^] Max. Thanks.
Watched code never compiles.
To achieve real transparency at a fast rate is hard. To get exact picture , you need to sort triangles from back to front , based your camera vector. Also sometiems , if triangles overlap , you need to splitup it. The best way to do this is by implementing BSP tree. Using that you can do both front-to back or back-to-front rendering. I would suggest you to look into that first. In general for a scene , i do like this ( for fake transparency ) 1. Render all opaque objects 2. Sort triangles based on their material transparency. 3. Draw triangles which having lesser transparency level first followed by others. :)
If u can Dream... U can do it
-
(OpenGL on vs2008) I'm drawing surfaces, not volumes. the issue is corruption (or maybe PEBKAC) when displaying "blended" (transparent) I don't seem to understand how the surface must be "setup" to obtain full surface transparency on both the front side and back side. I have something like :
::glReadBuffer( GL_BACK );
::glDrawBuffer( GL_BACK );
::glDepthFunc( GL_LESS );
::glEnable( GL_DEPTH_TEST );// init.
glPolygonMode ( GL_FRONT, GL_FILL );
glPolygonMode ( GL_BACK, GL_FILL );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE );
glDepthMask( GL_FALSE );
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );glColor4ub( red, green, blue, alpha ); //valid values.
// draw the cone (render triangles)...// cleanup...
glDisable( GL_BLEND );
glDepthMask( GL_TRUE );
glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE );When using this code, there are some corruption in the display, surface "patches" are not rendered appropriately when displaying against "itself", for example a front facing polygon of a cone or cylinder which is displayed against a back" face of the same cone or cylinder. see images showing the issue: simple cylinder : http://www.flickr.com/photos/thesorus/5346534862/in/photostream/[^] and a cone, a sphere and a plane. http://www.flickr.com/photos/thesorus/5345924155/in/photostream/[^] Max. Thanks.
Watched code never compiles.
Did you try
glDepthFunc( GL_ALWAYS )
? Basically allowing all pixels to be drawn. I think that might work rather thanglDepthFunc( GL_LESS )
andglDepthMask( GL_FALSE );
"It was when I found out I could make mistakes that I knew I was on to something." -Ornette Coleman "Philosophy is a study that lets us be unhappy more intelligently." -Anon.