gl method for lightmaps

BlitzMax Forums/OpenGL Module/gl method for lightmaps

Chris C(Posted 2005) [#1]
Does anyone know how to apply a texture and lightmap to a polygon, what blending is needed? can it be done without gl extensions?


AntonyWells(Posted 2005) [#2]
yeah it can, and you need multi-texturing extensions unless you do multipass, I've got code if you're not sure how to use it.

here's the texture set up func I use for blending etc. rip out the blending modes you need. which is no blending for layer 1(base texture, or disable lighting if you want to blend it in with vertex colors)
then use modulated blending for the lightmap layer.

Method Setup()
	'Local Profile:TProfile
'	If profilerOn
	'	 Profile:TProfile = Profiler.Enter("Texture Setup")
'	EndIf
		glMatrixMode(GL_TEXTURE)
		glLoadIdentity()
		glScalef(Scal[0],Scal[1],Scal[2])
		glTranslatef(Pos[0],Pos[1],Pos[2])
		glRotatef(Rot[2],0,0,1)
'		glRotatef(Rot[0],1,0,0)
	'	glRotatef(Rot[1],0,1,0)
		
		
		If Texture.BindBlend[BoundUnit]<>BlendMode
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
		Select BlendMode
			Case T_Normal
				glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB,GL_REPLACE)
			Case T_Blend
				glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_BLEND)
			Case T_modulated
				glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_MODULATE)
			Case T_Add
				glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB,GL_ADD)
			Case T_Dot3
				glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB,GL_DOT3_RGB)
			Case T_Dot3Alpha
				glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB,GL_DOT3_RGBA)
			Case T_Subtract
				glTexEnvf(GL_TEXTURE_ENV,GL_COMBINE_RGB,GL_SUBTRACT)
			Default
				MainError.Invoke("Illegal Texture Blend Mode Specified In Texture.Setup() Mode:"+BlendMode,True)
		End Select
		Texture.BindBlend[BoundUnit] = BlendMode
		EndIf
		
	
		
	'	If FilterMode<>Texture.BindFilter[BoundUnit]
		Select FilterMode
			Case T_None
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST)
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST)
			Case T_BiLinear
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
			Case T_TriLinear
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR)
				glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
			Default
				MainError.Invoke("Illegal Filter mode in Texture.Setup() Mode:"+FilterMode,False)
		End Select
		Texture.bindfilter[boundunit] = filtermode
	'	EndIf
		
		If ColorS<>Texture.BindColorS[boundunit]
			Texture.BindColorS[boundunit]=ColorS
			glTexEnvf(GL_TEXTURE_ENV,GL_RGB_SCALE_ARB,ColorS)
		EndIf
		
		glMatrixMode(GL_MODELVIEW)
	'	If ProfilerOn
	'		Profile.Leave()
	'	EndIf
	End Method



Chris C(Posted 2005) [#3]
okay maybe not the nightmare I thought, bsp parsing is going
well I have all the level/entity meshes rendering so all I have do now is pick the correct textures instead of test ones
and I'll be using this method
Thanks!


Chris C(Posted 2005) [#4]
eek you missed the hard bit!
got it sorted eventually thx.


ImaginaryHuman(Posted 2005) [#5]
As said, there's only one level of texturing normally in the supported version of OpenGL.


Chris C(Posted 2005) [#6]
no I meant the initilisation for the type of multitexturing
ie the "mix" your using

kinda kool the multi-texturning amazing the (wrong) effects I was getting!