Comment detail

ポリゴンを表示するプログラム (Nested Flatten)
Ruby/SDLとOpenGLでベタに書いてみました。
 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
require 'sdl'
require 'opengl'

vertices = [
  [[1.0, 0.0, 0.0], [-1.0, -1.0, 0.0]],
  [[0.0, 1.0, 0.0], [ 1.0, -1.0, 0.0]],
  [[0.0, 0.0, 1.0], [ 1.0,  1.0, 0.0]],
  [[1.0, 1.0, 1.0], [-1.0,  1.0, 0.0]]
]

SDL.init(SDL::INIT_VIDEO)
SDL::Screen.open(600, 600, 16, SDL::OPENGL)

GL.ClearColor(0.0, 0.0, 0.2, 1.0);
GL::Ortho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0)
GL::MatrixMode(GL::MODELVIEW);

loop {
  GL.Clear(GL::COLOR_BUFFER_BIT);
  
  GL::Rotate(1.0, 2.0, 3.0, 1.0);
  
  GL::Begin(GL::QUADS)
  vertices.each {|v|
    GL::Color(v[0])
    GL::Vertex(v[1])
  }  
  GL::End()
  
  SDL::GL.swap_buffers
  
  evt = SDL::Event.poll
  case evt
  when SDL::Event::Quit
    exit
  when SDL::Event::KeyUp
    exit if evt.sym == SDL::Key::ESCAPE
  end
}

Index

Feed

Other

Link

Pathtraq

loading...