  #compact
  $ title "Craft"
  $ FileName "t.exe"
 'uses RTL64
  % ExplicitMain
  uses OpenglSceneFrame
  uses MinMidi
  uses glo2\shapes
  uses glo2\materials
  uses glo2\textures
  uses glo2\particles

  indexbase 1
  float ang1
  sys   cube,sphere,helix,tors
  sys hmo 'midi
  Cloud cloud1
  Smoke smoke1
  Plant fern

  sub InitMidi()
  ================
  sys er
  er=midiOutOpen(hmo, 0, 0, 0, CALLBACK_NULL) '0=synth a 2=soft synth
  midiOutShortMsg(hmo, 0xC0+0x0D00)           'Xylophone Bells assign
  end sub

  function ding(sys v,n)
  ======================
  if v>127 then v=127
  if v<10 then v=10
  'midiOutShortMsg(hmo, v*0x10000+n*0x100+0x89) 'percussion off
  midiOutShortMsg(hmo, v*0x10000+n*0x100+0x99) 'percussion on
  end function


  sub initialize(sys hWnd)
  ========================
  '
  InitMidi
  GDIplus 1
  '
  static sys p,res=256
  BuildTextures 16,res
  p=fern.new res,32000 'pixel map
  MakeTexture p,res,res,texn[12]
  fern.free

  cube=CompileList   : CubeForm      : glEndList
  sphere=CompileList : Spheric 1,1,6 : glEndList
  '
  end sub

  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  DeleteTextures 16
  Gdiplus 0
  MidiOutClose hmo
  end sub

  sub RenderPlane(float su,sv, eu,ev)
  ===================================
  eu+=su : ev+=sv
  glBegin GL_QUADS
  glTexCoord2f su,sv : glVertex3f -1.0,0,-1.0
  glTexCoord2f eu,sv : glVertex3f  1.0,0,-1.0
  glTexCoord2f eu,ev : glVertex3f  1.0,0, 1.0
  glTexCoord2f su,ev : glVertex3f -1.0,0, 1.0    
  glend
  end sub


  sub scene(sys hWnd)
  ===================
  '
  static single ra,ri,angi1=.2
  sys t1=texn[10]
  sys t2=texn[11]
  '
  ActiveFrame
  glClearColor .50, .50, .75, 0
  Fog          .50, .50, .75, 0.020
  StandardLighting li
  StandardMaterial ma
  '
  '
  'MYSTERIOUS RED PLANET
  glPushMatrix
  glTranslatef -20.,10.,-95.0
  Material Red
  glScalef      6.,6.,6.
  glEnable GL_LIGHTING
  glCallList sphere
  'glDisable GL_LIGHTING
  Material White
  glPopMatrix
  '
  'TILES
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t1
  glPushMatrix
  glTranslatef -8.0,-1.99,-5.0
  glScalef     .25,1.,.25
  glPushMatrix
  sys e,i,j
  e=16
  float ii=1/e
  for j=1 to e
    for i=1 to e
      RenderPlane  i*ii,j*ii,ii,ii
      glTranslatef 4.,0.,0.
    next
    glTranslatef -62.,0.,-2.
  next
  glPopMatrix
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  'GREEN PLANE
  glPushMatrix
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,t2
  glTranslatef 0.0,-2.0,-29.0
  glScalef     16.,1.,16.
  RenderPlane  0.,0.,8.,8.
  glDisable GL_TEXTURE_2D
  glPopMatrix
  '
/*
  'SOFT SHADOWS
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[4]
  glPushMatrix
  glTranslatef -1.2,-1.98,-5.8 'for plinth
  glScalef     2.,1.,1.5
  RenderPlane  0.,0.,1.,1.
  glPopMatrix
  '
  glPushMatrix
  glTranslatef -3.5,-1.98,-7.5 'for cylinder
  glScalef     1.,1.,1.
  RenderPlane  texn[3],1.,1.
  glPopMatrix
  '
  glPushMatrix
  glTranslatef 2.5,-1.98,-5.5 'for sphere
  glScalef     .7,.7,.7
  RenderPlane  texn[3],1.,1.
  glPopMatrix
  'glDisable GL_TEXTURE_2D
  '
  glPushMatrix
  glTranslatef -0.,-1.98,-10. 'for metal balls
  glScalef     .7,.7,.7
  RenderPlane  texn[3],1.,1.
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
*/
  '
/*
  'RING
  Material Gold
  'glEnable GL_TEXTURE_2D
  'glBindTexture GL_TEXTURE_2D,texn[2]
  glPushMatrix
  glTranslatef -1.0,0.,-6.0
  glrotatef ang1,0,1,0
  glrotatef 90.0,1,0,0
  glScalef      .75,1.50,.75
  if not tors
    tors=CompileList : torus 1.,.20 : glEndList
  end if
  glCallList tors
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  'METALLIC ORBS
  glPushMatrix
  glTranslatef 0.5,-1.5,-8.0
  glScalef      .25,.25,.25
  Material Silver
  glCallList sphere
  glPopMatrix
  '
  glPushMatrix
  glTranslatef 1.0,-1.5,-9.0
  glScalef      .25,.25,.25
  Material Steel
  glCallList sphere
  glPopMatrix
*/
  '
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[4]
  glPushMatrix
  glTranslatef -.5,-1.98,-8. 'soft shadow
  glRotatef    ang1,0,1,0
  glScalef     4.,1.,2.
  RenderPlane  0.,0.,1.,1.
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  'CRAFT MAIN BODY
  glPushMatrix
  glTranslatef -.5,-1.,-8.0
  glRotatef    ang1,0,1,0
  glRotatef    10.,1,0,0
  glScalef      3.,.5,1.
  Material Alloy
  glCallList sphere
  '
  'FIN
  glpushMatrix
  glTranslatef -.5,.2,.0
  glScalef      .4,.89,.15
  glCallList sphere
  glPopMatrix
  
  'WINGS
  glpushMatrix
  glTranslatef .2,.2,.0
  glScalef      .25,.3,3
  glCallList sphere
  glPopMatrix
  
  'TAIL
  glpushMatrix
  glTranslatef -.75,.2,.0
  glScalef      .125,.15,1.5
  glCallList sphere
  glPopMatrix
  
  'CABIN
  glTranslatef .4,.5,.0
  glScalef      .5,.5,.5
  Material BlackShiny
  glCallList sphere
  glPopMatrix
  '

  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[4]
  glPushMatrix
  glTranslatef 3.,-1.97,-5. 'soft shadow
  glRotatef    ang1,0,1,0
  glScalef     2.,1.,2.
  RenderPlane  0.,0.,1.,1.
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  'CONE
  glPushMatrix
  Material Alloy
  glTranslatef 2.0,-1.5,-4.0
  glScalef    .5,.5,.5
  glBindTexture GL_TEXTURE_2D,t1
  ConeFaces 30,.0,.75,1.
  glPopMatrix
  '
  'CYLINDER
  glPushMatrix
  Material Bronze
  glTranslatef 4.,-2.,-9.0
  glScalef    .25,.5,.25
  ConeFaces 16,1.,8.,1.
  glPopMatrix

  '
  'CYLINDER (SMOKER)
  glPushMatrix
  Material Steel
  gltranslatef  5, -2.,-30.
  glScalef      .125,.5,.125
  ConeFaces 16,1.,2.,1.
  glPopMatrix
  '
  '
/*
  'HELIX
  glPushMatrix
  glTranslatef -1.0,-1.0,-6.0
  glScalef      .35,.35,.35
  glrotatef ang1,0,1,0
  if not helix
    helix=CompileList : toroid 1.,.25,.8,.16,5.,6. : glEndList
  end if
  Material Silver
  glCallList helix
  glPopMatrix
*/
  '
  glEnable GL_TEXTURE_2D
  Material White
  '
/*
  'PLINTH
  glPushMatrix
  glTranslatef -1.0,-1.5,-6.0
  glrotatef   30.0,0,1,0
  glScalef    .5,.5,.5
  glBindTexture GL_TEXTURE_2D,t1
  glCallList cube
  glPopMatrix
*/

  glDisable GL_TEXTURE_2D
  glDisable GL_LIGHTING
  '
  'CLOUD
  glEnable GL_TEXTURE_2D
  glPushMatrix
  gltranslatef -10.0, -10.0, -90.0
  glscalef      20.0,12.0,1.0
  cloud1.render 30 'max 50
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  'SMOKE
  glDisable GL_LIGHTING
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[2]
  glPushMatrix
  gltranslatef  5, -.9, -30.
  glScalef      2.,2.5,1.0
  smoke1.r<=    .45,.45,.55
  smoke1.render 25 'max 50
  'cloud1.render  15
  glPopMatrix
  glDisable GL_TEXTURE_2D
  'glEnable GL_LIGHTING
  '
'/*
  'PLANTS
  glBindTexture GL_TEXTURE_2D,texn(12)
  glEnable GL_TEXTURE_2D
  '
  glPushMatrix
  glTranslatef 1.,-1.,-3.0
  glScalef    .9,.9,1.
  glColor4f   .0,.1,.0,1.
  quadtex     1,1,0
  glPopMatrix
  '
  glPushMatrix
  glTranslatef .7,-1.,-2.99
  glscalef     .9,.9,1.
  glColor4f    .0,.2,.0,1.
  glRotatef    10.,0,0,1
  quadtex      1.,1.,0
  glPopMatrix
  '
  glPushMatrix
  glTranslatef .5,-1.,-2.98
  glscalef     .9,.9,1.
  glColor4f    .0,.3,.0,1.
  'quadtex      1.,1.,0
  glPopMatrix
  '
'*/
  glDisable GL_TEXTURE_2D
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW
