  #compact
  $ FileName  "t.exe"
  'uses RTL64
  'uses console
  '
  % ExplicitMain
  % title        "Saucer with Popup Console"
  % fontA        "Arial",FW_SEMIBOLD

  'macro keydown
  'case 27 : 'no action
  'case 32 : 'no action
  'end macro
  '
  uses OpenglSceneFrame
  uses glo2\shapes
  uses glo2\materials
  uses glo2\textures
  '
  uses ControlPanels
  indexbase 1
  float     ang1
  sys       cube,sphere



  sub initialize(sys hWnd)
  ========================
  '
  'GDIplus 1
  static sys p,res=256
  BuildTextures 16,res
  cube=CompileList   : CubeForm      : glEndList
  sphere=CompileList : Spheric 1,1,6 : glEndList
  end sub


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

  sub RenderPlane(float su,sv, eu,ev)
  ===================================
  eu+=su : ev+=sv
  glBegin GL_QUADS
  glNormal3f 0.0,1.0,0.0
  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)
  ===================
  '
  indexbase 1
  static single ra,ri,angi1=.5
  '
  'DozyFrame
  ActiveFrame
  glClearColor 0.5, 0.5, 0.7, 0
  Fog          .50, .50, .75, 0.025
  '
  BeginPick
  '
  glColor4f 1,1,1,1
  StandardLighting li
  StandardMaterial ma
  '

  'BACKGROUND SCENE
  '
  PickLabel 0
  '
  'MYSTERIOUS RED PLANET
  glPushMatrix
  glTranslatef -20.,10.,-95.0
  Material Red
  glScalef      6.,6.,6.
  glEnable GL_LIGHTING
  glCallList sphere
  Material White
  glPopMatrix
  '
  'GREEN PLANE
  glPushMatrix
  glEnable      GL_TEXTURE_2D
  glTranslatef  0.0,-2.0,-15.0
  glScalef      16.,1.,16.
  int t1=texn[11]
  glBindTexture GL_TEXTURE_2D,t1
  RenderPlane   0.,0.,8.,8.
  glDisable     GL_TEXTURE_2D
  glPopMatrix
  '
  '
  'CRAFT MOVING
  '
  class vclass
  float x,y,z
  float a.x,a.y,a.z
  end class
  '
  static vclass t={-2.0,1.0,-8.0}
  static float dx,dy,dz
  '
  if lastkey=49 then picked=lastkey-48
  if picked>=1 and picked<=9
    MoveObjectWithMouse t
    MoveObjectWithKeys  t, 0.025, 1.0
  end if
  '
  'CRAFT GROUND SHADOW
  '
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[4]
  glPushMatrix
  glTranslatef t.x+dx+1.0, -1.97, t.z+dz-1.0 'soft shadow
  glRotatef    ang1,0,1,0
  glScalef     6.,1.,6.
  RenderPlane  0.,0.,1.,1.
  glPopMatrix
  glDisable GL_TEXTURE_2D
  '
  '


  'CRAFT MAIN BODY
  '
  PickLabel 1
  '
  glPushMatrix
  glTranslatef t.x+dx,t.y+dy,t.z+dz
  glRotatef    t.a.x,1,0,0
  glRotatef    t.a.y,0,1,0
  glRotatef    t.a.z,0,0,1
  glRotatef    10.,1,0,0 'jaunty angle
  glScalef      3.,.5,3.
  Material Silver
  glCallList sphere

  int i

  'FINS

  for i=0 to 5
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.5,.20,.0
  glScalef      .4,.89,.15
  glCallList sphere
  glPopMatrix
  next
  '
  'THRUSTERS
  '
  for i=0 to 5
  glpushMatrix
  glRotatef i*60.0,0,1,0
  glTranslatef -.75,-.60,.00
  glScalef      .10, .30,.10
  glCallList sphere
  glPopMatrix
  next
  '
  'CABIN
  '
  glTranslatef .00,.99,.00
  glScalef     .50,1.99,.50
  Material Alloy
  glCallList sphere
  '
  'PORTS
  '
  for i=0 to 5
  glpushMatrix
  glRotatef 30.0+i*60.0,0,1,0
  glTranslatef .90,.10,.00 
  Material BlackShiny
  glscalef .10,.40,.20
  glCallList sphere
  glPopMatrix
  next
  '

  glPopMatrix 'end of craft main body
  '

  PickLabel 0

  '

  'CONTROL PANEL
  '
  scope
    static ControlPanelB cb
    if closing
      cb.destructor
      exit sub
    endif
    if cb.sc=.0 then cb.sc=.75  : cb.lock=1 'initial

    static float my,mm
    '
    'POSITION
    '
    if mposy>crect.bottom-15
      if my=0 then mm=.01 : actn=100
    elseif mposy<crect.bottom>>1
      if my>0 then mm=-.01 : actn=100
    end if
    if mm
      my+=mm
      if my>.414 then my=.414 : mm=0 : actn=0
      if my<0 then my=0 : mm=0 : actn=0
    end if
    '
    'BUILD
    '
    if my >.1
      glpushmatrix
      gltranslatef .0,-.675+my,-1.0
      float a=limit(500.0,crect.bottom,2000.0)
      cb.sc=400/a
      cb.act 0 'optional base id: 0000 1000 2000 3000 etc

      t.x+=.015*cb.j.vx
      t.y+=.015*cb.c[8].vy
      t.z-=.015*cb.j.vy
      t.a.x+=.090*cb.c[5].vy
      t.a.y+=.180*cb.c[6].vy
      t.a.z+=.090*cb.c[7].vy
      if t.y<-1.0 then t.y=-1.0 'on ground

      glpopmatrix
    end if
  end scope
  '
  EndPick
  '
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  '
  end sub
  '
  MainWindow width,height,WS_OVERLAPPEDWINDOW
