Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Graphics
  4. [OpenGL/MFC/C++] backface transparency...

[OpenGL/MFC/C++] backface transparency...

Scheduled Pinned Locked Moved Graphics
c++graphicscomgame-devhelp
3 Posts 3 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Maximilien
    wrote on last edited by
    #1

    (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.

    J P 2 Replies Last reply
    0
    • M Maximilien

      (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.

      J Offline
      J Offline
      jk chan
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • M Maximilien

        (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.

        P Offline
        P Offline
        parths
        wrote on last edited by
        #3

        Did you try glDepthFunc( GL_ALWAYS )? Basically allowing all pixels to be drawn. I think that might work rather than glDepthFunc( GL_LESS ) and glDepthMask( 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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups