
  $ FileName  "t.exe"
  'uses rtl32
  'uses rtl64
  '
  % ExplicitMain
  % title     "Pick and display cone number"
  % fontA     "Arial",FW_SEMIBOLD

  'macro keydown
  'case 27 : 'no action
  'case 32 : 'no action
  'end macro
  '
  uses OpenglSceneFrame
  uses glo2\Textures

  indexbase 1
  float     ang1
  sys       cube,pent
  

  sub initialize(sys hWnd)
  ========================
  '
  '
  GDIplus 1
  '
  'PREPARE TEXTURES
  '
  '
'/*
  glGenTextures 16, texn
  static sys res=256,texspace
  texspace=res*res*4
  string imgs[2]
  imgs[1]=nuls texspace
  'LoadPixImage "../images/crate.jpg",res,imgs[1]
  '
  'pixbase,width,height,stride,colorval,offset
  --------------------------------------------
  AddNoiseC strptr imgs[1],res,res,32,050,050,100,-2,0x53535353 
  AddNoiseC strptr imgs[1],res,res,08,050,050,100, 0,0x35353535 
  AddNoiseC strptr imgs[1],res,res,04,070,070,050, 0,0x53535353 
  MakeTexture strptr imgs[1],res,res,texn[10]

'*/
'BuildTextures 16,256
  '
  pent=CompileList : Sides 5,1,1 : glEndList
  cube=CompileList : CubeForm    : glEndList
  '
  end sub

  sub Release(sys hwnd)
  '====================
  DeleteAllGlCompiled
  glDeleteTextures 16, texn
  Gdiplus 0
  end sub

  sub ConeNorm(float xb,xe,y,zb,ze,sm)
  ====================================
  'Configured As Front Face
  float zd=zb-ze
  glBegin GL_QUADS
  glNormal3f   -sm , zd  , y : glTexCoord2f 0.0 , 0.0 : glVertex3f -xb , 0 , zb  
  glNormal3f    sm , zd  , y : glTexCoord2f 1.0 , 0.0 : glVertex3f  xb , 0 , zb  
  glNormal3f    sm , zd  , y : glTexCoord2f 1.0 , y   : glVertex3f  xe , y , ze  
  glNormal3f   -sm , zd  , y : glTexCoord2f 0.0 , y   : glVertex3f -xe , y , ze
  glEnd
  end sub

  sub ConeSides(sys n,float xb,xe,y,sm)
  =====================================
  float rb=1.0,re=xe/xb
  float w=tan(pi/n)
  float a=360/n
  int i
  for i=1 to n
  ConeNorm xb*w,xe*w,y,rb,re,sm
  glRotatef a,0,1,0 'anticlockwise
  next
  end sub

  sub RenderCone(float x,y,z,sc,rz,ry,sys n,sm,tex)
  =================================================
  glBindTexture GL_TEXTURE_2D,tex
  glPushMatrix
  gltranslatef  x,y,z
  glrotatef     ang1,0,1,0
  glscalef      sc,sc,sc
  ConeSides     n,1.0,rz,ry,sm
  glPopMatrix
  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)
  '==================
  '
  static single ra,ri,angi1=.5
  '
  SnapShots hWnd 'Ctrl-P take snapshot
  NewFrame
  glClearColor 0.5, 0.5, 0.7, 0.0
  Fog          0.5, 0.5, 0.7, 0.05 'rgb and density

  Navigation

  glColor4f .99,.99,.99,.99
  BeginPick
  StandardLighting li
  StandardMaterial ma
  '
  indexbase 1
  sys   t1=texn[10]'texture
  sys   n=10       'sides
  float ra=0       'top/base ratio
  float ry=2.0     'height/base ratio
  float sm         'smoothing by Normal x adjustment
  '
  glEnable GL_TEXTURE_2D

  'shape locate x,y,z,size,ra,ry,nside,norm,tex
  ---------------------------------------------
  '
  sm=0
  PickLabel 4 : RenderCone  6.5,-0.9,-16.0, 0.5,ra,ry,n,sm,t1
  PickLabel 3 : RenderCone  2.5,-0.9,-8.0 , 0.5,ra,ry,n,sm,t1
  PickLabel 2 : RenderCone  0.5,-0.9,-4.0 , 0.5,ra,ry,n,sm,t1
  PickLabel 1 : RenderCone -0.5,-0.9,-2.0 , 0.5,ra,ry,n,sm,t1
  '
  PickLabel 0
  '
  'PLANE
  glPushMatrix
  glTranslatef  0.0,-2.0,-20.0
  glScalef      16.,1.,16.
  glBindTexture GL_TEXTURE_2D,t1
  RenderPlane   0.,0.,8.,8.
  glPopMatrix
  '
  glDisable GL_TEXTURE_2D
  glDisable GL_LIGHTING
  '
  glPushMatrix
  '
  glLoadIdentity
  static int framecount
  framecount++
  gltranslatef -.5,.25,-1.0
  glColor3f    .99,.50,.50
  glscalef     .06,.06,.01
  gprint       str(framecount)
  '
  glLoadIdentity
  PickLabel    100
  gltranslatef -.5,.35,-1.0
  float w,h
  glscalef     .07,.07,.01
  GetWordArea  "Cone:",w,h
  if pick
    PutBoxArea   w,h
  elseif picked
    glColor3f    .99,.99,.00
    gprint       "Cone: "
    glColor3f    .99,.99,.99
    gprint       picked
  end if
  glPopMatrix
  '
  EndPick
  '
  ang1+=angi1
  if ang1>360 then ang1-=360
  sleep 10
  end sub

  MainWindow width,height,WS_OVERLAPPEDWINDOW
