GLBasic User Manual

Main sections


X_SPOT_LT num#, col#, x#, y#, z#, dirx#, diry#, dirz#, cutoff#

Configures a spot light.

num# specifies the id of the light. Values of 0-7 are valid for normal lights, -3 to -1 for special effect lights.
col# specifies the color of the light source. See RGB().
x#, y#, z# are the light position coordinates
dirx#, diry#, dirz# specify a vector describing the direction the light shines.
cutoff# specifies an angle for the light's cut off. The valid values for cutoff# are :-
0 : Turn light off
1-179 : Spot light
180 : Parallel light source.
360 : Point light source.

Special effects lights

With X_SPOT_LT you can create light sources for special effects. num# determines about the effect to be applied.
The CULLMODE for special effects must be set to -1 or 1! (See X_CULLMODE)

num# = -1: Bump Mapping

The 2nd texture will be used as a bump map texture. Darker pixels on the texture represent a lower point and brighter pixels a higher one.
Only the coordinates x#, y#, z# are taken into account. You must load textures with LOADSPRITE and LOADBUMPTEXTURE and select them with X_SETTEXTURE before use. For an example see the command LOADBUMPTEXTURE.

num# = -2 : Cel or Toon Shading

This special effect is also known as Cartoon Rendering.

With Cel shading a light calculation will be performed that does not result in gradual light changes but in stepped levels of brightness. This effect will make the resulting image resemble an image from a cartoon.
If you set a texture with X_SETTEXTURE first, it will be overlayed. This can be used for example to model faces and details onto a character. Only the light position (x#, y#, z#) is taken into account.
For an example see the sample "Cel-Shading" in the 3D samples folder.

num# = -3: Shadows

Special effect number -3 is realtime shadows with the stencil buffer. It works as follows:
- render the whole scene
- X_SPOT_LT -3, 0, x,y,z, 0,0,0, 360
(this light is the light source for the shadow direction)
- X_DRAWOBJ for all shadow casting objects
this finally draws the shadow
- the colour is used to taint the shadowed area.

// --------------------------------- //
// Project: ToonShading
// Start: Wednesday, October 07, 2004
// IDE Version: 2.41007

CreateTorus(1, 5, 10, 24, 24, 2, 2)
// Bild-Daten / Image data
// LOADSPRITE "image.bmp", 0
DRAWRECT 0,0,64,64,RGB(0xff,0xff,0xff)
DRAWRECT 0,28,64,9,RGB(0,0,0xff)
GRABSPRITE 0, 0,0, 64,64

// Hauptschleife / main loop
DRAWRECT 0,0,640,480,RGB(0,0,200)
X_MAKE3D 1, 250, 45
X_CAMERA 0, 10, 100, 0,0,0
// Licht Nr. -2 is Cel-Shading Postition / Light no -1 is cel shading position
X_SPOT_LT -2, 0, 0,0,100, 0,0,0,90
X_SETTEXTURE 0, -1 // 0=Tex
X_ROTATION 90, 1,0,0
X_ROTATION phi, 0, 1, 0.1

// ------------------------------------------------------------- //
// -=# CREATETORUS #=-
// Donut Objekt machen / Make a donut object
// By Samuel R. Buss
// ------------------------------------------------------------- //
FUNCTION CreateTorus: num, MinorRadius, MajorRadius, NumWraps, NumPerWrap, TextureWrapVert, TextureWrapHoriz
LOCAL i, di, j, wrapFrac, wrapFracTex, phi, thetaFrac, thetaFracTex, theta
LOCAL x, y, z, r

X_AUTONORMALS 2 // smooth
FOR di=0 TO NumWraps-1
FOR j=0 TO NumPerWrap
FOR i=di+1 TO di STEP -1
wrapFrac = MOD(j, NumPerWrap)/NumPerWrap
wrapFracTex = j/NumPerWrap
phi = 360*wrapFrac
thetaFrac = (MOD(i, NumWraps + wrapFracTex)/NumWraps
thetaFracTex = (i+wrapFracTex)/NumWraps
theta = 360*thetaFrac
r = MajorRadius + MinorRadius*COS(phi)
x = SIN(theta)*r
z = COS(theta)*r
y = MinorRadius*SIN(phi)
X_OBJADDVERTEX x,y,z, thetaFracTex*TextureWrapVert, 1-wrapFracTex*TextureWrapHoriz, _

See also...