Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
IO 1.66 KB | None | 0 0
  1. #!/usr/bin/env io
  2.  
  3. GLCylinderApp := Object clone do(
  4.     appendProto(OpenGL)
  5.  
  6.     angleX := -45
  7.     angleY := 0
  8.     lastX := 0
  9.     lastY := 0
  10.    
  11.     reshape := method(w, h,
  12.         glMatrixMode(GL_PROJECTION)
  13.         glLoadIdentity
  14.         gluPerspective(45, w / h, 1.0, 10.0)
  15.         glMatrixMode(GL_MODELVIEW)
  16.         glViewport(0, 0, w, h)
  17.     )
  18.  
  19.     display := method(
  20.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  21.        
  22.         glLoadIdentity
  23.         glTranslated(0, 0, -5)
  24.         glRotated(angleX, 1, 0, 0)
  25.         glRotated(angleY, 0, 1, 0)
  26.  
  27.         glTranslated(0, 0, -1.5)
  28.  
  29.         cylinder useFillStyle
  30.         cylinder draw
  31.  
  32.         glDisable(GL_LIGHTING)
  33.         glColor4d(.4,.4,.4, 1)
  34.         cylinder useLineStyle
  35.         cylinder draw
  36.         glEnable(GL_LIGHTING)
  37.        
  38.         glFlush
  39.         glutSwapBuffers
  40.     )
  41.  
  42.     mouse := method(button, state, x, y,
  43.         lastX = x
  44.         lastY = y
  45.     )
  46.  
  47.     motion := method(x, y,
  48.         angleX = angleX + (y - lastY)
  49.         angleY = angleY + (x - lastX)
  50.         lastX = x
  51.         lastY = y
  52.         glutPostRedisplay
  53.     )
  54.  
  55.     run := method(
  56.         glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
  57.         glutInitWindowSize(512, 512)
  58.         glutInit; glutCreateWindow("Io Cylinder")
  59.         glutEventTarget(self)
  60.         glutReshapeFunc
  61.         glutDisplayFunc
  62.         glutMouseFunc
  63.         glutMotionFunc
  64.        
  65.         glClearColor(1, 1, 1, 1)
  66.         glEnable(GL_DEPTH_TEST)
  67.         glEnable(GL_LIGHTING)
  68.         glEnable(GL_LIGHT0)
  69.         glDisable(GL_CULL_FACE)
  70.        
  71.         glEnable(GL_BLEND)
  72.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
  73.         glEnable(GL_LINE_SMOOTH)
  74.         glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
  75.         glLineWidth(2)
  76.        
  77.         self cylinder := GLUCylinder clone do(
  78.             setBaseRadius(1.0)
  79.             setTopRadius(1.0)
  80.             setHeight(3.0)
  81.             setSlices(16)
  82.             setStacks(8)
  83.         )
  84.    
  85.         glutMainLoop
  86.     )
  87. )
  88.  
  89. GLCylinderApp clone run
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement