Version 1 of Maze in openGL om windows navigation controlled by Tcl/Tk

Updated 2003-11-27 23:04:18

by Theo Verelst

After a long break, I got a maze application, sort of game, out of the dust. More than a few years ago, I did a robot arm () which was also an openGL window, as seperate program, controlled over a socket connection by a tcl program, which evidently has the major advantes of building scripts (..) to control the graphical scene. Also, the interactive nature of tcl lets you play along or experiment with the graphics and the pieces of program controlling them.

I picked a maze application this time, and found out as I started it is programmed with typical windows stuff (messages, window handling) in it. It's an older example I picked up on the web somewhere long ago, and it compiled fine under cygwin years ago. Maybe I'll make another glut based or so program later, which compiles on linux and others, too.

The tcl script is very simple, but it works, though it needs adapting parameter ranges, and is just basic. I just finished it, and the principle works, which is fun and interesting.

http://195.241.128.75/Wiki/maze1.jpg

The program is made by compiling these two source files:

 [http://195.241.128.75/Wiki/maze.c] maze.c
 [http://195.241.128.75/Wiki/serv2.c] serv2.c

by under a recent (or older, probably) cygwin:

 gcc -O -DWIN32 -D__WIN32__ -D_WINDOW -o maze.exe serv2.c maze.c -lglut32 -lglaux -lglu32 -luser32 -lgdi32 -lopengl32  -lm -lwinmm

The tcl script is:

 scale .ma.sh
 scale .ma.sv
 button .ma.bc -text connect -command {set mas [socket localhost 4100]}
 pack .ma.sv -expand y -fill both
 pack .ma.sh -expand y -fill both
 pack .ma.bc
 .ma.sh set 50
 .ma.sv set 50
 bind .ma.sv <ButtonRelease-1> mazp
 bind .ma.sh <ButtonRelease-1> mazp
 proc mazp {} {
    global mas; 
    puts $mas "[expr ([.ma.sv get] - 50.0)/1000.0] [expr ([.ma.sh get] - 50.0)/1000.0]";
    flush $mas
 }

The one slider controls the speed, the other, which should be scaled, the turning, which become active when the sliders are released, that is when the changes are sent over the connections.

First start the maze.exe program, make sure the cygwin1.dll and glut32.dll can libraries can be found, when necessary copy them from /cygwin/bin to the current directory.

Then connect the tcl script by pressing the button Connect, and after the initial maze 'flight' you have control by topping the maze window with the normal arrow keys, or by the tcl program, using the sliders!

You'll have to make a .bmp file (gimp can write them) of 512x512 pixels to enable the texture feature of the opengl program.

Quality and load, and contraints on the tcl script program depend on the graphics hardware and computer speed, on a recent 2+G pentium with accelerated graphics, high speeds are completely smooth, and load remains low. The tcl program can also receive data (for instance from the keys being pressed) over the do_read() function.

I didn't test the channels overload characteristics, the robot arm application had major trouble with that, maybe because of cygwin, maybe because of opengl (which I compiled myself after lots of hacking at the time) in combination with sockets.