Hi,
as I still haven't managed to build LuaGL, I now tested luaglut (0.5) with Gem, downloaded from here: http://lua-users.org/files/wiki_insecure/users/VarolKaptan/
This wins over LuaGL in the makeability contest with a README and a working Makefile, but lacks a bit in documentation. Anyway I still managed to "port" IOhannes' example posted some time ago from LuaGL to luaglut easily, and even extend it.
It's attached and the Pd example also compares rendering many lines with luagl over rendering them with Gem and double gemheads. Lua wins by an amazing margin on my machine: Lua is twice as fast as Pd when rendering 1000 lines here. I guess I'll be using luaglut in Pd quite a bit from now on, that's too much of a speedup to ignore for the tiny effort required. ;)
But one thing, which maybe only Claude can answer, makes me wonder, probably because I don't yet understand how the combination Lua/Gem/Pd works in general.
In the Lua file (attached), I have a method "render()" to do the rendering. This method is called whenever the object receives a "gem_state" in its 1st inlet. This looks a bit like black magic to me: How gets the stuff that M:render() renders with GL-commands finally get attached to the gem-state and transferred into the Gem-window?
function M:in_1(sel, atoms) if sel == "gem_state" then M:render(self) end end
function M:render(myself) -- Why can't I use "self" directly here?????? -- "self" seems to be a different table inside M:render(). Why? -- myself is not equal to self here max = math.max(myself.max, 1) glBegin(GL_LINES) for i=1,max do glColor3d(math.random(), math.random(), 0) glVertex2d(0, 0) glVertex2d(math.random(-400,400)/100, math.random(-400,400)/100) end glEnd() end
And the second black magic bullet that hit me: Normally all methods of a Pd class written in Lua get the same "self" passed. But M:render() seems to be different here: If I try to access the self.max value directly inside M:render(), it is "nil". Printing "self" in various places also gives different table-pointers, so the "self" in M:render() and the "self" in the other methods are different tables. I worked around this by passing the Pd class "self" as "myself", but for one this is awkward, and more importantly: I just don't get what makes M:render() special?
Anyone with good explanations?
Ciao
hey frank, I stopped all of my work after reading your email, because I got really excited, and wanted to try that too. I got lua 5.1.1 from http://www.algonet.se/~afb/lua/ and put it into /sw/lib/lua/5.1 (on my os x 10.5.1). when I open your patch, first, luagl gets created and I get some drawing (even with no gemhead turned on, which strange), but I only see 2 or so lines at a time and a constant error stream: lua: error in dispatcher: [string "pd.lua"]:133: attempt to call field '_error' (a nil value) lua: warning! pointers untested lua: warning! pointers untested you think I need lua 5.1.2? I also ran into building issues before... I don't know which pdlua version I am using. maybe I have to reinstall that also. marius.
Frank Barknecht wrote:
Hi,
as I still haven't managed to build LuaGL, I now tested luaglut (0.5) with Gem, downloaded from here: http://lua-users.org/files/wiki_insecure/users/VarolKaptan/
This wins over LuaGL in the makeability contest with a README and a working Makefile, but lacks a bit in documentation. Anyway I still managed to "port" IOhannes' example posted some time ago from LuaGL to luaglut easily, and even extend it.
It's attached and the Pd example also compares rendering many lines with luagl over rendering them with Gem and double gemheads. Lua wins by an amazing margin on my machine: Lua is twice as fast as Pd when rendering 1000 lines here. I guess I'll be using luaglut in Pd quite a bit from now on, that's too much of a speedup to ignore for the tiny effort required. ;)
But one thing, which maybe only Claude can answer, makes me wonder, probably because I don't yet understand how the combination Lua/Gem/Pd works in general.
In the Lua file (attached), I have a method "render()" to do the rendering. This method is called whenever the object receives a "gem_state" in its 1st inlet. This looks a bit like black magic to me: How gets the stuff that M:render() renders with GL-commands finally get attached to the gem-state and transferred into the Gem-window?
function M:in_1(sel, atoms) if sel == "gem_state" then M:render(self) end end function M:render(myself) -- Why can't I use "self" directly here?????? -- "self" seems to be a different table inside M:render(). Why? -- myself is not equal to self here max = math.max(myself.max, 1) glBegin(GL_LINES) for i=1,max do glColor3d(math.random(), math.random(), 0) glVertex2d(0, 0) glVertex2d(math.random(-400,400)/100, math.random(-400,400)/100) end glEnd() end
And the second black magic bullet that hit me: Normally all methods of a Pd class written in Lua get the same "self" passed. But M:render() seems to be different here: If I try to access the self.max value directly inside M:render(), it is "nil". Printing "self" in various places also gives different table-pointers, so the "self" in M:render() and the "self" in the other methods are different tables. I worked around this by passing the Pd class "self" as "myself", but for one this is awkward, and more importantly: I just don't get what makes M:render() special?
Anyone with good explanations?
Ciao
GEM-dev mailing list GEM-dev@iem.at http://lists.puredata.info/listinfo/gem-dev
marius schebella wrote:
lines at a time and a constant error stream: lua: error in dispatcher: [string "pd.lua"]:133: attempt to call field '_error' (a nil value) lua: warning! pointers untested lua: warning! pointers untested you think I need lua 5.1.2? I also ran into building issues before...
i think the "pointers untested" warning comes from pdlua. are you using the latest and greatest version of pdlua?
fmgasdr. IOhannes
Hallo, marius schebella hat gesagt: // marius schebella wrote:
I stopped all of my work after reading your email, because I got really excited, and wanted to try that too. I got lua 5.1.1 from http://www.algonet.se/~afb/lua/ and put it into /sw/lib/lua/5.1 (on my os x 10.5.1). when I open your patch, first, luagl gets created and I get some drawing (even with no gemhead turned on, which strange), but I only see 2 or so lines at a time and a constant error stream: lua: error in dispatcher: [string "pd.lua"]:133: attempt to call field '_error' (a nil value) lua: warning! pointers untested lua: warning! pointers untested you think I need lua 5.1.2? I also ran into building issues before... I don't know which pdlua version I am using. maybe I have to reinstall that also.
You should install the newer pdlua. Claude did some work on pointers and gem-states, and you appear to be using the old version. It also changed the numbering of inlets to be more Lua-like (where counting starts at 1 instead of 0). Lua 5.1 is the recommended Lua version to use, too.
Ciao
Frank Barknecht wrote:
Anyone with good explanations?
M is the class, self is the instance.
function M:in_1(sel, atoms) if sel == "gem_state" then M:render(self) end end
Try replacing M:render(self) with self:render() ?
(Don't have time to test this right now, but I think that's the solution...)
Hope this helps,
Claude
Hallo, Claude Heiland-Allen hat gesagt: // Claude Heiland-Allen wrote:
Frank Barknecht wrote:
Anyone with good explanations?
M is the class, self is the instance.
function M:in_1(sel, atoms) if sel == "gem_state" then M:render(self) end end
Try replacing M:render(self) with self:render() ?
Ah, of course, as x:y() is syntactical sugar for x.y(x) I need to use self:render() to get self.render(self). ..
So no need to test, it's a silly bug in my code.
Ciao