  $ filename "t.exe"
  'uses rtl64


  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,z

  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


  dim vector pv[4000], int pj

  function Curve(vector *r1,*rc,*r2)
  ======================================
  vector r3,r4,rr
  int    i,n
  float  q,f
  indexbase 0
  n=25   'steps
  f=1/n  'increment
  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
    copy @pv[pj],@rr,sizeof vector
    pj++
  next
  end function


  function RoundedShape(vector*pt, sys e, float q)
  ================================================
  vector r1,r2,r3,rc
  int    j
  int    j1,j2,j3
  float  q1,q2,f
  q1=q
  q2=1-q
  indexbase 0
  for j=0 to < e 'each pair of control lines
    j1=j
    j2=mod(j1+1,e)
    j3=mod(j2+1,e)
    InterpLine q1,pt[j1],pt[j2],r1
    InterpLine q2,pt[j2],pt[j3],r2
    InterpLine q1,pt[j2],pt[j3],r3
    Curve r1,pt[j2],r2
    'IN-FILL
    copy @pv[pj],@rc,sizeof vector : pj++
    copy @pv[pj],@r2,sizeof vector : pj++
    copy @pv[pj],@r3,sizeof vector : pj++
  next
  end function


  function Render(sys n,t,c)
  ==========================
  vector *rr,rc
  int    i,j,b,e
  indexbase 0
  for i=1 to c
    e=b+n-1
    glBegin GL_TRIANGLE_FAN
    'glBegin GL_LINE_STRIP
    glVertex2f rc.x,rc.y
    for j=b to e
      @rr=@pv[j]
      glVertex3f rr.x,rr.y,rr.z
    next
    glEnd
    glBegin GL_TRIANGLE_FAN
    'glBegin GL_LINE_STRIP
    b+=n
    e+=t
    for j=b to e
      @rr=@pv[j]
      glVertex3f rr.x,rr.y,rr.z
    next
    glEnd
    b+=3
  next 'i
  end function


  sub scene(sys hWnd)
  ===================
  float scl=0.25
  StillFrame
  glClearColor  0.3, 0.0, 0.0, 0.0
  glTranslatef  0.0,-0.1,-1.0
  glScalef      scl,scl,scl
  glColor3f     0.5, 1.0, 1.0 ' color 14
  glLinewidth   2.0
  '
  BeginGlCompile shape
  vector pt[]={ {-1,-1},{1,-1},{1,1},{.5,1},{.5,1.7},{-.5,1.7},{-.5,1},{-1,1} }
  RoundedShape pt,8,0.5
  Render 26,3,8
  'vector array, elements, curve control 0.0 to 0.5
  EndGlCompile
  go shape
  end sub


