Lightmapping works by creating a second texture layer on the object and applying the light map to that new layer. The final appearance is obtained by simply blending the main texture with the lightmap texture. The lightmaps are saved in a separate folder in the project directory.
Once you have run my first demo you can simply load the new lightmapped object. For example, create a new project in the same folder as before and run the following code. Note that the fvf format is now 530 whereas it was initially 274 before the lightmapping was performed (274 is the default DBPro fvf format). The change reflects the addition of a second set of UV coordinates, i.e. 274+256 = 530.
If you wanted to I guess you could prepare a series of lightmaps for the same object and just apply them to the correct stage when needed. [I haven't tested that suggestion yet so the usual health warning applies
.]
Edit Sorry! Forgot the code. Here it is hopefully:
` simple test of lightmapped object
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
hide light 0
autocam off
position camera 0, 500, 0
point camera 0, 0, 0
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
load object "myThirdLMObject.dbo", 1
` find the fvf format of the lightmapped object
make mesh from object 1, 1
make memblock from mesh 1, 1
fvf = memblock dword(1, 0)
repeat
text 20, 20, "fps = "+str$(screen fps())
text 20, 40, "fvf = "+str$(fvf)
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction
Edit2 Just adding a bit more detail on the lightmapping. The following code shows how you can achieve the same result by using the blend mapping commands directly. So, once you've lightmapped the object you can change the main texture if you like. Not sure about the lightmap - the calculated UV data for stage 1 might be linked to the light map used. I'd have to do more tests to find out.
` simple test of lightmapped object
set display mode desktop width(), desktop height(), 32
sync on: sync rate 60: sync
hide light 0
autocam off
position camera 0, 500, 0
point camera 0, 0, 0
global cx#
global cy#
cx# = camera angle x()
cy# = camera angle y()
load object "myThirdLMObject.dbo", 1
` find the fvf format of the lightmapped object
make mesh from object 1, 1
make memblock from mesh 1, 1
fvf = memblock dword(1, 0)
delete mesh 1
delete memblock 1
load image "lightmaps/myThirdLM0.png", 1 ` load the lightmap
load image "white.png", 2 ` plain white image for testing
set blend mapping on 1, 0, 2, 0, 2 ` apply white texture to stage 0
set blend mapping on 1, 1, 1, 0, 4 ` apply lightmap to stage 1 and blend with output from stage 0
repeat
text 20, 20, "fps = "+str$(screen fps())
text 20, 40, "fvf = "+str$(fvf)
positionCamera()
sync
until spacekey()
end
function positionCamera()
control camera using arrowkeys 0, 1, 0
cx# = cx# + mousemovey(): cy# = cy# + mousemovex()
rotate camera cx#, cy#, 0
endfunction