
  #case capital
  '#compact
  $ FileName "t.exe"
  'uses RTL32
  'uses RTL64

  string title = "waves and particles  (space-bar to pause)"
  int width  = 800
  int height = 800
  '

  uses OpenglSceneFrame

  sys texn[1]


  '
  '
  sub MakePatternA(sys n)
  =======================
  '
  %size 1024
  static long pixels[size*size]
  static long tx=size, ty=size, x, y, p, c

  type   rgba
    byte r,g,b,a
  end type

  double range,x,y,r,sc,stp
  double cosx,siny
  long   px,py,p
  rgba   tex at (@pixels)
  '
  double q=pi/3
  range=24 : sc=127 : stp=range*2/size
  y=-range
  p=@pixels
  for py=1 to size
    x=-range
    for px=1 to size
      cosx=cos(x)
      siny=sin(y)
      'r=+Cosx+Siny '24
      'r = cosx * Siny '32     
      'r = Cosx * Siny+Cosx+Siny '24      
      'r = Cosx*Cosx+Siny*Siny '24      
      'r = hypot(Cosx,Siny) '***      
      'r = hypot(Cosx,Siny)+(cosx+siny)
      r = hypot(Cosx,Siny)+(cosx+siny)*.5
      Tex.r = 128+sc*Cos(r*y)
      Tex.g = 128+sc*Cos(r*x*y)
      Tex.b = 128+sc*Sin(r*x)
      Tex.a = 255
      @tex+=sizeof tex 'ADVANCE TEXTURE ARRAY POINTER
      x+=stp
    Next
    y+=stp
  Next
  '
  MakeTexture @Pixels,size,size,texn[1]
  '
  end sub
  '
  '
  sub Initialize(sys hWnd)
  ========================
  GDIplus 1
  glGenTextures 1, texn
  MakePatternA 1
  end sub 'initialize



  sub Release(sys hWnd)
  =====================
  glDeleteTextures 1, texn
  GDIplus 0
  end sub 



  sub Scene(sys hWnd)
  '==================
  '
  static single ang1, angi1=.1
  static single sx,sy,sz
  '
  'Snapshots hwnd 'Ctrl-P to take snapshot
  '
  if pause
    act=0 : sleep 50 : exit sub
  end if
  '
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  glClearColor 0.5, 0, 0, 0
  glLoadIdentity
  '
  'ACTIVATE TEXTURE
  '----------------
  '
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[1]
  '
  sx=1.0 : sy=1.0 : sz=-1
  'sx=0.3 : sy=0.3 : sz=-1
  '
  '
  'MOVEMENT
  '--------
  '
  single x=cos(rad(ang1))*.50
  single y=sin(rad(ang1))*.50
  single z=0
  
  gltranslatef x,y,z
  '
  'DRAW SHAPE
  '----------
  '
  'this quad is drawn clockwise
  '
  glbegin GL_QUADS
  glTexCoord2f 0,0 : glvertex3f -sx, -sy,  sZ 'BOTTOM LEFT
  glTexCoord2f 0,1 : glvertex3f -sx,  sy,  sZ 'TOP LEFT
  glTexCoord2f 1,1 : glvertex3f  sx,  sy,  sZ 'TOP RIGHT
  glTexCoord2f 1,0 : glvertex3f  sx, -sy,  sZ 'BOTTOM RIGHT
  glend
  '
  '
  glDisable GL_TEXTURE_2D
  '
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  ang1+=angi1 : if ang1>=360 then ang1-=360
  '
  sleep 10
  '
  end sub


