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

  def skyboxi 13
  '
  '
  sub main()
  ==========

  static float  ang1,angi1=.5
  static int    SkyShader
  static int    SkyTexture
  static int    SkyUL[4]

  '
  if opening

    'glClientActiveTexture(GL_TEXTURE0)
    '
    LoadCubicTextures (
    "..\..\images\SkyBox\left.jpg",
    "..\..\images\SkyBox\right.jpg",
    "..\..\images\SkyBox\bottom.jpg",
    "..\..\images\SkyBox\top.jpg",
    "..\..\images\SkyBox\front.jpg",
    "..\..\images\SkyBox\back.jpg",
    SkyTexture
    )
    '
    shaders()
    CreateShaderProg ps[skyboxi]
    SkyShader = ps[skyboxi].ph
    SkyUL[1] = glGetUniformLocation(SkyShader, "CubeMap")
    SkyUL[2] = glGetUniformLocation(SkyShader, "Projection")
    SkyUL[3] = glGetUniformLocation(SkyShader, "ModelView")
    BuildSkyBox() 'Cube buffer
   '
  endif 'opening
  '
  if closing
    glDeleteTextures 1,SkyTexture
    ReleaseShaderProg ps[skyboxi]
    exit sub
  endif

  if ShaderError then exit sub

   'SKY BOX RENDER
  '==============
  '
  'SET PROJECTION
  int ortho=0
  SetProjectionMatrix projection, 45, aspect, 1, 1e4, ortho
  'GENERATE TRANSFORM MATRICES
  ShaderMatrix4 ShaderMaj.m0, 1, GL_FALSE, projection  'PROJECTION

  'SET MODEL VIEW
  LoadIdentity
  if ortho
    scalef 0.2,0.2,0.2      'correction for ortho scale
  endif

  Rotatef 30,-1,0,0     'x tilt
  Rotatef Ang1*.4,0,1,0 'y spin
  Scalef 1000,1000,1000
  savematrix modelView
  '
  ShaderMatrix4 SkyUL[2], 1, GL_FALSE, projection  'PROJECTION
  ShaderMatrix4 SkyUL[3], 1, GL_FALSE, modelView   'MODELVIEW
  DrawSkyBox(SkyTexture,SkyShader)

  '
  'UPDATE ROTATION ANGLES
  '----------------------
  ang1+=0.1
  'if ang1>360 then ang1-=360
  '
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW
