  #compact
  $ filename "t.exe"
 'uses rtl64
  uses glTransB

  '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 scene(sys hWnd)
  ===================
  % BackGroundColor 0 , 0 , 0.2,0
  BeginPick
  PrepareSceneFrame

  static sys init
  static ShapeObject boa

  if init then goto EachFrame else init=1

  float m=-1,l=1,o=0
  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       imgn, "../../images/glass.jpg"

  int a,b,c

  a=0x00300000 'backgroundcolor
  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

  

  float a=.99,d=.00,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, imgn 'FOR COLOR 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, 4, float {0,0,1,0} 'xyz direction from object


  EachFrame:
  ==========
  '
  ShaderProgram shaderMaj.ph
  '
  '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+10]+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]
    ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, tm 'modelView
    PickLabel 0xff00
    boa.render
  next
  EndPick
if picked then print hex picked : picked=0
  ShaderProgram -1
  '
  end sub



  MainWindow width,height,WS_OVERLAPPEDWINDOW
