openGL, masking, alphas, & FOG

This is a discussion on openGL, masking, alphas, & FOG within the Game Programming forums, part of the General Programming Boards category; This is a gerneral question about how to handle transparentcy in OpenGL scenes where fog is enabled. Let's say I'm ...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    35

    Question openGL, masking, alphas, & FOG

    This is a gerneral question about how to handle transparentcy in OpenGL scenes where fog is enabled.

    Let's say I'm trying to create trees or some other complex object by first drawing a mask texture and then the image texture. With the mask texture, everything but the mask is completely transparent, so if I'm applying this texture to a quad, the quad's shape is completely invisible.

    Ditto for the image, where everything but the image is invisible, so you don't see the polygon it's applied to.

    This technique works fine with no fog -- the polygon is completely invisible and the effect looks good. But with fog enabled, the fog makes the polygon visible and the effect sucks. Does anyone know a technique for getting around this problem? I can turn off fog while I draw the image, but then that image isn't affected by the fog and so it looks stupid. What do the pros do?

    Would greatly appreciate suggestions or links to tutorials that deal with this issue.

    (Example of sliding texture on transparent quad...I'm just experimenting with the technique here, don't worry about what it's supposed to be...)

    Code:
     
       glEnable( GL_BLEND );
       glDisable( GL_LIGHTING );
    //   glDisable( GL_FOG );
       glDepthMask ( GL_FALSE );
       glMatrixMode( GL_TEXTURE );
       glPushMatrix();
          glTranslatef(0.0f, scroll, 0.0f);
    
       glMatrixMode( GL_MODELVIEW );
       glPushMatrix();
    
          glBindTexture( GL_TEXTURE_2D, texture[4] );                    //apply mask
          glShadeModel( GL_FLAT );
          glBlendFunc( GL_DST_COLOR, GL_ZERO );
          glBegin( GL_QUADS );
             glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 5.0f);
             glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.0f, 5.0f);
             glTexCoord2f(1.0f, 1.0f); glVertex3f(10.0f, 10.0f, 5.0f);
             glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f, 5.0f);
          glEnd();
    //   glEnable( GL_FOG );
          glBindTexture ( GL_TEXTURE_2D, texture[2] );                   //apply image
          glBlendFunc( GL_ONE, GL_ONE );
          glBegin( GL_QUADS );
             glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 5.0f);
             glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 10.0f, 5.0f);
             glTexCoord2f(1.0f, 1.0f); glVertex3f(10.0f, 10.0f, 5.0f);
             glTexCoord2f(1.0f, 0.0f); glVertex3f(10.0f, 0.0f, 5.0f);
          glEnd();
          glShadeModel( GL_SMOOTH );
    
       glPopMatrix();
    
       glMatrixMode( GL_TEXTURE );
       glPopMatrix();
    
       glMatrixMode( GL_MODELVIEW);
       glDisable(GL_BLEND);
       glDepthMask( GL_TRUE );
       glEnable( GL_LIGHTING );

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I posted a sticky thread located at the top of this forum. I'm confident that one of the provided links can help you with this problem.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Opengl masking problem
    By kaptenkraek in forum Game Programming
    Replies: 1
    Last Post: 03-14-2008, 12:26 PM
  2. OpenGL and 2D Masking
    By dxfoo in forum Game Programming
    Replies: 7
    Last Post: 03-08-2008, 12:00 PM
  3. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  4. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  5. OpenGL .dll vs video card dll
    By Silvercord in forum Game Programming
    Replies: 14
    Last Post: 02-12-2003, 06:57 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21