  #compact
  $ title     "Shaders and Index Buffer Objects"
  $ FileName  "t.exe"
  'uses RTL64
  uses glTransH
  

  sub main()
  ==========

  '
  if opening
    BuildSky
    static cloudMist cl 
    'BuildTorus boa
    BuildSphereFace boc
    'BuildVesselShape boa
    BuildUFO boa, 15
    
    BuildTextures
    float a,d,s,sh
    static RenderObject rt
'    rt.Setup
    'print rt.Check
'    rt.RenderToTexture
    'print rt.texturebuf
    'rt.RenderToScreen
    'rt.release
    'print "opening!"
    exit sub
  endif 'opening
  '
  if closing
    'print "closing!"
    glDeleteTextures 1,SkyTexture
    ReleaseShaderProg ps[skyboxi]
    boa.release
    boc.release
    rt.release
    exit sub
  endif


  EachFrame:
  ==========

  if ShaderError then exit sub

  'rt.RenderToTexture

  RenderSky 'ang1


  ShaderProgram shaderMaj.ph

  int ortho=0
  SetProjectionMatrix projection, 45, aspect, 1, 1e4, ortho

  loadidentity
  rotatef 10, 1,0,0    'tilt
  translatef 0,-5,-10         'set distance
  if ortho
    scalef 0.2,0.2,0.2      'correction for ortho scale
  endif
  savematrix modelView

  a=0.3   'ambient
  d=0.2   'diffuse
  s=0.5   'specular
  sh=30.0 'shine

  ShaderMatrix4 ShaderMaj.m0, 1, GL_FALSE, projection  'PROJECTION
  ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, modelView   'MODELVIEW
  ShaderTexture shaderMaj.t0, 0, simgn2                'FOR COLOR TEXTURE
  ShaderTexture shaderMaj.t1, 1, norm3                 'FOR NORMAL TEXTURE
  ShaderVector4 ShaderMaj.v0, 1, float {1,.8,.3,1}       'TINT
  ShaderVector4 ShaderMaj.v1, 4, float {a,a,a,1, d,d,d,1, s,s,s,1, sh,0,0,0} 'LIGHT
  ShaderVector4 ShaderMaj.v2, 1, float {0,0,1,0}       'XYZ LIGHT DIRECTION FROM OBJECT
 'ShaderVector4 ShaderMaj.v3, 1, float {1,0,0,1}       'FLAT COLOR
  ShaderVector4 ShaderMaj.v4, 1, float {0.2,0.6,0.7, -70.0}  'FOG COLOR AND DIST LIMIT

  'GENERATE TRANSFORMS

  '
  picklabel 999
  '
  loadidentity
  scalef 1.5,1.5,1.5
  translatef 0,0,-5
  rotatef 20, 1,0,0    'tilt
  rotatef ang3,0,1,0   'Y SPIN
  boa.clearmatrix
  boa.putmatrix mats,16
  
  loadidentity
  scalef 1.5,1.5,1.5
  translatef 3,6,-12
  rotatef 30, 1,0,0    'tilt
  rotatef ang3*0.5,0,1,0   'Y SPIN
  boa.putmatrix mats,16

  loadidentity
  scalef 1.5,1.5,1.5
  translatef -3,6,-30
  rotatef 40, 1,0,0    'tilt
  rotatef ang3*0.5,0,1,0   'Y SPIN
  boa.putmatrix mats,16

  boa.transfermatrix 'COMMIT MATRIX ARRAY

  boa.render 'all panels gpu side

 

  'cl.render 10 'max 100

/*
  rt.RenderToScreen

  NewFrame
  glClearColor 0.6, 0.95 , 0.95, 0.0

  ortho=0
  SetProjectionMatrix projection, 45, aspect, 1, 1e4, ortho
  loadidentity
  translatef 0,0,-10         'set distance
  savematrix modelView

  a=0.3  'ambient
  d=0.6  'diffuse
  s=0.1  'specular
  sh=30.0 'shine

  ShaderMatrix4 ShaderMaj.m0, 1, GL_FALSE, projection  'PROJECTION
  ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, modelView   'MODELVIEW
  ShaderTexture shaderMaj.t0, 0, rt.texture 't0 FOR COLOR TEXTURE
  ShaderVector4 ShaderMaj.v0, 1, float {0.85, 0.85, 0.9, 1.0}     'TINT
  ShaderVector4 ShaderMaj.v1, 4, float {a,a,a,1, d,d,d,1, s,s,s,1, sh,0,0,0} 'LIGHT
  ShaderVector4 ShaderMaj.v4, 1, float {0.0,0.0,0.0, -10000.0}  'FOG COLOR AND DIST LIMIT


  loadidentity
  translatef -10,5,-20
  'rotatef ang1,0,0,1
  scalef 3,3,3
  SqPanel.clearmatrix
  SqPanel.putmatrix mats,16
  SqPanel.transfermatrix
  SqPanel.render '


  loadidentity
  translatef 1,0,0
  rotatef ang1,0,0,1
  scalef 3,3,3
  boc.clearmatrix
  boc.putmatrix mats,16
  boc.transfermatrix
  boc.render
*/



  'LEFT
  sys hWnd=gWnd
  '
  glViewport(10,10,80,80)
  glScissor(10,10,80,80)
  glClearColor 0,0,0.50,0
  boa.render
  'RenderSky
  ShaderProgram 0
  '
  glViewport(10,110,80,80)
  glScissor(10,110,80,80)
  glClearColor 0,0,0.50,0
  'boa.render
  RenderSky
  ShaderProgram 0

  RECT cRect
  GetClientRect  hWnd,cRect
  glViewport 100, 0, crect.right-100, crect.bottom

  'rt.RenderToTexture
  
  



  '
  'UPDATE ROTATION ANGLES
  '----------------------
  ang1+=0.1
  ang3+=0.5
  '
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW
