As is the case with most programming languages, BGL includes subroutines. The following example illustrates a BGL subroutine call.
BGL_CALLSOLDIER_MODEL
;Soldier Field Model Subroutine
SOLDIER_MODEL:
TEXTURE0,0,0,0,'soldier .r8 '
PERSPECTIVE
GFACET4_TMAP0,32767,0,0,0,178,185,1,96,185,2,96,69,3,178,69
BGL_RETURN
The preceding example includes a model of Soldier’s Field Stadium in Chicago. The model has been simplified to portray the stadium as a flat texture on the ground.
In the example, notice the BGL_CALL command that vectors execution to the model subroutine and the BGL_RETURN command at the end of the subroutine. Also note that the subroutine doesn't include any capabilities to pass variables, but the context in which the subroutine is executed implicitly passes information to the subroutine. The SCALE command that defines the center location and scale that is in effect when the subroutine is called is the command that is used by the subroutine. Likewise, any color commands and other status information that is set by setting variables is effectively “passed” to the subroutine.
BGL subroutines are extensions of LOGOL subroutines that were originally intended to define objects that were used multiple times in different locations. Although BGL subroutines have been used for this purpose to a small degree, they are more often used as a tool to structure BGL code. For instance, the Soldier’s Field example earlier in this topic didn’t use the subroutine to put copies of Soldier’s Field at different locations, but rather to set the model off as a separate object that better organized the BGL code.