-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.rb
87 lines (71 loc) · 2 KB
/
draw.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'opengl'
require 'glu'
require 'glut'
include Gl
include Glu
include Glut
def display
glDepthFunc(GL_LEQUAL)
glEnable(GL_DEPTH_TEST)
# Activamos el el Z-Buffer
glClearColor(0.0,0.0,0.0,0.0)
glClearDepth(1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
light_1_position = [20.0, 20.0, 30.0]
light_2_position = [-20.0, -20.0, 50.0]
color = [1.0,1.0,1.0,1.0]
color2 = [0.0,1.0,1.0,1.0]
ambient = [0.2,0.2,0.2,0.1]
shine = 1.0
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
glEnable(GL_LIGHT1)
glEnable(GL_COLOR_MATERIAL)
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE)
glMaterialfv(GL_FRONT, GL_SPECULAR, color)
glMaterialf(GL_FRONT, GL_SHININESS, shine * 128.0)
glEnable(GL_NORMALIZE)
glShadeModel(GL_SMOOTH)
glLightfv(GL_LIGHT0,GL_POSITION,light_1_position)
glLightfv(GL_LIGHT0,GL_DIFFUSE,color)
glLightfv(GL_LIGHT0,GL_SPECULAR,color)
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient)
# Borramos el buffer de color y el Z-Buffer
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(40.0,1.0,1.0,120.0)
glMatrixMode(GL_MODELVIEW)
glTranslatef(0.0,0.0,-4.0)
# Esfera 1
glPushMatrix()
glColor3f(1.0,0.8,0.5)
glTranslatef(0.9,0.9,0)
glutSolidSphere(0.9, 50, 50);
glPopMatrix()
# Esfera 2
glPushMatrix()
glColor3f(0.1,0.2,1.0)
glTranslatef(0.9,-0.9,0)
glutSolidSphere(0.9, 50, 50);
glPopMatrix()
# Esfera 3
glPushMatrix()
glColor3f(1.0,0.6,1.0)
glTranslatef(-0.9,-0.9,0)
glutSolidSphere(0.9, 50, 50);
glPopMatrix()
# Esfera 4
glPushMatrix()
glColor3f(0.1,1.0,1.0)
glTranslatef(-0.9,0.9,0)
glutSolidSphere(0.9, 50, 50);
glPopMatrix()
glFlush()
end
glutInit
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH)
glutInitWindowSize(500,500)
glutInitWindowPosition(20,20)
glutCreateWindow("Draw Four Spheres")
glutDisplayFunc :display
glutMainLoop