SDL2 - Jim Tcl sdl extension update

Since the early days of Jim Tcl, the included sdl extension has provided an example of how to integrate an external library as a Jim Tcl extension.

However this extension had not been updated for some time, and did not support the newer SDL2 API.

Now the sdl extension has been updated to support both SDL and SDL2, and also includes some additional features.

Building the extension

configure uses pkg-config to find the required libraries, so be sure to have SDL2_gfx (and optionally SDL2_ttf) installed where pkg-config can find them.

$ pkg-config --modversion SDL2_gfx
1.0.2

Build the sdl extension as a module by specifying it at configure time.

$ ./configure --full --with-mod=sdl
...
Checking for SDL2_gfx ...1.0.2
Checking for SDL2_ttf ...2.0.15
Extension sdl...module
...
$ make
...
	CC	jim-sdl.o
	LDSO	sdl.so
...

Testing the extension

Some test scripts are available in the examples/ directory.

$ ./jimsh examples/sdltest.tcl

Jim-SDL sdltest

$ ./jimsh examples/sdlevents.tcl

Using the extension

Create a window (sdl screen) with the sdl.screen command

. package require sdl
1.0
. set s [sdl.screen 640 480 "Window Title"]
::sdl.surface4

The returned handle provides a number of subcommands. Help is available for each subcommand.

. $s -commands
free flip poll clear pixel circle aacircle fcircle rectangle box line aaline font text
. $s -help fcircle
Usage: ::sdl.surface4 fcircle x y radius red green blue ?alpha?
. $s fcircle 100 100 30 200 0 0
. $s flip

Colours in SDL use separate red, green and blue components. These are specified as integers from 0 to 255. Similarly, the alpha (opacity) is specified from 0 (transparent) to 255 (opaque).

The image commands are as follows:

  • clear - clear the entire window to the given colour
  • pixel - draw a single pixel
  • circle - draw a circle (outline)
  • aacircle - draw a circle (outline) with antialiasing
  • fcircle - draw a filled circle
  • rectangle - draw a rectangle (outline)
  • box - draw a filled rectangle
  • line - draw a line
  • aaline - draw a line with antialiasing

If the SDL2_ttf package is available, basic text support is also provided.

  • font - load a TrueType font from a file with the given point size
  • text - draw text with the currently loaded font

Some notes on text:

  • Only one font may be loaded at a time
  • The specified font may not support all unicode glyphs.
  • To display utf-8 text, Jim Tcl must have been built with –utf8

There are several non-drawing commands.

  • free - close the window and free the handle (the same as: rename $s "")
  • flip - update the window to match graphics changes, then clear the background buffer and poll for events
  • poll - update the window to match graphics changes, then poll for events

Note that the graphics window is double (or triple) buffered. This means that any graphics changes are not displayed until flip or poll is used. In general, you should display an entire frame and then call flip.

In order to keep the SDL window responsive, it is necessary to pump the SDL event loop. Both flip and poll can be used for this. Currently the only SDL event that is recognised is the SDL_QUIT event. When this event occurs, flip and poll return JIM_EXIT. By default, this will exit the interpreter.

A typical script that simply displays a single image will look like:

... draw the SDL image ...

$s poll { sleep 0.25 }

This will run the SDL event loop and then eval the given script. If SDL_QUIT is ever received, the script will exit.

See examples/sdlevents.tcl for an example of how to integrate the SDL event loop with the Jim Tcl event loop.

Steve Bennett (steveb@workware.net.au)

Comments >>>

Jim Tcl version 0.80

ANNOUNCE: Jim Tcl version 0.80

Jim Tcl 0.80 has been released and is available from:

https://github.com/msteveb/jimtcl

Find out all about Jim Tcl at http://jim.tcl.tk/

CHANGES SINCE VERSION 0.79

This release contains bug fixes plus a number of additional features. A summary is below. See git for the full changelog.

Thanks to everyone who contributed to this release.

Bugs fixed in version 0.80

  • return -level 0 -code xxx now returns the correct result
  • regexp - fix an issue with failed optional group
  • oo - fix an issue when no class variables are given
  • oo - fix super invocation with multiple inheritance levels
  • tailcall - fix to avoid growing the C stack frame
  • regsub -all with \A now works correctly
  • scan - fix an issue with chars vs bytes in utf-8 mode
  • aio - fix eventloop and eof for ssl connections
  • lsearch -regexp - fix the case where the pattern begins with a dash
  • lsearch -command - handle the case with too few args
  • Disallow renaming a local proc with upcall to avoid inconsistent behaviour

Features and improvements added in version 0.80

  • Dictionaries now preserve insertion order
  • string map and string compare now support embedded nulls
  • string match and other glob matches now support embedded nulls
  • Variable and proc names now support embedded nulls
  • Interactive mode now prints results containing embedded nulls
  • Generate a build warning if system is non-Y2038 compliant
  • package names added as an alias for package list
  • file rootname, file dirname are now more consistent with Tcl
  • aio - add Server Name Indication (SNI) ssl support
  • aio - add socket pty support
  • The 0d radix prefix is now supported for decimal (base 10)
  • String comparison operators lt, gt, le and ge are now supported
  • dict getwithdefault (and the alias dict getdef) are now supported
  • Build has coverage support, and test coverage is now over 90%
  • Performance improvements in a number of areas

Steve Bennett (steveb@workware.net.au)

Comments >>>

Move primary repo to github

ANNOUNCE: Jim Tcl is moving to github

As repo.or.cz has been down for some time, the mirror at github has now been designated as the primary repository.

https://github.com/msteveb/jimtcl

Steve Bennett (steveb@workware.net.au)

Comments >>>

Jim Tcl version 0.79

ANNOUNCE: Jim Tcl version 0.79

Jim Tcl 0.79 has been released and is available from:

https://github.com/msteveb/jimtcl

Find out all about Jim Tcl at http://jim.tcl.tk/

CHANGES SINCE VERSION 0.78

This release contains bug fixes plus a number of additional features. A summary is below. See git for the full changelog.

Thanks to everyone who contributed to this release.

Bugs fixed in version 0.79

  • aio - Fix closing stdin in bootstrap jimsh
  • clock scan - Unspecified fields use the current date/time
  • Fix linenoise assertion failure on Windows
  • file - Improved support for trailing slashes in pathnames
  • regexp, regsub - Various fixes in UTF-8 mode
  • $(...) syntax now properly returns non-error codes

Features added in version 0.78

  • file - Add mtimeus for microsecond resolution
  • file - Add missing split subcommand
  • lreplace - Implement TIP #505
  • aio - Add dgram unix socket support
  • aio - Add support for lock -wait
  • aio copyto - Significantly improve performance
  • aio tty - Allow setting echo
  • signal - Add block for blocking signals with SIG_IGN
  • Add built-in JSON support with the json extension
  • Improve performance when indexing UTF-8 strings

Other changes

  • Documentation updates to improve consistency, remove obsolete commands, add some missing commands
  • exec no longer forces SIGPIPE disposition to SIG_DFL
  • Update autosetup to v0.6.9 with optimised insert/delete

Steve Bennett (steveb@workware.net.au)

Comments >>>

Jim Tcl version 0.78

ANNOUNCE: Jim Tcl version 0.78

Jim Tcl 0.78 has been released and is available from:

http://repo.or.cz/w/jimtcl.git or https://github.com/msteveb/jimtcl

Find out all about Jim Tcl at http://jim.tcl.tk/

CHANGES SINCE VERSION 0.77

This release contains some bug fixes plus a number of additional features. A summary is below. See git for the full changelog.

Thanks to everyone who contributed to this release.

Bugs fixed in version 0.78

  • local - Fix crash when local command is deleted
  • history - When creating ~/.jim_history, set permissions to 0600 for security
  • exec - Fix windows exec with empty or unset env
  • exec - Fix check for | and |&
  • jim.c - Fix Object leak in zlib support
  • signal - Restore default signal handling on interp exit
  • dict - Fix [dict values] with duplicate values
  • Fix ‘/’ command, divide by zero
  • expr - Replace expression engine to fix a number of problems
  • zlib - Various fixes
  • lsort -unique - Fix case with no duplicates
  • aio tempname - Fix a crash when the template is invalid
  • Tcl compatibility - Error on extra characters after close brace
  • eventloop - Return from callback is not an error
  • oo - Fix methods for superclasses
  • Various refcount and edge case fixes found by fuzz testing

Features added in version 0.78

  • Add support for utf-8 wide characters
  • aio - Add tty for termios settings
  • aio - Add sockopt for broadcast, tcp_nodelay, etc.
  • utf-8 - Update UnicodeData.txt to 9.0.0
  • jimsh - Add support for jimsh -
  • jimsh - Scriptable command-line completion support via tcl::autocomplete
  • history - Add autocompletion support history completion <cmd>
  • Add support for -commands to many commands
  • Add pkg-config support - jimtcl.pc
  • clock - Add -gmt option to format and scan
  • tree - Allow nodes to be deleted
  • defer, $jim::defer - Allow scripts to run on proc exit
  • eventloop - Support sub-millisecond timer resolution
  • Support lambda even if references are disabled
  • Performance - Improve a number of common cases through caching
  • signal, exec, wait, pid, pipe - Many improvements
  • build - Support --silent-rules, and enable by default
  • regexp - Implement class shorthand escapes in brackets
  • linenoise (jimsh) - Add ^Z (SUSP) support
  • linenoise (jismh) - Update to support multiline mode

Other changes

  • signal - Remove the signal command from child interpreters
  • os.wait is now wait
  • aio ssl now upgrades the current channel rather than creating a new channel
  • Update autosetup to v0.6.8

Steve Bennett (steveb@workware.net.au)

Comments >>>

Jim Tcl version 0.77

ANNOUNCE: Jim Tcl version 0.77

Jim Tcl 0.77 has been released and is available from:

http://repo.or.cz/w/jimtcl.git or https://github.com/msteveb/jimtcl

Find out all about Jim Tcl at http://jim.tcl.tk/

CHANGES SINCE VERSION 0.76

This release contains some bug fixes plus a number of additional features. A summary is below. See git for the full changelog.

Thanks to everyone who contributed to this release.

Bugs fixed in version 0.77

  • exec - better handline of pipeline abnormal termination
  • exec - fix append redirection on Windows
  • regsub - fix substitution with trailing backslash
  • expr - improved mathfunc handling and pow/**
  • chained tailcalls were not always being run

Features added in version 0.77

  • Add support for configure --docdir=...
  • Add support for jimsh --help
  • Add support for booleans in string is and expressions (true, false, on, off, yes, no)
  • aio - add sync, openssl bindings, posix locking
  • expr - add support for atan2, hypot and fmod
  • regexp, regsub:
    • Add support for \D, \W and \S
    • Add partial support for \A, \Z
    • Add support for all character classes: [[::blank:]], [[::xdigit::]], etc.
  • Update included sqlite3 to v3.14.1
  • Add $tcl_platform(engine)
  • Add basic (optional) zlib support
  • Add interp child interprester support
  • oo:
    • Add support for constructor, runs on new object creation
    • Add support for unknown method
  • Add Travis and AppVeyor continuous integration support
  • Use pkg-config in configure to find packages if possibe

Steve Bennett (steveb@workware.net.au)

Comments >>>

See All News Articles »