
  $ FileName "t.exe"
  'uses rtl32
  'uses rtl64
  $ title  "Crates in Fog"
  $ fontA     "Arial",FW_SEMIBOLD
  uses OpenglSceneFrame

  indexbase 1
  sys   texn[3]
  sys   GdiplusToken
  float ang1
  float li[16]
  float ma[13]
  sys cube pent


  sub initialize(sys hWnd)
  ========================
  '
  'GDIPLUS
  '
  sys hr
  GdiplusStartupInput StartupInput

  StartupInput.GdiplusVersion = 1
  hr=GdiplusStartup GdiplusToken, StartupInput, null
  '
  if hr then
    print "Error initializing GDIplus: " hex hr
    exit function
  end if
  '
  'PREPARE TEXTURES
  '
  glGenTextures 2, texn
  '
  static sys res=256
  string imgs[1]=""
  LoadPixImage "../images/crate.jpg",res,imgs[1]
  MakeTexture *imgs[1],res,res,texn[1]
  '
  cube=CompileList : CubeForm    : glEndList
  pent=CompileList : Sides 5,1,1 : glEndList
  '
  'standard lighting
  ------------------
  li<=
  0.0, 8.0, 8.0, 1.0,  'position
  1.0, 1.0, 1.0, 1.0,  'diffuse 
  1.0, 1.0, 1.0, 1.0,  'ambient
  1.0, 1.0, 1.0, 1.0   'specular

  'standard material
  ------------------
  ma<=
  0.7, 0.7, 0.6, 1.0, 'diffuse
  .15, .15, 0.2, 1.0, 'ambient
  0.0, 0.0, 0.1, 1.0, 'specular  
  0                   'shininess
  Material ma
  Lighting li
  '
  end sub

  sub Release(sys hwnd)
  '====================
  glDeleteLists    cube,1 
  glDeleteLists    pent,1 
  glDeleteTextures 2, texn
  GdiplusShutdown GdiplusToken
  end sub

  sub RenderCrate(float x,y,z,sc,sys tex)
  =======================================
  'glColor4f .99,.99,.99,.99
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef x,y,z
  glrotatef    ang1,0,1,0
  glscalef sc,sc,sc
  glCallList Cube
  'glCallList Pent
  glPopMatrix
  glDisable GL_TEXTURE_2D
  end sub


  sub scene(sys hWnd)
  '==================
  '
  static single ra,ri,angi1=.5
  '
  '
  SnapShots hWnd 'Ctrl-P take snapshot
  NewFrame
  glClearColor 0.5, 0.5, 0.7, 0.0
  Fog          0.5, 0.5, 0.7, 0.05 'rgb and density
  '
  'TEXT
  glDisable GL_LIGHTING
  glLoadIdentity
  static int framecount
  framecount++
  gltranslatef -.50, .35,-1.0
  glcolor3f .99,.50,.50
  glscalef .06,.06, .01
  'glcalllist cube
  gprint "frames: "+str(framecount)
  '
  'CRATES
  glLoadIdentity
  sys t=texn[2]
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t

  glEnable GL_LIGHTING
  'glEnable GL_NORMALIZE
  glColor4f .99,.99,.99,.99
  sys n=texn[1]
  RenderCrate  11.5,-0.9,-24.0,0.5,n
  RenderCrate   6.5,-0.9,-16.0,0.5,n
  RenderCrate   2.5,-0.9,-8.0, 0.5,n
  RenderCrate   0.5,-0.9,-4.0, 0.5,n
  RenderCrate  -0.5,-0.9,-2.0, 0.5,n
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub
