  % Title "Sphere Mapping Demo"
  % Animated
  % ScaleUp
 '% PlaceCentral
 '% AnchorCentral
  $ filename "t.exe"
 'uses RTL64
  uses ConsoleG

  function SphereMap(int nPrecision)
  ==================================
  'From Mike Lobanovsky / Sphere mapping
  float ex,ey,ez,theta1,theta2,theta3
  float M_TWOPI = pi()*2
  float M_PI_2  = pi()/2
  int   i,j,ei
  ei=(nprecision-1)\2
  For i = 0 To ei
    theta1 = i * M_TWOPI / nPrecision - M_PI_2
    theta2 = (i + 1) * M_TWOPI / nPrecision - M_PI_2
    glBegin(GL_TRIANGLE_STRIP)
    For j = 0 To nPrecision
      theta3 = j * M_TWOPI / nPrecision
      ' Splices
      ex = cos(theta2) * cos(theta3) ' calculate Euler angles on 3 axes
      ey = sin(theta2)
      ez = cos(theta2) * sin(theta3)
      glNormal3f(ex, ey, ez) ' set up normals
      glTexCoord2f(-j / nPrecision, 2 * (i + 1) / nPrecision) ' set up UVs
      glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez) ' render vertices
      ' Sides
      ex = cos(theta1) * cos(theta3)
      ey = sin(theta1)
      ez = cos(theta1) * sin(theta3)
      glNormal3f(ex, ey, ez)
      glTexCoord2f(-j / nPrecision, 2 * i / nPrecision)
      glVertex3f(1.5 * ex, 1.5 * ey, 1.5 * ez)
    Next
    glEnd()
  Next
  end function

  sub main()
  ==========
  static int   imgn,res,wi,ht,earth
  static float angx,angy
  if not imgn
    imgn=21
    res=0 'use image wi and ht (512*256)
    LoadTexture "..\..\images\Earth.jpg",imgn,res,wi,ht
   'LoadTexture "NASA_Blue_Marble.jpg",imgn,res,wi,ht
   'http://www.johnstonsarchive.net/spaceart/earthmap.jpg
   'LoadTexture "earthmap.jpg",imgn,res,wi,ht
    earth=CompileList : SphereMap 128 : glEndlist
  end if
  cls '0,0,0
  'display image
  '
  pushstate
  move 16,-16
  shading
  color 1,1,1,1
  texture imgn
  scale 8
 'rotateX angX
  rotateY angY
  go earth
  'quadnorm 10.0, 10.0 'apply image texture to quad
  texture 0
  popstate
 flat
 move 0,-.5
 scale 2
 printl "Sphere Mapping"
  angx+=.100 : if angx>=360 then angx-=360
  angy+=.125 : if angy>=360 then angy-=360
  end sub 'main

  EndScript