Skip to content

Instantly share code, notes, and snippets.

@pjc0247
Last active December 14, 2015 12:48
Show Gist options
  • Save pjc0247/5088847 to your computer and use it in GitHub Desktop.
Save pjc0247/5088847 to your computer and use it in GitHub Desktop.
Ruby-opengl
require 'opengl'
require 'glu'
require 'glut'
$x = 0
$y = 0
def onMove(x,y)
$x = x
$y = y
end
def onRender
glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 40, 480/320, -10,10
gluLookAt $x, $y, $y, 1, 1, 1, 0, 1, 0
glMatrixMode GL_MODELVIEW
glLoadIdentity
glMaterialfv GL_FRONT, GL_SPECULAR, [1, 1, 1, 1]
glMaterialfv GL_FRONT, GL_SHININESS, [20]
glutSolidTeapot 10
glutSwapBuffers
end
begin
# initialize glut library
glutInit
# initialize glut window
glutInitWindowPosition 100,100
glutInitWindowSize 480,320
glutInitDisplayMode GLUT_DEPTH | GLUT_RGBA | GLUT_DOUBLE
# create glut window
glutCreateWindow "ruby-gl"
# regist callback methods
glutDisplayFunc :onRender
glutIdleFunc :onRender
glutMotionFunc :onMove
# set up environments
glEnable GL_DEPTH_TEST
glEnable GL_LIGHTING
glEnable GL_LIGHT0
glLightfv GL_LIGHT0, GL_POSITION, [10, 10, 10, 0]
glLightfv GL_LIGHT0, GL_AMBIENT, [1, 0, 1, 1]
glLightfv GL_LIGHT0, GL_DIFFUSE, [0, 1, 1, 1]
glLightfv GL_LIGHT0, GL_SPECULAR, [1, 1, 1, 1]
# start program
glutMainLoop
rescue
p "Error : #{$!}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment