Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Lightmap blending not working?

  1. #1
    Guest

    Lightmap blending not working?

    Hi, i've read a few things on lightmaps and how to blend them and they say to do this:

    glBlendFunc( GL_ONE, GL_ZERO );
    render lightmap
    glBlendFunc( GL_DST_COLOR, GL_ZERO );
    render textures

    but i tried that, and all i see is the lightmaps on the screen... can anyone help me out with what i may be doing wrong? i'm going insane, it doesn't make any sense why it's not blending...

    some code:
    Code :
     
    void GamePlay :: drawLeaf ( int index )
    {
    	for( int i = 0; i < bsp.bsp_leafs[ index ].n_leaffaces; i++ )
    	{
    		BSP_Face & currFace = bsp.bsp_faces[ bsp.bsp_leaffaces[ bsp.bsp_leafs[ index ].leafface + i ].face ];
     
    		glEnable( GL_BLEND );
     
    		glColor4f( 1, 1, 1, 1 );
    		glBlendFunc( GL_ONE, GL_ZERO );
     
    		glBindTexture( GL_TEXTURE_2D, textureArray[ bsp.texturesDirEntry.numElements + currFace.lm_index ] );
    		glBegin( GL_TRIANGLES );
    			for( int j = 0; j < currFace.n_meshverts; j++ )
    			{
    				glTexCoord2fv( bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].texcoord[ 1 ] );
    				glVertex3f( bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 0 ],
    							bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 2 ],
    							bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 1 ] );
    			}
    		glEnd( );
     
    		glColor4f( 1, 1, 1, 1 );
    		glBlendFunc( GL_DST_COLOR, GL_ZERO );
     
    		glBindTexture( GL_TEXTURE_2D, textureArray[ currFace.texture ] );
    		glBegin( GL_TRIANGLES );
    			for( int j = 0; j < currFace.n_meshverts; j++ )
    			{
    				glTexCoord2fv( bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].texcoord[ 0 ] );
    				glVertex3f( bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 0 ],
    							bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 2 ],
    							bsp.bsp_vertexes[ bsp.bsp_meshverts[ currFace.meshvert + j ].offset + currFace.vertex ].position[ 1 ] );
    			}
    		glEnd( );
     
     
    	}
    }
     
    void GamePlay :: genTexs ( )
    {
    	Tga24Bit	tgaTemp;
    	string		strTemp;
     
    	glEnable( GL_TEXTURE_2D );
     
    	textureArray = new GLuint [ bsp.texturesDirEntry.numElements + bsp.lightmapsDirEntry.numElements ];
    	glGenTextures( bsp.texturesDirEntry.numElements + bsp.lightmapsDirEntry.numElements, &amp;textureArray[ 0 ] );
     
    	for( int i = 0; i < bsp.texturesDirEntry.numElements; i++ )
    	{
    		strTemp = "";
    		strTemp += bsp.bsp_textures[ i ].name;
    		strTemp += ".tga";
    		tgaTemp.loadTGA( strTemp.c_str() );
     
    		glBindTexture( GL_TEXTURE_2D, textureArray[ i ] );
    		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
     
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
     
    		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, tgaTemp.width, tgaTemp.height, 0, GL_RGB, GL_UNSIGNED_BYTE, tgaTemp.imageData );
     
    		tgaTemp.releaseData( );
    	}
     
    	for( int i = 0; i < bsp.lightmapsDirEntry.numElements; i++ )
    	{
    		glBindTexture( GL_TEXTURE_2D, textureArray[ bsp.texturesDirEntry.numElements + i ] );
    		glPixelStorei( GL_UNPACK_ALIGNMENT, 1 );
     
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
    		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
    		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
     
    		glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, bsp.bsp_lightmaps[ i ].map );
    	}
     
    }

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Berlin, Germany
    Posts
    188

    Re: Lightmap blending not working?

    You're drawing the same geometry twice. The second pass will generate the same depth values as the first. With enabled depth test and the default depth test function (GL_LESS), the second pass will be completely discarded. You have to change your depth function to GL_LEQUAL (for both passes) or GL_EQUAL (for the second pass). Or use a polygon offset to increase the depth values for the second pass.

    A much better solution, if available, though, is to use multitexturing. Because you need only one pass and no blending. The first texture unit uses the color texture, and the second unit the lightmap with GL_MODULATE.
    355/113 -- Not the famous irrational number PI, but an incredible simulation!

  3. #3
    Guest

    Re: Lightmap blending not working?

    ahh that worked great for the blending, thanks! i tried to use the ARB multitexture extension but wouldn't link in Dev-C++.

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jul 2005
    Location
    Berlin, Germany
    Posts
    188

    Re: Lightmap blending not working?

    On windows, you generally can't use extension functions directly. You have to setup function pointer variables for the functions, and acquire the real entry point from the context via wglGetProcAddress or a similar function. Or use a helper library like GLEW to handle all the nasty details.
    355/113 -- Not the famous irrational number PI, but an incredible simulation!

  5. #5
    Guest

    Re: Lightmap blending not working?

    yeah, i know about the pointer junk, but it told me i have multiple definitions of the pointer i was trying to declare when i tried to compile... i think it's because i'm using Dev-Cpp and not VC++ ( even though i have vc++... )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •