home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 December / DPPCPRO1205.ISO / Essentials / Programming / Basic4GL / Setup Basic4GL v2.3.1.exe / $INSTDIR / Programs / Flames01.gb < prev    next >
Encoding:
Text File  |  2005-07-29  |  2.8 KB  |  90 lines

  1. ' Flames01.gb
  2. '
  3. ' Original version by Scott Brosious
  4. ' Converted to Basic4GL by Tom Mulgrew
  5.  
  6. const width = 128           ' Width of bitmap. Must be a power of 2 (so we can load it into an OpenGL texture)
  7. const height = 64           ' Height of bitmap. Must be a power of 2 (so we can load it into an OpenGL texture)
  8. dim a1(height-1)(width-1)   ' Due to the way Basic4GL stores arrays, the first dimension
  9. dim a2(height-1)(width-1)   ' actually ends up as the Y, and the second as the X when the texture is loaded into OpenGL
  10.  
  11. ' Working variables
  12. dim x, y, c1, c2, nohs, i, j
  13.  
  14. ' Setup OpenGL
  15. glMatrixMode (GL_PROJECTION)        ' Use a 2D projection (2D mode)
  16. glLoadIdentity ()
  17. gluOrtho2D (0, 1, 0, 1)
  18. glMatrixMode (GL_MODELVIEW)
  19.  
  20. ' Setup an OpenGL texture.
  21. ' We will copy our image into this texture and draw it as a quad
  22. dim tex
  23. glEnable (GL_TEXTURE_2D)
  24. tex = glGenTexture ()
  25. glBindTexture (GL_TEXTURE_2D, tex)
  26. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
  27. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
  28. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
  29. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
  30.  
  31. FOR x = 0 TO width - 1
  32.     C1 = (RND() % 25) + 50
  33.     C2 = (RND() % 25) + 50
  34.     a1(height-2)(x) = c1
  35.     a1(height-1)(x) = c2
  36. next
  37.  
  38. while true
  39. nohs = INT(RND() % 15) + 15
  40. FOR i = 1 TO nohs
  41.     x = INT(RND() % (width - 3)) + 1
  42.     a1(height-3)(x-1) = 255
  43.     a1(height-3)(x  ) = 255
  44.     a1(height-3)(x+1) = 255
  45.     a1(height-2)(x-1) = 255
  46.     a1(height-2)(x  ) = 255
  47.     a1(height-2)(x+1) = 255
  48.     a1(height-1)(x-1) = 255
  49.     a1(height-1)(x  ) = 255
  50.     a1(height-1)(x+1) = 255
  51. NEXT 
  52.  
  53. for x = 1 to width - 2
  54.     for y = 1 to height - 2
  55.         a2 (y-1)(x) = (a1(y)(x-1) + a1(y)(x+1) + a1(y-1)(x) + a1(y+1)(x)) / 4 - 3
  56.     next
  57. NEXT 
  58.  
  59. FOR j = 0 TO height - 1
  60.     FOR i = 0 TO width - 1
  61.         if a2(j)(i) < 1 then a2(j)(i) = 1 endif
  62.         a1(j)(i) = a2(j)(i)
  63.     NEXT 
  64. NEXT 
  65.  
  66. ' Load array into current OpenGL texture
  67. ' We will use GL_LUMINANCE, to create a luminance texture.
  68. ' This is a texture of a single colour, but varying brightness (luminance).
  69. ' We use GL_UNSIGNED_BYTE, to instruct OpenGL to treat each element as a byte.
  70. ' So 0 is the minimum brightness, and 255 is the maximum,
  71. glTexImage2D (GL_TEXTURE_2D, 0, 1, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, a1)
  72.  
  73. ' Draw texture.
  74. glClearColor (0.4, 0, 0, 1)
  75. glDisable (GL_DEPTH_TEST)
  76. glEnable (GL_TEXTURE_2D)
  77. glEnable (GL_BLEND)
  78. glBlendFunc (GL_SRC_ALPHA, GL_ONE)
  79. glClear (GL_COLOR_BUFFER_BIT)
  80. glColor3f (1, 1, .4)
  81. glBegin (GL_QUADS)
  82.     glTexCoord2f (0, 1): glVertex2f (0, 0)
  83.     glTexCoord2f (1, 1): glVertex2f (1, 0)
  84.     glTexCoord2f (1, 0): glVertex2f (1, .5)
  85.     glTexCoord2f (0, 0): glVertex2f (0, .5)
  86. glEnd ()
  87.  
  88. ' Show texture
  89. SwapBuffers ()
  90. wend