  #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
    'BuildSpheric boa, 15

    BuildTextures

    static float ang3
    float a,d,s,sh


    static RenderObject rt
    rt.Setup
    'print rt.Check
    rt.RenderToTexture
    'print rt.texturebuf
    'rt.RenderToScreen
    'rt.release
    exit sub

  endif 'opening
  '
  if closing
    glDeleteTextures 1,SkyTexture
    ReleaseShaderProg ps[skyboxi]
    boa.release
    boc.release
    exit sub
  endif



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

  if ShaderError then exit sub

  RenderSky 'ang1


  ShaderProgram shaderMaj.ph



  'TORUS RENDER
  =============

  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.4  'ambient
  d=0.6  'diffuse
  s=0.1  'specular
  sh=0.1 'shine

  ShaderMatrix4 ShaderMaj.m0, 1, GL_FALSE, projection  'PROJECTION
  ShaderMatrix4 ShaderMaj.m1, 1, GL_FALSE, modelView   'MODELVIEW
  ShaderTexture shaderMaj.t0, 0, simgn1                'FOR COLOR TEXTURE
  ShaderTexture shaderMaj.t1, 1, norm3                 'FOR NORMAL TEXTURE
  ShaderVector4 ShaderMaj.v0, 1, float {1,1,1,1}       '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
 '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
  translatef 0,0,-5
  rotatef 20, 1,0,0    'tilt
  rotatef ang3,0,1,0   'Y SPIN
  boa.clearmatrix
  boa.putmatrix mats,16
  
  loadidentity
  translatef 3,6,-12
  rotatef 30, 1,0,0    'tilt
  rotatef ang3*0.5,0,1,0   'Y SPIN
  savematrix tm
  boa.putmatrix tm,16
  'boa.putmatrix mats,16

  loadidentity
  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

  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.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


  rt.RenderToTexture

  ShaderProgram 0



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

  MainWindow width,height,WS_OVERLAPPEDWINDOW
