Last active
December 14, 2015 12:48
-
-
Save pjc0247/5088847 to your computer and use it in GitHub Desktop.
Ruby-opengl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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