primitive graphics application

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

primitive graphics application

Dave Smead
Greetings,

I'm a Lua newbie, but a programmer of many years using C and Python.
I've used Linux exclusively since 1994, Debian most of that time and
presently using Ubuntu 8.10.

At the moment I'm still having some difficulties getting Lua packages
installed because I'm not up to speed on luarocks yet.  I'm a little
hesitant to download packages outside the luarocks mechanism because I'm
painfully aware that grabbing a tar.gz file and running make will
sometimes clobber library versions that are used by programs obtained
via apt-get, (that is make a mess that is difficult to clean up).

My immediate interest is using Lua to access graphics primitives such as
draw-line, draw-circle, draw-arc, etc.  I see there are bindings to SDL,
opengl, wx, tk and others.  While I need some gui widgets, mostly I need
widgets that represent analog meters, and trend graphs, (plots). I have
C code from the 1980's that ran on DOS with a primitive vgalib so
primitive is fine for what I need.

Can anyone offer opinions of which graphics library would be best
suited?

The graphics rendering program will run on a Linux machine, but I want
to connect it via a TCP socket to a very small microcomputer that tells
the rendering program what to draw using ASCII strings, or better yet,
by passing a Lua table to the rendering program.

Thanks in advance for any words of wisdom.


David Smead
www.amplepower.com

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Timm S. Mueller
On Sun, 3 May 2009 22:15:04 -0700 (PDT)
Dave Smead <[hidden email]> wrote:

> At the moment I'm still having some difficulties getting Lua packages
> installed because I'm not up to speed on luarocks yet.  I'm a little
> hesitant to download packages outside the luarocks mechanism because I'm
> painfully aware that grabbing a tar.gz file and running make will
> sometimes clobber library versions that are used by programs obtained
> via apt-get, (that is make a mess that is difficult to clean up).
>
> My immediate interest is using Lua to access graphics primitives such as
> draw-line, draw-circle, draw-arc, etc.  I see there are bindings to SDL,
> opengl, wx, tk and others.  While I need some gui widgets, mostly I need
> widgets that represent analog meters, and trend graphs, (plots). I have
> C code from the 1980's that ran on DOS with a primitive vgalib so
> primitive is fine for what I need.
>
> Can anyone offer opinions of which graphics library would be best
> suited?

I don't know which package is best suited, but recently we have added a
graph class to tekUI [1] that might serve as an example for custom
visualizations. Widgets and some graphics primitives are provided, but
arc/circle functions are missing and would have to be emulated. Your
hesitance to install the package should be no issue, because you can
run the examples locally, without installing anything.

The installation docs [2] list the Ubuntu packages required to build
the project. After installing them, the following commands should be
sufficient to get the example on your screen:

# wget http://tekui.teklib.org/releases/tekui-snapshot.tar.gz
# tar xzf tekui-snapshot.tar.gz
# cd tekui-snapshot
# make all
# bin/meter.lua

See also the screenshots section to get an impression.

> The graphics rendering program will run on a Linux machine, but I want
> to connect it via a TCP socket to a very small microcomputer that tells
> the rendering program what to draw using ASCII strings, or better yet,
> by passing a Lua table to the rendering program.

Messages from the outside coming in via stdin are dispatched to the
toolkit and can be intercepted in custom classes, so all you had to do
would be to forward them from the network to your program. The
meter.lua example demonstrates how to register a handler that parses
them and causes a redraw:

 self.Application:addInputHandler(ui.MSG_USER, self, self.updateData)

- Timm

[1] http://tekui.teklib.org/
[2] http://tekui.teklib.org/installation.html

--
Timm S. Mueller <[hidden email]>
Schulze & Mueller GbR, Erbacher Straße 26, 64342 Seeheim-Jugenheim,
Gesellschafter: Franciska Schulze, Timm S. Mueller,
Tel. +49 6257 648853-0, http://www.schulze-mueller.de/
Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Asko Kauppi
In reply to this post by Dave Smead

My preference for Lua & graphics is Cairo.  There are multiple  
bindings even for this (one for Lua's curses, I must say).

Can you get Cairo to run on the embedded board, or maybe render on the  
server and just feed a raw image to the embedded one.

-asko


Dave Smead kirjoitti 4.5.2009 kello 8:15:

> Greetings,
>
> I'm a Lua newbie, but a programmer of many years using C and Python.
> I've used Linux exclusively since 1994, Debian most of that time and
> presently using Ubuntu 8.10.
>
> At the moment I'm still having some difficulties getting Lua packages
> installed because I'm not up to speed on luarocks yet.  I'm a little
> hesitant to download packages outside the luarocks mechanism because  
> I'm
> painfully aware that grabbing a tar.gz file and running make will
> sometimes clobber library versions that are used by programs obtained
> via apt-get, (that is make a mess that is difficult to clean up).
>
> My immediate interest is using Lua to access graphics primitives  
> such as
> draw-line, draw-circle, draw-arc, etc.  I see there are bindings to  
> SDL,
> opengl, wx, tk and others.  While I need some gui widgets, mostly I  
> need
> widgets that represent analog meters, and trend graphs, (plots). I  
> have
> C code from the 1980's that ran on DOS with a primitive vgalib so
> primitive is fine for what I need.
>
> Can anyone offer opinions of which graphics library would be best
> suited?
>
> The graphics rendering program will run on a Linux machine, but I want
> to connect it via a TCP socket to a very small microcomputer that  
> tells
> the rendering program what to draw using ASCII strings, or better yet,
> by passing a Lua table to the rendering program.
>
> Thanks in advance for any words of wisdom.
>
>
> David Smead
> www.amplepower.com
>

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

steve donovan
In reply to this post by Dave Smead
On Mon, May 4, 2009 at 7:15 AM, Dave Smead <[hidden email]> wrote:
> My immediate interest is using Lua to access graphics primitives such as
> draw-line, draw-circle, draw-arc, etc

wxLua is probably a good fit.  A simple GUI program with graphics
primitives is really straightforward, very portable. (This was tested
using wxLua bundled with Lua For Windows)

steve d.

------------------------------------------------------------------------------------------
-- draw.wlua (based on Minimal.wx.wlua from LfW)

-- Load the wxLua module, does nothing if running from wxLua,
wxLuaFreeze, or wxLuaEdit
require("wx")

frame = nil

-- paint event handler for the frame that's called by wxEVT_PAINT
function OnPaint(event)
    -- must always create a wxPaintDC in a wxEVT_PAINT handler
    local dc = wx.wxPaintDC(panel)
    -- call some drawing functions
    dc:DrawRectangle(10, 10, 300, 300);
    dc:DrawRoundedRectangle(20, 20, 280, 280, 20);
    dc:DrawEllipse(30, 30, 260, 260);
    dc:DrawText("A test string", 50, 150);
    -- the paint DC will be automatically destroyed by the garbage collector,
    -- however on Windows 9x/Me this may be too late (DC's are
precious resource)
    -- so delete it here
    dc:delete() -- ALWAYS delete() any wxDCs created when done
end

frame = wx.wxFrame( wx.NULL,            -- no parent for toplevel windows
                    wx.wxID_ANY,          -- don't need a wxWindow ID
                    "wxLua Draw Demo", -- caption on the frame
                    wx.wxDefaultPosition, -- let system place the frame
                    wx.wxSize(450, 450),  -- set the size of the frame
                    wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles

panel = wx.wxPanel(frame, wx.wxID_ANY)

-- connect the paint event handler function with the paint event
panel:Connect(wx.wxEVT_PAINT, OnPaint)

frame:Show(true)

wx.wxGetApp():MainLoop()

---------------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

matias.guijarro
In reply to this post by Dave Smead
Hello,

My advice would be to use the FLTK toolkit :
http://www.fltk.org

It is very efficient, lightweight, and
it offers widgets like analog meters etc.
There is a nice 1D plotting library (only
1 small cpp file...) on top of FLTK, called
Cartesian :

http://rfltk.svn.sourceforge.net/viewvc/rfltk/cartesian/

It is very easy to add file descriptors watching
(select) within the GUI main loop. It helps
a lot for sockets. Of course, other toolkits
probably offers the same kind of features.

As far as I know there are some Lua bindings
for FLTK. However, it might be more efficient
to write the GUI code in C++, and to exchange
data using the Lua C API if you don't really
need GUI objects to be exported on the Lua
side (do you see what I mean ?).

My 2 cents,
cheers,
Matias.


Quoting Dave Smead <[hidden email]>:

> Greetings,
>
> I'm a Lua newbie, but a programmer of many years using C and Python.
> I've used Linux exclusively since 1994, Debian most of that time and
> presently using Ubuntu 8.10.
>
> At the moment I'm still having some difficulties getting Lua packages
> installed because I'm not up to speed on luarocks yet.  I'm a little
> hesitant to download packages outside the luarocks mechanism because I'm
> painfully aware that grabbing a tar.gz file and running make will
> sometimes clobber library versions that are used by programs obtained
> via apt-get, (that is make a mess that is difficult to clean up).
>
> My immediate interest is using Lua to access graphics primitives such as
> draw-line, draw-circle, draw-arc, etc.  I see there are bindings to SDL,
> opengl, wx, tk and others.  While I need some gui widgets, mostly I need
> widgets that represent analog meters, and trend graphs, (plots). I have
> C code from the 1980's that ran on DOS with a primitive vgalib so
> primitive is fine for what I need.
>
> Can anyone offer opinions of which graphics library would be best
> suited?
>
> The graphics rendering program will run on a Linux machine, but I want
> to connect it via a TCP socket to a very small microcomputer that tells
> the rendering program what to draw using ASCII strings, or better yet,
> by passing a Lua table to the rendering program.
>
> Thanks in advance for any words of wisdom.
>
>
> David Smead
> www.amplepower.com
>
>


Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Philippe Lhoste
In reply to this post by Dave Smead
On 04/05/2009 07:15, Dave Smead wrote:
> My immediate interest is using Lua to access graphics primitives such as
> draw-line, draw-circle, draw-arc, etc.  I see there are bindings to SDL,
> opengl, wx, tk and others.  [...]  so
> primitive is fine for what I need.
>
> Can anyone offer opinions of which graphics library would be best
> suited?

I think I would have used LuaCairo[1], as Asko said, it works well.
I also used Lua-GD[2] in the past.
You also have CD (Canvas Draw)[3] which can be see as an "official" graphics library for Lua.
Or even game libraries like LÖVE[4].
And some others, of course.
Indeed, the difficulty is to make a choice! :-)

[1] http://www.dogusan.net/dogusanh
[2] http://lua-gd.luaforge.net/
[3] http://www.tecgraf.puc-rio.br/cd
[4] http://love2d.org/

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Andreas Krinke
In reply to this post by Asko Kauppi
Asko Kauppi wrote:
>
> My preference for Lua & graphics is Cairo.  There are multiple bindings
> even for this (one for Lua's curses, I must say).

You might want to have a look at Scrupp [1]. The next version will
include the cairo binding by Geoff Richards [2] and LuaSocket by Diego
Nehab [3]. These new parts are currently in svn only and not documented,
yet.

In general, Scrupp is a cross-platform 2D engine which uses SDL and
OpenGL for visualization. The svn contains examples of how to use the
cairo binding to create images and how to display them using Scrupp. [4]
shows one of the examples.

Andreas

[1] http://scrupp.sf.net
[2] http://www.daizucms.org/lua/library/oocairo (domain seems to have
expired, but the documentation and source code is included in scrupp svn)
[3] http://www.tecgraf.puc-rio.br/~diego/professional/luasocket/
[4]
http://scrupp.svn.sourceforge.net/viewvc/scrupp/trunk/examples/cairo/simple-example.slua?revision=45

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

steve donovan
In reply to this post by Philippe Lhoste
On Mon, May 4, 2009 at 12:22 PM, Philippe Lhoste <[hidden email]> wrote:
> You also have CD (Canvas Draw)[3] which can be see as an "official" graphics
> library for Lua.

Unfortunately, the documentation makes the head sore.

A good place to start is the Lua examples provided here:

http://www.tecgraf.puc-rio.br/cd/download/samples_cdlua5.zip

which also use IUP.

steve d.
Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Wolfgang Oertl
Now that everyone suggested his/her favourite toolkit, here's another
option: LuaGnome [1] offers a complete Cairo binding as well as all
the other Gnome related libraries (Gtk, Gdk etc.).  Examples for Cairo
are included, too. Disclaimer - I'm the author and may be biased ;)

[1] http://luaforge.net/projects/lua-gtk (use the CVS snapshot)
Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Asko Kauppi
In reply to this post by Dave Smead

To respond to your original mail:

- "make" itself does not clobber files maintained by apt-get or  
others. Be restful, and try it. You will be unnecessarily limiting  
your choices if sticking to LuaRocks only (also, LR might not have the  
latest versions of all the modules)

- don't do "make install". Study the Makefile, and copy necessary  
files (.so and maybe some .lua) to the appropriate folders. You can  
even have them under your user account root, say ~/lua and make  
LUA_PATH and LUA_CPATH point there. The mechanism is easy and efficient.

Having re-read the mail, I realize the "microcomputer" isn't the one  
showing the graphics. Therefore, let me change my recommendation to  
IUP / LuaGnome (though I've used neither). Cairo alone does not have  
event handlers, which would be needed for interaction with the  
graphics. If it were output only, Cairo itself is more than enough.

Personally, I will be going the SVG + JavaScript road on such.

-asko


Dave Smead kirjoitti 4.5.2009 kello 8:15:

> Greetings,
>
> I'm a Lua newbie, but a programmer of many years using C and Python.
> I've used Linux exclusively since 1994, Debian most of that time and
> presently using Ubuntu 8.10.
>
> At the moment I'm still having some difficulties getting Lua packages
> installed because I'm not up to speed on luarocks yet.  I'm a little
> hesitant to download packages outside the luarocks mechanism because  
> I'm
> painfully aware that grabbing a tar.gz file and running make will
> sometimes clobber library versions that are used by programs obtained
> via apt-get, (that is make a mess that is difficult to clean up).
>
> My immediate interest is using Lua to access graphics primitives  
> such as
> draw-line, draw-circle, draw-arc, etc.  I see there are bindings to  
> SDL,
> opengl, wx, tk and others.  While I need some gui widgets, mostly I  
> need
> widgets that represent analog meters, and trend graphs, (plots). I  
> have
> C code from the 1980's that ran on DOS with a primitive vgalib so
> primitive is fine for what I need.
>
> Can anyone offer opinions of which graphics library would be best
> suited?
>
> The graphics rendering program will run on a Linux machine, but I want
> to connect it via a TCP socket to a very small microcomputer that  
> tells
> the rendering program what to draw using ASCII strings, or better yet,
> by passing a Lua table to the rendering program.
>
> Thanks in advance for any words of wisdom.
>
>
> David Smead
> www.amplepower.com
>

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Miles Bader-2
Asko Kauppi <[hidden email]> writes:
> Having re-read the mail, I realize the "microcomputer" isn't the one
> showing the graphics. Therefore, let me change my recommendation to  IUP
> / LuaGnome (though I've used neither). Cairo alone does not have  event
> handlers, which would be needed for interaction with the  graphics. If
> it were output only, Cairo itself is more than enough.

Presumably you meant lua-gtk?

("gnome" uses gtk, but is tons of extra unrelated junk on top of it; gtk
is all you need to make a fully functional app)

I can confirm that lua-gtk is an excellent and well-done package.  It's
very easy to use and works well.

[For documentation, I actually found myself using gtkmm docs, as the
lua-gtk interface seems pretty similar (basically it's a
straight-forward transformation of gtk into an object-oriented style,
e.g., eliminating redundant prefixes on names from the C interface.]

One caveat though -- when I was originally playing with lua-gtk (last
year), it was kind of tricky to build; I now use the debian lua-gtk
package, which of course makes it trivial.  I don't know if building it
from source is still hard or not...

-Miles

--
Arrest, v. Formally to detain one accused of unusualness.

Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Iñigo Serna
Hi there,

2009/5/5 Miles Bader <[hidden email]>:
> [...]
>
> One caveat though -- when I was originally playing with lua-gtk (last
> year), it was kind of tricky to build; I now use the debian lua-gtk
> package, which of course makes it trivial.  I don't know if building it
> from source is still hard or not...
>
> -Miles

There is also lgob [1], which is quite easy to build in linux and
looks as complete as lua-gtk.

Best regards,
Iñigo Serna

[1] http://oproj.tuxfamily.org/wiki/doku.php?id=projects
Reply | Threaded
Open this post in threaded view
|

Re: primitive graphics application

Wolfgang Oertl
In reply to this post by Miles Bader-2
Miles: I have renamed lua-gtk to LuaGnome to reflect that it not only
supports gtk, but all the other libraries related to Gnome. As each
library is supported by a separate module, and you only have to
install or load those which are needed for a certain application,
there is no bloat.

Iñigo: thanks for the link to lgob. I downloaded and compiled, which
worked mostly. No time now to look at it in detail or try examples,
but as far as I can tell, most functions should be there.

Wolfgang