' 
' 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 "[ Light #2 ]"

TYPE Light
 AS INTEGER R, G, B, A
 AS SINGLE X, Y, dirX, dirY
 AS INTEGER w
 
END TYPE

DIM MyLight(1 TO 5) AS Light
DIM AS INTEGER e

RANDOMIZE TIMER

FOR e = 1 TO 5
With MyLight(e)   
 .w = INT(RND * 256) + 128
 .X = INT(RND * scrnX) + 1
 .Y = INT(RND * scrnY) + 1
 .R = INT(RND * 128) + 128
 .G = INT(RND * 128) + 128
 .B = INT(RND * 128) + 128
 .A = INT(RND * 128) + 128 
 .dirX = INT(RND * 6) - 3
 .dirY = INT(RND * 6) - 3  
End With
NEXT e

DIM AS GFXType light_texture, background_texture
DIM AS INTEGER x, y

glEnable GL_TEXTURE_2D						 ' Texturen erlauben.
load_texture ("resources/examples/light.tga", light_texture)	 ' Lade Lichttextur
load_texture ("resources/examples/brick.tga", background_texture)' Lade Hintergrund

glEnable GL_BLEND

do
  glCls  
  glcolor4f .5,.5,.5,1
  glDepthFunc (GL_LESS)
  glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
  
  FOR x = 0 TO fix(scrnX / background_texture.width)
   FOR y = 0 TO fix(scrnY / background_texture.height)   
    PutTexture (background_texture,_
    x * background_texture.width,_
    y * background_texture.height, 0)
   NEXT y 
  NEXT x
    
  glDepthFunc (GL_ALWAYS)
  glBlendFunc (GL_SRC_ALPHA, GL_SRC_ALPHA)  
  FOR e = 1 TO 5
  With MyLight(e)
   glcolor4ub .R, .G, .B, 255
   glBindTexture GL_TEXTURE_2D, light_texture.handle
   DrawTexQuad (.X, .Y, 2, .w, .w)

   IF .X + .w/2 >= scrnX THEN .dirX = .dirX*-1
   IF .Y + .w/2 >= scrnY THEN .dirY = .dirY*-1
   IF .X + .w/2 <= 0 THEN .dirX = .dirX*-1
   IF .Y + .w/2 <= 0 THEN .dirY = .dirY*-1
   .X += .dirX
   .Y += .dirY 
      
  IF MULTIKEY(SC_R) THEN  
   .X = INT(RND * scrnX) + 1
   .Y = INT(RND * scrnY) + 1
   .R = INT(RND * 128) + 128
   .G = INT(RND * 128) + 128
   .B = INT(RND * 128) + 128  
   .A = INT(RND * 128) + 128  
   .w = INT(RND * 256) + 128
   .dirX = INT(RND * 6) - 3
   .dirY = INT(RND * 6) - 3    
  END IF
      
  End With   
  Next e   
  
  glDepthFunc(GL_LESS)
  glBlendFunc GL_DST_COLOR, GL_DST_COLOR
  glcolor4f 0,0,0,1: 
  glBindTexture GL_TEXTURE_2D, 0
  PutBox (0,0,scrnX,scrnY,3)
  
  glFlush 
  flip 
  screensync
loop until multikey(SC_ESCAPE) ' Verlasse die Schleife sobald Escape gedrückt wird
