Rem --------------------------------------------------------------
Rem  Dark Occlusion Example
Rem --------------------------------------------------------------

// Enable syncing
Sync on
Sync rate 60

// Set the general occlusion settings: PixelError=4, Fps=every frame
set occlusion settings 4, 0

// Create 100 randomly placed cubes
for i=1 to 100
    
    objectID = i
    
    // Create the cube
    make object cube objectID, 1
    
    // Position the cube at a random position
    position object objectID, rnd(20), 0, rnd(20)
    
    // Enable occlusion culling for the cube
    set object occlusion cull objectID, 1, objectID
    
    // Draw the cube as a wireframe so the occlusion culling is visible
    set object wireframe objectID, 1
    
next i

// Reset the mouse movement
null# = mousemovex()
null# = mousemovey()

// Main loop
Do
    
    // Print the frames per second to the screen
    text 10, 10, "Fps: "+str$( screen fps() )
    // Print the number of static occluders checked in the last update call (These are grouped, so this will not match the actual number of objects)
    text 10, 30, "Static: "+str$( get static occluders() )
    // Print the number of dynamic occluders checked in the last update call
    text 10, 50, "Dynamic: "+str$( get dynamic occluders() )
    // Print the number of visible objects on the screen
    text 10, 70, "Visible: "+str$( get visible objects() )
    // Print the id's of the visible objects
        text 10, 90, "---"
        // Create a memblock holding the id's of all the visible objects on the screen
        make memblock from visible objects 1
        
        // Loop through the memblock and print the id's
        for i=0 to get visible objects()-1
            text 10, 100 + i*20, str$( memblock dword(1, i*4) )
        next i
        
        // Delete the temporary memblock
        delete memblock 1
    
    // Simple camera movement
    if upkey() then move camera .1
    if downkey() then move camera -.1
    
    // Rotate the camera with the mouse
    rotate camera wrapvalue( camera angle x()+mousemovey() ), wrapvalue( camera angle y()+mousemovex() ), 0
    
    // Update dark occlusion for camera 0, all occluded objects will be culled
    Update Dark Occlusion 0
    
    // Sync the screen
    Sync
Loop

// This function should be ignored
// Includes all the libraries (3D, Camera, Memblock) for Dark Occlusion
Function IncludeLibraries()
    make object cube 1, 1
    make camera 1
    delete camera 1
    delete object 1
    make memblock 1, 1
    delete memblock 1
endfunction