[ruby-opengl-devel] new callback added in glut_callbacks.i

minh thu noteed at gmail.com
Wed Aug 30 10:02:39 EDT 2006


what follows is a copy of a file meant to try to move gl_callbacks.i
to some .rb file.
it doesn't handle '4' version.
(disclaimer : I use ruby for 3 weeks now :)
---

# ropengl.rb
#
# The idea for this file is to provide rubyish version of opengl functions.
# I.e. the kind of thing provided by opengl_untyped.i.
#
# We map to gl*d versions because ruby float corresponds to c double.
# Or provide both, or a switch ( rglFloatFormat(RGL_FLOAT) )?
# But, IMO, we're in a scripting language, we can do with double.
# Moreover, if it's a matter of speed, we'll not use these conveniences.
#
#  --thu
#

require 'matrix'

# dummy opengl methods to try.
def glVertex3d( x, y, z )
  puts "glVertex3d #{x}, #{y}, #{z}"
end

def glVertex2d( x, y )
  puts "glVertex2d #{x}, #{y}"
end

def glVertex3dv( xyz )
  puts "glVertex3dv #{xyz[0]}, #{xyz[1]}, #{xyz[2]}"
end

def glVertex2dv( xy )
  puts "glVertex2dv #{xy[0]}, #{xy[1]}"
end

# 3 cases : one array, one vector, or some floats.
# For each case : there can be 2, 3, or 4 elements.
def glVertex( *a )
  if a.length == 1 and a[0].kind_of? Array
    case a[0].length
    when 2
      glVertex2dv a[0]
    when 3
      glVertex3dv a[0]
    else
      puts "glVertex : wrong array length : #{a[0].length}"
    end # case a[0].length
    return
  end

  if a.length == 1 and a[0].kind_of? Vector
    case a[0].size
    when 2
      glVertex2dv a[0].to_a
    when 3
      glVertex3dv a[0].to_a
    else
      puts "glVertex : wrong vector size : #{a[0].size}"
    end # case a[0].size
    return
  end

  if a.length == 2
      glVertex2dv a
      return
  end

  if a.length == 3
      glVertex3dv a
      return
  end

  puts "glVertex : wrong number of argument"
  nil
end

glVertex2d 5.0, 6.0
glVertex3d 7.0, 8.0, 9.0
glVertex2dv [5.0, 6.0]
glVertex3dv [7.0, 8.0, 9.0]

glVertex [1.0, 2.0]
glVertex [3.0, 4.0, 5.0]
glVertex 1.0, 2.0
glVertex 3.0, 4.0, 5.0

v1 = Vector[1.0]
v2 = Vector[1.0, 2.0]
v3 = Vector[1.0, 2.0, 3.0]
v4 = Vector[1.0, 2.0, 3.0, 4.0]
glVertex v1
glVertex v2
glVertex v3
glVertex v4

glVertex [1.0, 2.0, 3.0, 4.0]
glVertex [1.0]
glVertex 1.0, 2.0, 3.0, 4.0
glVertex 1.0



2006/8/30, minh thu <noteed at gmail.com>:
> I forgot the attachment...
>
>


More information about the ruby-opengl-devel mailing list