The spotlight texture is the aperture of the spotlight that shines on the surface. Prepare a spot texture brightness map, use the projection texture method described in "glsl projective texture" to project the spot texture to the spotlight.
Unsigned char * pixels = (unsigned char *) malloc (64*64 );
For (Int J = 0; j <64; j ++ ){
For (INT I = 0; I <64; I ++ ){
Float x = (I/31.5f)-1;
Float y = (J/31.5f)-1;
Float ls = max (1-(x * x + y * Y), 0.0f );
Pixels [J * 64 + I] = (unsigned char) (255.0f * ls );
}
}
Texid_spot = gl_create_texture (64, 64, gl_luminance, pixels );
Glbindtexture (gl_texture_2d, texid_spot );
Gltexparameterf (gl_texture_2d, gl_texture_mag_filter, gl_linear );
Gltexparameterf (gl_texture_2d, gl_texture_min_filter, gl_linear );
Glteximage2d (gl_texture_2d, 0, gl_luminance8, 64,64, 0, gl_luminance, gl_unsigned_byte, pixels );
Glbindtexture (gl_texture_2d, 0 );