bbTablet
A bare bones digitizing tablet interface
C++ API for Win32
by William Baxter

About |Usage |Install |History |Bugs |Download |Contact |


>> about <<
The bbTablet API is some code I put together to make writing C++ applications that use Wacom tablets on Win32 easier.  This is not industrial strength code, but it should be sufficient for a quick first-pass prototype, or research application.  The source code is available and is completely free so you can add to it as you find yourself needing more access to the underlying Wintab API.

bbTablet is quick and dirty, and easy to use.  You can go from no tablet support to support for basic pressure readings in next to no time.  It also has the unique feature of being able to give you a 3D rotation for the orientation of the brush for tablets where tilt is available (Intuos and Intuos II series of Wacom tablets only, I think).  This requires more effort than you might think.

The API translates most of the tablet's integer values into single-precision floating  point numbers in the range [0,1) (type float).  So you don't need to worry whether you've got a pen with 512 levels of pressure or 1024.  Zero is no pressure, 1.0 is full pressure.  Similar for positional values: bbTablet also reports those to you as [0,1) floats.
>> usage <<
Basically, to use bbTablet once you've installed it, you include the bbtablet header with "#include <bbtablet.h>" in your C++ program and call a few lines of code.

To use the tablet you should first initialize the bbTablet library with this bit of code:
    #include <bbtablet.h>
HWND wnd = << get the window's device somehow!* >>
bbTabletDevice &td = bbTabletDevice::getInstance( );
td.initTablet( wnd, bbTabletDevice::SYSTEM_POINTER );
The above code will make it so your system mouse is controlled by the tablet.  If you want to continue to use the mouse separately (e.g. for bi-manual input), pass in 'bbTabletDevice::SEPARATE_POINTER' instead.

Getting the HWND can be a non-trivial task if you're using a higher level toolkit that doesn't readily give you that sort of information, but there are ways.  For instance a call to GetForegroundWindow() at the right time often seems to do the trick.  If you're working with GLUT or OpenGL this little bit of code does the trick:
   #define WIN32_LEAN_AND_MEAN
#include <windows.h>
static void* getCurrentHWND()
{
// get current DC from wgl
return WindowFromDC(wglGetCurrentDC());
}
You just need to be sure your GLUT window's GL context is current when you call the above function.

Once initialized, you just have to periodically check for new tablet events in your code:
    bbTabletDevice &td = bbTabletDevice::getInstance();
bbTabletEvent evt;
if (!td.getNextEvent(evt));
return;

<< use evt >>
Where an evt has the following members:
    evt.x        // [0,1] x coord
evt.y // [0,1] y coord
evt.z // [0,1] z coord (usually not supported)
evt.pressure // [0,1] pressure value
 evt.angle // angle&axis give 3D rotation
evt.axis[3] //
evt.id // unique physical id if supported
evt.buttons // bitmask of pressed buttons
evt.type // cursor type

The angle and axis parameters define a 3D transformation for the stylus.  This uses the tilt information from the stylus whenever available.  Otherwise it just acts like the pen is standing straight up.

More information may also be available in the README.txt in the zips below.  There is also a test program or two in the distribution you can play with.  Project files are available for MSVC++ 6.0 only.
>> installation <<

bbTablet relies on Wintab32.dll for operation. If you have a tablet, then you should have a copy of Wintab32.dll that was installed by the tablet's driver installer.   If you don't have a tablet, that's ok too because bbtablet uses run-time linking to get at the stuff in Wintab32.dll, and if it can't find the DLL your program can still proceed, just without tablet input.  

In addition to Wintab32.dll, to actually compile anything the WINTAB SDK is also necessary.  It is included in the "Sample Code" zip file which is a free download at http://www.wacomeng.com/windows/index.html. The SDK contains the necessary headers for compiling a tablet-aware application: wintab.h, pktdef.h, and maybe one other. (Note, they keep moving the SDK around, so my aplologies if the link is broken. Last time I found by going to the main "Support" section on the Wacom website and then to the "Developer Support" subsection under that.)

Once you have WINTAB installed you just need to put bbtablet.lib and bbtablets.lib somewhere that your compiler can find it to link with.  When you #include "bbtablet.h", the lib will be automatically linked (thanks to the #pragma comment(lib, "...") in the bbtablet.h header).  If you don't want it to link automatically, define the preprocessor symbol BBTAB_NOAUTOLINK when you compile.
>> history <<
This is the version change history
Jan 7, 2009
Version 0.9.
Changed license to MIT license.
Feb 18, 2003
Version 0.81b.
Added API to query whether tablet was initialized properly.
Sept 15, 2002
Version 0.8b.
First web release.
>> bugs <<
Here's the current low-down on bugs, features, and enhancement ideas.

  • Add Linux support
  • Add a callback style interface option in addition to the current call-in/query style
  • Allow more interesting mappings of tablet area.  Currently always returns values in [0,1] range for x and y.  Might want to handle aspect ratios differently.
  • Allow more querying of tablet info, like physical size, aspect ratios, resolution etc. I think it's all available through wintab.
  • Better error handling and reporting.

>> download <<
The newest versions (Tested with MSVC++7, MSVC++8, and MSVC++9):

bbtablet-2009-01-07.zip Source + precompiled libs
bbtablet-src-2009-01-07.zip Source only

Older versions:


>> contact <<
The bare bones tablet library was developed by William Baxter, mostly while a PhD student at the University of North Carolina at Chapel Hill working on graphics and interactive techniques.   If you're interested, have a look at the other projects I've worked on.

If you find this software useful, or make any improvements, please let me know.  If you have patches you'd like to contribute by all means please send 'em in!

<EMAIL ADDRESS>
    You can contact me by by sending email to 'w' followed by my last name @gmail.com.  Replace 'my last name' with my actual last name of course.

Happy Wacom'ing!