GLBasic User Manual

Main sections

X_SPRITE

X_SPRITE no#, x#, y#, z#, scaling#



Draws a 2D sprite at a 3D position. This technique is also known as Billboarding. The hot spot of the sprite (the part which will be drawn at the give location) is the sprite's bottom center.

Sample:
// --------------------------------- //
// Project: Billboards

LOADBMP "back.bmp"
LOADSPRITE "tree.bmp", 0
LOADSPRITE "grass.bmp", 1

WHILE TRUE
X_MAKE3D 1,1500,45
MOUSESTATE mx, my, b1, b2
X_CAMERA SIN(mx)*200, 44, COS(mx)*200, 0, 75, 0

// Billboard trees
FOR phi=0 TO 360 STEP 30
FOR ny=0 TO 360 STEP 45
// Draw a 3D (so called Billboard) sprite
// A 3D sprite, that's always facing the camera
X_SPRITE 0, SIN(phi)*500+COS(ny)*300, 0, COS(phi)*300+SIN(ny)*500, .5
NEXT
NEXT

// Grass...
X_OBJSTART 0
f=RGB(255,255,255)
X_OBJADDVERTEX -2000,0,-2000, 0 ,0,f
X_OBJADDVERTEX 2000,0,-2000, 50, 0,f
X_OBJADDVERTEX -2000,0, 2000, 0,50,f
X_OBJADDVERTEX 2000,0, 2000, 50,50,f
X_OBJEND
X_SETTEXTURE 1; X_DRAWOBJ 0,0

X_MAKE2D // LOADBMP requires this before a SHOWSCREEN
SHOWSCREEN
WEND



See also...