' 
' Written by Paul Grunewald (aka Stormy)
' Date: 07.28.2006
' Mail: Paul.Grunewald@gmail.com
'
#include "inc/2d_opengl.bi"

' Festlegung der Konstanten, die für den Bildschirm wichtig sind
const scrnX = 640
const scrnY = 480
const depth = 32
const fullscreen = &h0           ' Vollbildmodus ( &h0 = aus, &h1 = an )

' Initialisiere den Schirm
Init_ogl2D(scrnX, scrnY, depth, fullscreen)

WindowTitle "[ Font ]"

DIM MyFont AS FontSystem
MyFont.Spacing = 2
FontLoad(MyFont, "resources/examples/standard.tga","resources/examples/standard.dat")

TYPE BouncingText
 AS STRING Text
 AS INTEGER R, G, B
 AS INTEGER posX, posY
 AS INTEGER dirX, dirY
 AS INTEGER w
END TYPE

DIM MyText(1 TO 5) AS BouncingText
DIM AS INTEGER e, x, y, r

RANDOMIZE TIMER

FOR e = 1 TO 5
With MyText(e)   
 .text = "Example text #" + STR$(e)
 .w = FontGetWidth(MyFont, .text)
 .posX = INT(RND * scrnX - .w) + 1
 .posY = INT(RND * scrnY - 16) + 1
 .dirX = INT(RND * 6) - 3
 .dirY = INT(RND * 6) - 3 
 .R = INT(RND * 128) + 128
 .G = INT(RND * 128) + 128
 .B = INT(RND * 128) + 128
End With
NEXT e

glEnable (GL_BLEND)

do
  glCls  
  FOR x = 0 TO fix(scrnX / 16)
   FOR y = 0 TO fix(scrnY / 16)   
    r = INT(RND * 50)+40
    glPrint (MyFont, STR$(INT(RND * 2)), x*16,y*16,0,r,r,r)
   NEXT y 
  NEXT x
  FOR e = 1 TO 5
  With MyText(e)
   glPrint (MyFont, .text, .posX, .posY, 1, .R, .G, .B)
   IF .posX + .w >= scrnX THEN .dirX = .dirX*-1
   IF .posY + 16 >= scrnY THEN .dirY = .dirY*-1
   IF .posX <= 0 THEN .dirX = .dirX*-1
   IF .posY <= 0 THEN .dirY = .dirY*-1
   .posX += .dirX
   .posY += .dirY 
  
  IF MULTIKEY(SC_R) THEN  
   .posX = INT(RND * scrnX - .w) + 1
   .posY = INT(RND * scrnY - 16) + 1
   .dirX = INT(RND * 6) - 3
   .dirY = INT(RND * 6) - 3 
   .R = INT(RND * 128) + 128
   .G = INT(RND * 128) + 128
   .B = INT(RND * 128) + 128  
  END IF
   
  End With   
  Next e   
  glFlush 
  flip 
  screensync
loop until multikey(SC_ESCAPE) ' Verlasse die Schleife sobald Escape gedrückt wird

DestroyFont(MyFont)
