
  #case capital

  '$ FileName "t.exe"
  'uses rtl32
  $ title     "Rotating Images"
  uses OpenglSceneFrame

  def nims 3
  sys GdiplusToken
  sys texn[nims],wi[nims],ht[nims]


  sub Initialize(sys hWnd)
  '=======================

  'USING GDIPLUS

  sys hr
  GdiplusStartupInput StartupInput

  StartupInput.GdiplusVersion = 1
  hr=GdiplusStartup GdiplusToken, StartupInput, byval 0
  '
  if hr then
    print "Error initializing GDIplus: " hex hr
    exit function
  end if
  '
  '
  'Prepare Textures
  '----------------
  '
  glGenTextures nims, texn
  '
  sys i,p,res
  string imgs[nims]
  LoadPixImage  "../images/fruitfly1.jpg",res,imgs[1],wi[1],ht[1]
  LoadPixImage "../images/human1.jpg",res,imgs[2],wi[2],ht[2]
  LoadPixImage  "../images/head1.jpg",res,imgs[3],wi[3],ht[3]
  '
  '
  'RENDER WHITE BACKGROUND TRANSPARENT
  '
  sys e
  for i=1 to nims
    e=wi[i]*ht[i] 'number of pixels
    p=*imgs[i]
    mov edx,e
    mov ecx,p
    (
      mov eax,[ecx]
      (
        'R G channels of RGBA
        cmp al,240
        jb exit
        cmp ah,240
        jb exit
        mov al,0
        mov [ecx],0 'zero including alpha
      )
      add ecx,4 'step next pixel
      dec edx
      jg repeat
     ) 
     MakeTexture *imgs[i],wi[i],ht[i],texn[i]
   next
  '
  glEnable GL_BLEND
  glBlendFunc GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA
  'glEnable GL_DEPTH_TEST
  glDepthFunc GL_LEQUAL
  '

  end sub 'initialize


  sub Release(sys hWnd)
  '====================
  glDeleteTextures 1, texn
  GdiplusShutdown GdiplusToken
  end sub 


  sub scene(sys hWnd)
  '==================
  '
  static single ang1, angi1=1
  static single sx,sy,sz,sc,x,y,z
  '
  Snapshots hwnd 'Ctrl-P to take snapshot
  '
  glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT
  glClearColor 0.5, 0, 0, 0
  glLoadIdentity
  '
  'ACTIVATE TEXTURE
  '----------------
  '
  glEnable GL_TEXTURE_2D
  glBindTexture GL_TEXTURE_2D,texn[1]
  '
  sx=1 : sy=1 : sz=-1 : sc=.2
  '
  '
  'MOVEMENT
  '--------
  '
  int i
  for i=1 to nims
  '
  glpushmatrix
  '
  x=cos(rad(ang1))*.4 : y=sin(rad(ang1))*.2 : z=0
  if i=1 then glrotatef ang1*2, 0,0,1
  if i=3 then gltranslatef x,y,z
  if i=2 then gltranslatef .6,.0,-1.1
  glScalef .2,.2,1
  
  '
  'DRAW SHAPE
  '----------
  '
  'this quad is drawn clockwise
  '
  '
  glBindTexture GL_TEXTURE_2D,texn[i]
  glbegin GL_QUADS
  '
  sx=wi[i]/256
  sy=ht[i]/256
  glTexCoord2f 0,0  : glvertex3f -sx, -sy,  sZ
  glTexCoord2f 0,1  : glvertex3f -sx,  sy,  sZ
  glTexCoord2f 1,1  : glvertex3f  sx,  sy,  sZ
  glTexCoord2f 1,0  : glvertex3f  sx, -sy,  sZ
  '
  glend
  glpopmatrix
  '
  next
  '
  glDisable GL_TEXTURE_2D
  '
  '
  'UPDATE ROTATION ANGLES
  '----------------------
  '
  ang1+=angi1
  if ang1>720 then ang1-=720
  '
  '
  end sub


