  '% BackGroundColor 0 , 0 , 0.2, 0.0
  $ filename "t.exe"
 'uses rtl64
  uses glTransC


  'ARRAY OF MODEL VIEW MATRICES
  '
  %mmax 0x1000
  float matf[mmax*16] 'matrix array
  float vz[mmax]      'float array for z (translation)
  sys   midx[mmax]    'index for ascending-order of z


  sub main
  ========

  StepAngle ang1,1

  if opening=0 then goto EachFrame

  float m=-1,l=1,o=0
  static ShapeObject boa
  boa.init
  boa.PutMatrix float {l,o,o,o, o,l,o,o, o,o,l,0, o,o,o,l },16
  boa.PutVertex float {
  'VERTEX NORMAL TEXCOR
  m,m,o,  o,o,l, o,o, 
  l,m,o,  o,o,l, l,o, 
  l,l,o,  o,o,l, l,l, 
  m,l,o,  o,o,l, o,l
  },32 'SQUARE PANEL
 'boa.PutIndex int {0,1,2, 2,3,0},6,GL_TRIANGLES
  boa.PutIndex int {0,1,3,2},4,GL_TRIANGLE_STRIP
 'boa.PutIndex int {0,1,2,3},4,GL_QUADS
  boa.Transfer 

  CreateTexture       imgn0, "../../images/glass.jpg"

  int a,b,c

  a=PixelColor BackGroundColor '0x00300000
  b=0xa0a0ffff
  c=0xffffffff
  '
  CreateSynthTexture imgn1, int {
  a,a,a,
  a,b,a,
  a,a,a
  }, bytesof

  CreateSynthTexture imgn2, int {
  a,a,a,a,a,
  a,b,a,b,a,
  a,a,b,a,a,
  a,b,a,b,a,
  a,a,a,a,a
  }, bytesof

  CreateSynthTexture imgn3, int {
  a,a,a,a,a,a,a,
  a,a,a,b,a,a,a,
  a,a,b,b,b,a,a,
  a,b,b,c,b,b,a,
  a,a,b,b,b,a,a,
  a,a,a,b,a,a,a,
  a,a,a,a,a,a,a
  }, bytesof

  'NORMAL XYZ IN RGB CHANNELS
  'DEPTH SHADING IN A CHANNEL
  a=0xff0000ff 'MAX X
  b=0xff00ff00 'MAX Y
  c=0xffff0000 'MAX Z
  '
  CreateSynthTexture norm1, int {
  a,a,a,a,a,a,a,
  a,a,a,b,a,a,a,
  a,a,b,b,b,a,a,
  a,b,b,c,b,b,a,
  a,a,b,b,b,a,a,
  a,a,a,b,a,a,a,
  a,a,a,a,a,a,a
  }, bytesof

  CreateSynthTexture norm2, int {
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a,
  a,c,a,c,a,c,a
  }, bytesof

  

  float a=.15,d=.85,s=.00,sh=0
  float projection[16]
  ShaderProgram shaderMaj.ph
  SetProjectionMatrix projection, 45, aspect, 1, 1e6
  ShaderMatrix4 ShaderMaj.m0, 1, GL_FALSE, projection
  ShaderTexture shaderMaj.t0, 0, imgn0            'FOR COLOR TEXTURE
  ShaderTexture shaderMaj.t1, 1, norm2            'FOR NORMAL TEXTURE
 'ShaderVector4 ShaderMaj.v3, 1, float {1,0,0,1}  'FLAT COLOR
  ShaderVector4 ShaderMaj.v0, 1, float {1,1,1,.7} 'TINT
  ShaderVector4 ShaderMaj.v1, 4, float {a,a,a,1, d,d,d,1, s,s,s,1, 100,0,0,0} 'LIGHT
  ShaderVector4 ShaderMaj.v2, 1, float {0,0,1,0} 'XYZ LIGHT DIRECTION FROM OBJECT


  EachFrame:
  ==========
  '

  shaderMaj.use
  '
  'GENERATE ARRAY OF TRANSFORMS
  float ang2,ang3
  sys   i,j,k,m
  sys   n=8
  float ang=360/n
  float d=tan(rad(90-ang/2))
  '
  j=0 : k=0
  for m=0 to 1 'with inner circle
    for i=0 to <n
      ang2=i*ang
      ang3=ang1+ang2
      ' 
      loadidentity
      translatef   0,0,-10
      if m then  scalef .5,.5,.5
      rotatef      20,  1,0,0
      if m then  translatef 1,0,0
      rotatef      ang3,0,1,0
      translatef   0,0,d
      savematrix   matf(j)
      '
      vz[k]=matf[j+14] 'COLLECT Z DISPLACEMENT
      j+=16 : k+=1
    next
  next
  '
  'ARRANGE PANELS INTO ASCENDING Z ORDER
  sortindex vz, midx, k
  '
  float tm[16]
  '
  '
  'RENDER BLACK BACKGROUND PANEL FOR PICKING
  'PickBackGround


  'RENDER PANELS IN Z ORDER (FARTHEST FIRST)
  sys nn=n*m
  for i=0 to <nn
    j=midx[i]*16 'SELECT MATRIX VIA INDEX (ASCENDING ORDER)
    'TranslationMatf tm,matf[j] 'BILLBOARDING
    'ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, tm 'modelView
    ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, matf[j] 'modelView
    PickLabel 0xff00
    boa.render
  next

  PickLabel 0xff01

  ShaderProgram -1

  if closing then
    'print hex picked
  end if
  '
  end sub


  MainWindow width,height,WS_OVERLAPPEDWINDOW
