Theo Verelst Mesa/OpenGL page

I've compiled the mesa lib under cygnus/Gnu C, and made an example containing a major part of the graphics functionality I'd need to make an interesting 3D viewer/manipulator, especially once I've got the sockets working in any decent manner... LATEST ADDITION: A server version of a Mesa program, integrating event loops, and making it possible to use remote controlled graphics applations, such as a combination of a Tcl/Tk graphical interface and a (3D) Mesa window. BTW: this also serves an example of how to use sockets under the cygnus/Gnu compiler on a windows95 machine !

The mesa library and related libs

I've got all but the last library (a high level one) working, allowing interesting examples (not all the flashy one's, though...) to be compiled and run.

Here is an archive with the major part of the libraries and include files that are needed, you should be able to use this to do your own graphics programming on anything that runs i386 code and a gnu-cygnus compatible compiler:, about a meg large.

I didn't (yet) test wether what's in this archive is actually enough to compile, but I think it is all there, at least the libs and include's are. Meanwhile, I've tested it and I can at least compile the Book/robot.c program using tmy supplied script: cm robot under cygnus 1.8 (not 1.9 ! Didn't try yet.).

Example: a robot arm

Nothing too flashy, but real time rendered, resizable, goureaud shaded, double buffered polygons, with smooth animation (at least on a 100 MHz Pentium) under keyboard control. It is not an example that is provided in this fashion with the distribution or from any other site, but of course contains parts of several examples. The idea is to have two blocks resemble two parts of a robot arm which can be rotated as a whole, and the parts can be rotated with respect to eachother. The main thing is that goureaud shading and double buffering are available in an interactive way. I've been working on the 'picking' mechanism, to trace back mouse clicks to parts of the 3D model. This facility is available under mesa, I just didn't finish all the 'mask' programming that goes with it yet, because I focussed on other things.

The program file can be start from a dos (or bash shell, if you like the unix feel) or windows, and needs the cygwin library (version 1.8 !) in the same directory, or somewhere in the 'windows' path. This version was done under version 1.8, I haven't tried it yet under 1.9, also because even with the path, it has the habit of hanging my (incredibly innovative) microsoft windows 'dos' shell (running bash) when it punishes me for only one illegal command. Can't work like that, but I guess 2.0 will solve the (bash) problem.

The lib is in a zip archive, not because it will be compressed a lot, but because standard up- and download on tripod doesn't recognize .dll as a binary file ...

You can have the source code to have a look at. It shouldn't be too hard to import general polygonal models for rendering.

Use the arrow keys and z and x keys to exploit the degrees of freedom of the 'robot-arm'. q quits the program. It even sees to survive (and adapt to) resolution changes.

Robot arm example: server version

I've finally gotten the sockets to work under the Cygnus environment (on windows, it a bit odd, but streams do more or less what they should do), and decided it would be interesting to do one of the things I'd planned long ago: a combination of a (command line) server with a graphics program under Mesa.

Mainly, I've added the code to wait for a connect on socket 6543 before the first window draw of the robot example, and of course the harder thing: included a 'select' based socket handler in the mesa main event loop. I've done it in a 'clean', but not necessarily the most fundamental way, by adding a poll in the tkIdleFunc, and making sure that as little time as possible is waisted. Basically, when Mesa is done updating windows, this function is called, and it keeps reading the opened socket stream until no more input is available. The read function only returns one line at a time, so it will wait for a newline to arrive first, and this is where windows sometimes seems to mess things up: a lot of lines in a row do not get read in sequence, because the fcnt funtion doesn't indicate all bytes that are already available for reading. Or I've done an incomplete job in the line handling (I've done this in one morning, so that is quite possible, too).

When a line is successfully read form the socket stream, it is interpreted as a command, currently only one command with one parameter is recognized: spine (value), which sets the spine rotation variable to the specified angle (in degrees), and redraws the robot arm.

I've used Pcom (see here ) to provide the client connection, basically the pcom input line can be used to transfer data to the mesa application, running in parallel, possibly on another machine. All lines are repeated on the standard output of the robot process, and only lines starting with 'spine' are interpreted and lead to a redraw.

All this works fine (except for the lagging behind of the socket read function when a lot of lines are buffered on the stream, see above), and I've made good use of the Tcl/Tk programming facilities to make a very simple graphical interface to rotate the robot arm by remote control. The tcl/tk code is as follows:

# read the command shell ++
source pcom.tcl
# connect using port 6543 and pressing the 'connect' button
toplevel .rr
button .rr.b -text "Spine +" -command \
   {global spine; incr spine 5; send "spine $spine" }
button .rr.b2 -text "Spine -" -command \
   {global spine; incr spine -5; send "spine $spine" }
pack .rr.b ; pack .rr.b2
entry .rr.e1 -textvar spine; pack .rr.e1
bind .rr.e1 &stReturn> {global spine; send "spine $spine"}
set spine 90
Try it yourself, the result is a rudimentary graphical interface to the robot arm Mesa application:

The source files and makefile for the robot application are contained in this zip archive , and the necessary libraries (for cygnus 1.8) are here .

Here is the executable example, and various graphics libraries: . Remember to use the cynwin.dll library either in your windows or local directory (with robots.exe).