File: testgl.rb

package info (click to toggle)
ruby-sdl 2.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 4,344 kB
  • ctags: 4,200
  • sloc: cpp: 7,598; ansic: 4,475; ruby: 2,258; sh: 102; makefile: 97
file content (168 lines) | stat: -rw-r--r-- 3,231 bytes parent folder | download | duplicates (4)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# a sample with ruby-opengl and Ruby/SDL
require 'sdl'
require 'gl'

include Gl

# initialize SDL and opengl
SDL.init SDL::INIT_VIDEO
SDL::GL.set_attr SDL::GL_RED_SIZE,5
SDL::GL.set_attr SDL::GL_GREEN_SIZE,5
SDL::GL.set_attr SDL::GL_BLUE_SIZE,5
SDL::GL.set_attr SDL::GL_DEPTH_SIZE,16
SDL::GL.set_attr SDL::GL_DOUBLEBUFFER,1
SDL::Screen.open 640,400,16,SDL::OPENGL

glViewport( 0, 0, 640, 400 );
glMatrixMode( GL_PROJECTION );
glLoadIdentity( );

glMatrixMode( GL_MODELVIEW );
glLoadIdentity( );

glEnable(GL_DEPTH_TEST);

glDepthFunc(GL_LESS);

glShadeModel(GL_SMOOTH);

shadedCube=true

color =
  [[ 1.0,  1.0,  0.0], 
  [ 1.0,  0.0,  0.0],
  [ 0.0,  0.0,  0.0],
  [ 0.0,  1.0,  0.0],
  [ 0.0,  1.0,  1.0],
  [ 1.0,  1.0,  1.0],
  [ 1.0,  0.0,  1.0],
  [ 0.0,  0.0,  1.0]]

cube =
  [[ 0.5,  0.5, -0.5], 
  [ 0.5, -0.5, -0.5],
  [-0.5, -0.5, -0.5],
  [-0.5,  0.5, -0.5],
  [-0.5,  0.5,  0.5],
  [ 0.5,  0.5,  0.5],
  [ 0.5, -0.5,  0.5],
  [-0.5, -0.5,  0.5]]


loop do

  while event = SDL::Event2.poll
    case event
    when SDL::Event2::Quit, SDL::Event2::KeyDown
      exit
    end
  end

  glClearColor(0.0, 0.0, 0.0, 1.0);
  glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);


  glBegin(GL_QUADS) 

  if shadedCube then
    glColor(color[0]);
    glVertex(cube[0]);
    glColor(color[1]);
    glVertex(cube[1]);
    glColor(color[2]);
    glVertex(cube[2]);
    glColor(color[3]);
    glVertex(cube[3]);
    
    glColor(color[3]);
    glVertex(cube[3]);
    glColor(color[4]);
    glVertex(cube[4]);
    glColor(color[7]);
    glVertex(cube[7]);
    glColor(color[2]);
    glVertex(cube[2]);
    
    glColor(color[0]);
    glVertex(cube[0]);
    glColor(color[5]);
    glVertex(cube[5]);
    glColor(color[6]);
    glVertex(cube[6]);
    glColor(color[1]);
    glVertex(cube[1]);
    
    glColor(color[5]);
    glVertex(cube[5]);
    glColor(color[4]);
    glVertex(cube[4]);
    glColor(color[7]);
    glVertex(cube[7]);
    glColor(color[6]);
    glVertex(cube[6]);
    
    glColor(color[5]);
    glVertex(cube[5]);
    glColor(color[0]);
    glVertex(cube[0]);
    glColor(color[3]);
    glVertex(cube[3]);
    glColor(color[4]);
    glVertex(cube[4]);
    
    glColor(color[6]);
    glVertex(cube[6]);
    glColor(color[1]);
    glVertex(cube[1]);
    glColor(color[2]);
    glVertex(cube[2]);
    glColor(color[7]);
    glVertex(cube[7]);
    
  else
    glColor(1.0, 0.0, 0.0);
    glVertex(cube[0]);
    glVertex(cube[1]);
    glVertex(cube[2]);
    glVertex(cube[3]);
    
    glColor(0.0, 1.0, 0.0);
    glVertex(cube[3]);
    glVertex(cube[4]);
    glVertex(cube[7]);
    glVertex(cube[2]);
    
    glColor(0.0, 0.0, 1.0);
    glVertex(cube[0]);
    glVertex(cube[5]);
    glVertex(cube[6]);
    glVertex(cube[1]);
    
    glColor(0.0, 1.0, 1.0);
    glVertex(cube[5]);
    glVertex(cube[4]);
    glVertex(cube[7]);
    glVertex(cube[6]);
    
    glColor(1.0, 1.0, 0.0);
    glVertex(cube[5]);
    glVertex(cube[0]);
    glVertex(cube[3]);
    glVertex(cube[4]);
    
    glColor(1.0, 0.0, 1.0);
    glVertex(cube[6]);
    glVertex(cube[1]);
    glVertex(cube[2]);
    glVertex(cube[7]);
    
  end

  glEnd()
  
  glMatrixMode(GL_MODELVIEW);
  glRotate(5.0, 1.0, 1.0, 1.0);
  
  SDL::GL.swap_buffers

end