[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

can opengl work with an object method?

anne001

2/21/2006 12:33:00 AM

I started with robot.rb in the sample folder of opengl-0.32g

It comes with a display proc:
display = Proc.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 = Node.new
GLUT.DisplayFunc(upperarm.traversetree);

displays the image in a different size, and does not respond to resize
or keyboard keys

Any option?

5 Answers

Logan Capaldo

2/21/2006 1:32:00 AM

0


On Feb 20, 2006, at 7:38 PM, anne001 wrote:

> I started with robot.rb in the sample folder of opengl-0.32g
>
> It comes with a display proc:
> display = Proc.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 = Node.new
> GLUT.DisplayFunc(upperarm.traversetree);
>
> displays the image in a different size, and does not respond to resize
> or keyboard keys
>
> Any option?
>
>

I'm pretty sure you meant to write:
GLUT.DisplayFunc(upperarm.method(:traversetree))



Ilmari Heikkinen

2/21/2006 2:17:00 AM

0

On 2/21/06, Logan Capaldo <logancapaldo@gmail.com> wrote:>> On Feb 20, 2006, at 7:38 PM, anne001 wrote:>> > GLUT.DisplayFunc(upperarm.traversetree);>> I'm pretty sure you meant to write:> GLUT.DisplayFunc(upperarm.method(:traversetree))>Except that GLUT insists on getting a Proc :|glut.c:22 if (!rb_obj_is_kind_of(arg1,rb_cProc) && !NIL_P(arg1)) rb_raise(rb_eTypeError, "GLUT.%s:%s",#_funcname,rb_class2name(CLASS_OF(arg1)));

George Ogata

2/21/2006 2:45:00 AM

0

"anne001" <anne@wjh.harvard.edu> writes:

> I started with robot.rb in the sample folder of opengl-0.32g
>
> It comes with a display proc:
> display = Proc.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 = Node.new
> GLUT.DisplayFunc(upperarm.traversetree);
>
> displays the image in a different size, and does not respond to resize
> or keyboard keys
>
> Any option?

It doesn't work because `upperarm.traversetree' calls #traversetree
and returns its value, rather than the method itself. If you want the
method itself, you need to do `upperarm.method(:traversetree)'.

However, it seems GLUT.DisplayFunc won't accept Method objects; only
Procs. Do that with Kernel#lambda:

GLUT.DisplayFunc(lambda{upperarm.traversetree})

Xavier Shay

2/21/2006 9:05:00 AM

0

Logan Capaldo wrote:
> On Feb 20, 2006, at 7:38 PM, anne001 wrote:
>
>> def traversetree
>>
>>
>
> I'm pretty sure you meant to write:
> GLUT.DisplayFunc(upperarm.method(:traversetree))

I'm pretty sure you meant to write:
GLUT.DisplayFunc(upperarm.method(:traversetree).to_proc)

Note the "to_proc" at the end. Just had to do this myself :)

--
Posted via http://www.ruby-....


anne001

2/21/2006 11:19:00 AM

0

Thank you to the four of you, this list is just amazing to help folks
like me.

George Ogata's idea worked!
GLUT.DisplayFunc(lambda{upperarm.traversetree})