Skip to content

Instantly share code, notes, and snippets.

@suzumura-ss
Last active December 17, 2015 16:59
Show Gist options
  • Save suzumura-ss/5643130 to your computer and use it in GitHub Desktop.
Save suzumura-ss/5643130 to your computer and use it in GitHub Desktop.
Ruby/openGLでteapotを表示
require 'opengl'
$rot = 0.0
def display
glEnable(GL_DEPTH_TEST)
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glClearColor(0.0, 0.0, 1.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glColor3d(1.0, 0.0, 0.0)
glLightfv(GL_LIGHT0, GL_POSITION, [1, 3, 1, 1])
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, [1, 0, 0, 1])
glPushMatrix();
glRotatef($rot, 1, 0, 0)
glRotatef($rot * 1.1, 0, 1, 0)
glutSolidTeapot(0.5)
glPopMatrix()
$rot += 0.1
glutSwapBuffers()
end
def reshape(w, h)
glViewport(0, 0, w, h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-1.5, 1.5, -1.5, 1.5, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
end
def keyboard(key, x, y)
exit(0) if key=='q'
end
glutInitWindowPosition(200, 200)
glutInitWindowSize(800, 600)
glutInit(ARGV)
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH)
glutCreateWindow("ruby-pot")
glutDisplayFunc(lambda{ display })
glutReshapeFunc(lambda{|w,h| reshape(w, h) })
glutKeyboardFunc(lambda{|k, x, y| keyboard(k, x, y) })
glutIdleFunc(lambda{ glutPostRedisplay })
glutMainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment