  string title = "Bezier Closed Shape Plot"
  int width  =   600
  int height =   600

  uses OpenglSceneFrame

  sub initialize(sys hWnd)
  ========================
  end sub


  sub Release(sys hwnd)
  =====================
  DeleteAllGlCompiled
  end sub

  type vector float x,y

  function InterpLine(float f1,vector *p1,*p2,*rr)
  ================================================
  float f2=1-f1
  rr.x=p1.x*f1 + p2.x*f2
  rr.y=p1.y*f1 + p2.y*f2
  end function


  function DrawCurve(vector *r1,*rc,*r2)
  ======================================
  vector r3,r4,rr
  int    i,n
  float  q,f
  indexbase 0
  n=100  'steps
  f=1/n  'increment
  glBegin GL_LINE_STRIP
  for i=0 to n 'plot curve
    q=i*f 'successive ooints
    InterpLine q,r1,rc,r3
    InterpLine q,rc,r2,r4
    InterpLine q,r3,r4,rr
    glVertex2f rr.x,rr.y
  next
  glEnd
  end function


  function DrawRoundShape()
  =========================
  float v=1.0
  vector pt[]={ {-v,-v},{v,-v},{v,v},{-v,v} } 'SQUARE
  vector r1,r2
  int    j
  int    j1,j2,j3
  float  q,f
  indexbase 0
  for j=0 to 3 'each pair of control lines
    j1=j      and 3
    j2=(j1+1) and 3
    j3=(j2+1) and 3
    q=.5  'for midpoints
    InterpLine q,pt[j1],pt[j2],r1
    InterpLine q,pt[j2],pt[j3],r2
    DrawCurve r1,pt[j2],r2
  next
  end function


  sub scene(sys hWnd)
  ===================
  StillFrame
  glClearColor  0.3, 0.0, 0.0, 0.0
  glTranslatef  0.0, 0.0,-1.0
  glScalef      0.3, 0.3, 0.3
  glColor3f     0.5, 1.0, 1.0 ' color 14
  glLinewidth   2.0
  '
  BeginGlCompile shape
  DrawRoundShape
  EndGlCompile
  go shape
  end sub


