Graphics... why so shrouded in mystery?

I’ve been working with ruby for quite a while now, and I still don’t
know how to manipulate graphics. I know about libraries like RMagick,
but how do they do it? What are the rudimentary methods used to, say,
display an image or pixel to the screen? Do I have to use C or Java just
to accomplish this? Do I need to use some .dlls?

Why can’t I find any information on this subject. Isn’t image
manipulation essential now-a-days?

Sorry for ranting, but I just get so frustrated when I can’t find any
leads on such a common and important subject. I’ll take any help that
can be provided.

~Ruby Panda

Hi

Weston C. wrote:

I’ve been working with ruby for quite a while now, and I still don’t
know how to manipulate graphics. I know about libraries like RMagick,
but how do they do it?

Libraries like RMagick are intended for manipulating images in files
(for example, resizing or rotating them) without actually displaying
them on screen.

What are the rudimentary methods used to, say,
display an image or pixel to the screen?

For that you will need a GUI toolkit which knows how to display images
and pixels within a desktop environment like Windows or OS X.

There are several GUI toolkits available for Ruby. They all have
strengths and weaknesses but any should be able to draw an image on
screen.

As an example, wxRuby is easy to install (gem install wxruby) and
handles a wide variety of image formats (JPG/PNG/TIF/BMP etc). It has a
demonstration of painting images on screen in samples/images/images.rb.
It can also use Device Contexts to draw primitives like lines and
circles, as well as images and text, onto screen or to a printer. See
samples/printing/printing.rb

I would expect most of the other major toolkits have similar examples of
how to achieve this with that API.

Do I have to use C or Java just
to accomplish this?

No, thank goodness.

hth
alex

To display graphics… you first need a window !

If you want to display pixels, lines, use ruby-opengl, your code will
execute everywhere.

If you need controls, you need some platform specific library or
something like Ruby/Tk.

require ‘tk’
root = TkRoot.new() { title “Hello, world!” }
Tk.mainloop()

Gaspard

2007/9/11, Weston C. [email protected]:

Weston C. wrote:

I’ve been working with ruby for quite a while now, and I still don’t
know how to manipulate graphics. I know about libraries like RMagick,
but how do they do it? What are the rudimentary methods used to, say,
display an image or pixel to the screen? Do I have to use C or Java just
to accomplish this? Do I need to use some .dlls?

Why can’t I find any information on this subject. Isn’t image
manipulation essential now-a-days?

Because Ruby is not fronted by a mega-corporation running any checklist
of
“must have” goodies. Put another way, there is no single graphics
library
that will receive the blessing of Ruby’s “vendor lockin” system.

Next, each graphics library comes with its own mix of trade-offs and
compromises. Some work great - with one specific hardware. Some are
freakishly hard to install. Some are slow at interaction but provide
camera-ready technical charts. Ruby - more wisely than a corporate
offering - declines to pick only one of those and cram them down your
throat.

Sorry for ranting, but I just get so frustrated when I can’t find any
leads on such a common and important subject. I’ll take any help that
can be provided.

That’s because open source software is no fun to document, and because
most
such documentation simply defers to each graphic library’s home
implementation - OpenGL, GraphViz, DirectX, etc. None of those were
written
in Ruby, because they need good performance!

Or if you are looking for a drag-and-drop visual environment for GUI
design, you could look at WideStudio - it’s a full environment for
exactly that (and is not restricted to Ruby - works with C/C++/Java,
etc.)

The window there will give you a canvas that should let you draw
whatever you want.

Cheers,
Mohit.
9/12/2007 | 12:58 PM.

Mohit S. wrote:

Or if you are looking for a drag-and-drop visual environment for GUI
design, you could look at WideStudio - it’s a full environment for
exactly that (and is not restricted to Ruby - works with C/C++/Java,
etc.)

The window there will give you a canvas that should let you draw
whatever you want.

Cheers,
Mohit.
9/12/2007 | 12:58 PM.

Actually, I want to know how the people who made these graphics
libraries and GUIs made them in the first place. How are these libraries
and toolkits working with graphics? How do they do it?

I need to know how to make my own custom libraries and toolkits, mainly
because I get so frustrated using something that I don’t really
understand. Or, more likely, the library or tk doesn’t have what I need
or implements something in a way I don’t agree with.

So, I’m basically asking how to make my own graphics libraries and GUI
toolkits, I want to know where my tech-organic graphics are being grown,
and how. Thanks for any enlightenment in advance.

~Ruby Panda

On 9/12/07, Weston C. [email protected] wrote:

So, I’m basically asking how to make my own graphics libraries and GUI
toolkits, I want to know where my tech-organic graphics are being grown,
and how. Thanks for any enlightenment in advance.

Just download the source code and read it. If you can understand it
proceed with your project. Otherwise find something else to do.

Bob

From: “Weston C.” [email protected]

Actually, I want to know how the people who made these graphics
libraries and GUIs made them in the first place. How are these libraries
and toolkits working with graphics? How do they do it?

Ultimately such libraries tend to call window manager and graphics
routines
on the native platform. These operating system calls are totally
different on
Windows, Mac OS X, Linux, etc…

On Windows, one tends to use the CreateWindowEx() function to
create the window, which is documented here:
http://msdn2.microsoft.com/en-us/library/ms632680.aspx

There are numerous examples on the web for creating windows and
drawing graphics into them.

I need to know how to make my own custom libraries and toolkits, mainly
because I get so frustrated using something that I don’t really
understand. Or, more likely, the library or tk doesn’t have what I need
or implements something in a way I don’t agree with.

If you want to do it yourself, you’ll need to learn at least the
following:

  • How to write the code for your platform (usually in C or C++) to
    create windows and draw graphics. (There will be plenty of examples
    on the web for this.)

  • How to wrap your C or C++ code so that it may be called from ruby.

Another possibility would be to start with an already-existing but
simple
library which already has ruby bindings, and learn to use it. Then when
you find something it can’t do, or something you would prefer to do
differently, study its code and tweak it to suit your needs, add
features,
etc.

So, I’m basically asking how to make my own graphics libraries and GUI
toolkits, I want to know where my tech-organic graphics are being grown,
and how. Thanks for any enlightenment in advance.

Also - as Phlip mentioned: It depends on the kind of graphics you want
to render. If you’re interested in fast, efficient, high-framerate
graphics
suitable for real-time video game rendering, you’ll take one path. If
you
are interested in slower high-resolution anti-aliased print-quality
rendering,
you’ll probably take a different path. If you want to render
native-looking
buttons and widgets, and draw some simple static or animated icons next
to them, you might take a third path.

I would never try to discourage you from learning more about the native
window manager and graphics API calls on your platform. But at the
same time I would recommend at least playing with a few various
toolkits… Whether WxRuby, FXRuby, Tk, … or even some more game-
oriented ones like Gosu or rubygame, if you want to cut right to the
graphics part.

http://wxruby.rubyforge.org/
http://www.fxruby.org/
http://code.google.com/p/gosu/
http://rubygame.sourceforge.net/

Hope this helps,

Bill

Alex F. wrote:

By comparison, wxWidgets source package is c20MB and makes extensive use
of macros which can make the fundamentals hard to pick out. GTK+ is a
similar size. QT is the real heavyweight - the source install package is a
whopping 175MB.

Another “mystery” here is whether the OP wants GUI graphics (windows,
buttons, etc.), or CGI graphics (shaders, animation, etc.).

Weston C. wrote:

Actually, I want to know how the people who made these graphics
libraries and GUIs made them in the first place. How are these libraries
and toolkits working with graphics? How do they do it?

In that case you might find shoes [1] a worthwhile study. It uses the
native window creation routines on each platform, and then wraps the
Cairo library to provide a cross-platform drawing canvas within those
windows. Cairo (and its ruby wrapper) itself might be a next step.

One advantages is the brevity and clarity of the source - only a few
thousand lines of C. It’s focussed on drawing, rather than accessing all
the different platform routines for interacting with GUI objects.

By comparison, wxWidgets source package is c20MB and makes extensive use
of macros which can make the fundamentals hard to pick out. GTK+ is a
similar size. QT is the real heavyweight - the source install package is
a whopping 175MB.

hth
alex

[1] http://code.whytheluckystiff.net/shoes

Phlip wrote:

Another “mystery” here is whether the OP wants GUI graphics (windows,
buttons, etc.), or CGI graphics (shaders, animation, etc.).
Or images such as JPEGs and GIFs, especially since OP mentioned RMagick.
Weston, can you clarify what you mean by “graphics”?

Weston C. wrote:

Actually, I want to know how the people who made these graphics
libraries and GUIs made them in the first place. How are these libraries
and toolkits working with graphics? How do they do it?

http://www.amazon.com/Computer-Graphics-Principles-Practice-2nd/dp/0201848406

Also any book by Jim Blinn

If you want to draw GUI stuff, and have control over it, you will
find this is where code can get really complex. Every platform
handles things in its own way. Your first choice is between a
particular platform or cross platform. Cross platform may be the most
useful way to go first. With that, check out the Wx, Tk or Qt code,
all are open source and cross platform. Qt is not free for all uses
though. (but arguably the best looking) Ruby has bindings to all 3.
All 3 do things in their own way to some degree.
Most of the bindings don’t look much different from the C or C++
native to the libraries.

If you want to do CGI like drawing 2D or 3D graphics, again, you need
to make a decision. You can go with Microsoft’s stuff, or you can go
with OpenGL. SDL is also a popular and easy to use library with
bindings in many languages.

Regardless, you might be best off using C or C++ for this stuff if
you want deep control and customization. One approach is to look at
the code of a functioning open source project and see how they do it,
tweak it and see if you can learn what you want to do. I recommend
checking out VLC (video lan client) it’s a nice cross platform video
player that has native GUI for each platform. The code is well
maintained and should give you some insights.

You can also consider using game creation libraries and tools.
They’re intended for games, but may as well be used for creating
original GUI’s ! Ruby has Gosu and Rubygame and ruby/sdl. But you
could even probably use Torque game engine or some other.
A graphical game is just an application after all!

On 9/12/07, Weston C. [email protected] wrote:

So, I’m basically asking how to make my own graphics libraries and GUI
toolkits, I want to know where my tech-organic graphics are being grown,
and how. Thanks for any enlightenment in advance.

~Ruby Panda

If you really want to start with the barest of bare bones, no OS
window managers, no system calls, nothing, you could look at
http://www.colorforth.com/ . But it’s kind of out there and
experimental.

-A

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs