------extPart_000_0BAE_01C6363F.CC189340
Content-Type: text/plain;
	format­´wed;
	charsetso-8859-1";
	reply-typeiginal
Content-Transfer-Encoding: 7bit

Hi,

From: "anne001" <anne / wjh.harvard.edu>
>
>I started with robot.rb in the sample folder of opengl-0.32g
> 
> It comes with a display proc:
> display  roc.new {}
> 
> which is called by a glut function
>  GLUT.DisplayFunc(display);
> 
> When I place the exact same code in a method
> class Node
>  def traversetree
>  end
> end
> 
> upperarm  ode.new
> GLUT.DisplayFunc(upperarm.traversetree);
> 
> displays the image in a different size, and does not respond to resize
> or keyboard keys
> 
> Any option?

I have a very simplistic Ruby wrapper for GLUT... It's small so
I've attached it to this email.

You can subclass GLUTWindow, and just override the methods you
want to add custom handlers for, for ex. reshape_func, keyboard_func,
display_func, draw_scene.  This example just overrides draw_scene...

  require 'opengl'
  require 'glut'
  require 'ftgl'

  case RUBY_PLATFORM
  when /mswin32/
    DEFAULT_FONT  C:/WINNT/Fonts/arial.ttf"
  when /darwin/
    DEFAULT_FONT  ./demo/arial.ttf"  # ???????????
  else
    DEFAULT_FONT  /usr/share/fonts/truetype/arial.ttf"
  end

  class MyWindow < GLUTWindow
    def initialize(left, top, wid, hgt, title, parentl)
      super
      font_filename  EFAULT_FONT
      @font  TGL::PixmapFont.new(font_filename)
      font_size  4
      @font.SetFaceSize(font_size)
    end

    def draw_scene
      super  # GLUTWindow#draw_scene will clear the screen for us
      
      GL.PolygonMode(GL::FRONT_AND_BACK, GL::FILL)
      GL.RasterPos(100, 50)
      @font.Render("hello world")
    end
  end

  GLUT.Init
  GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB)
  w  yWindow.new(100, 100, 800, 600, "hello")
  GLUT.MainLoop


The above example uses the 'ftgl' true-type-font extension[1], but
that's not required to use the GLUTWindow wrapper itself.

Hope this helps,

Bill

[1] http://rubyforge.org/projects/ruby-ftgl/


------extPart_000_0BAE_01C6363F.CC189340
Content-Type: application/octet-stream;
	namelut-window.rb"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filenamelut-window.rb"

#!/usr/bin/env ruby
#
#
# Usage example:
#   GLUT.Init
#   GLUT.InitDisplayMode(GLUT::DOUBLE | GLUT::RGB)
#   
#   main1  LUTWindow.new(100, 100, 800, 600, "foobar")
#   m1s1  ain1.new_child(10, 10, 320, 240, "foobar child1")
#   m1s2  ain1.new_child(400, 10, 320, 240, "foobar child2")
#   
#   main2  LUTWindow.new(100, 100, 800, 600, "xyzzy")
#   m2s1  ain2.new_child(10, 10, 320, 240, "xyzzy child1")
#   m2s2  ain2.new_child(400, 10, 320, 240, "xyzzy child2")
#   
#   GLUT.MainLoop
#


require 'opengl'
require 'glut'
# require 'ftgl'


class GLUTWindow
  
  def initialize(left, top, wid, hgt, title, parentl)
    @title  itle
    if parent
      @win  LUT.CreateSubWindow(parent, left, top, wid, hgt)
    else
      GLUT.InitWindowSize(wid, hgt)
      GLUT.InitWindowPosition(left, top)
      @win  LUT.CreateWindow(title)
    end
    @width, @height  , 1  # set by reshape_func
    @clear_color  0.0, 0.0, 0.0]
    
    GLUT.DisplayFunc(build_display_func)
    GLUT.ReshapeFunc(build_reshape_func)
    GLUT.KeyboardFunc(build_keyboard_func)
  end

  def new_child(left, top, wid, hgt, title)
    GLUTWindow.new(left, top, wid, hgt, title, @win)
  end

  protected

  def draw_scene
    c  clear_color
    GL.ClearColor(c[0], c[1], c[2], 0.0)
    GL.Clear(GL::COLOR_BUFFER_BIT)
  end

  def display_func
    draw_scene
    GLUT.SwapBuffers
  end

  def reshape_func(w, h)
   puts "reshape: winwin ww} hh}"
    @width, @height  , h
    do_ortho
  end
  
  def keyboard_func(key, x, y)
    case key
    when 27
      exit(0)
    end  
  end

  def do_ortho
    w, h  width, @height

    # Use the whole window.
    GL.Viewport(0, 0, w, h)

    # We are going to do some 2-D orthographic drawing.
    GL.MatrixMode(GL::PROJECTION)
    GL.LoadIdentity

    size  (w > ) ? w : h) / 2.0

    if w < 
      aspect  .to_f / w
      GL.Ortho(-size, size, -size*aspect, size*aspect, -100000.0, 100000.0)
    else
      aspect  .to_f / h
      GL.Ortho(-size*aspect, size*aspect, -size, size, -100000.0, 100000.0)
    end

    # Make the world and window coordinates coincide so that 1.0 in
    # model space equals one pixel in window space.
    GL.Scaled(aspect, aspect, 1.0)

    # Now determine where to draw things.
    GL.MatrixMode(GL::MODELVIEW)
    GL.LoadIdentity
  end

  def build_display_func
    Proc.new {display_func}
  end

  def build_reshape_func
    Proc.new {|w, h| reshape_func(w, h)}
  end

  def build_keyboard_func
    Proc.new {|key, x, y| keyboard_func(key, x, y)}
  end
end



------extPart_000_0BAE_01C6363F.CC189340--