RenderingPipeline

from geometry to pixels

Adding analog inputs to your graphics app

When prototyping graphics applications it doesn’t take long until you want to control some parameters during runtime. Using the keyboard is often the first candidate as getting keystrokes is very easy for most toolkits used in graphics like GLFW or GLUT.

But it doesn’t take long until the number of keys it so large that it becomes confusing. There is also no direct feedback of the currently set values (and a lot of printf doesn’t scale so good as well). So the next step is adding a simple UI. Some use QT for this as it’s a nice GUI toolkit and works cross platform (so did I for many projects). QT is great when your prototype turns into a full application (unless you are building a game) but may require too much glue code for simple prototypes.

More limited but also much simpler to include into existing projects and very simple to set up for simple tasks is AntTweakBar. After writing a couple of lines of glue code, exposing one more variable for testing is a matter of one line of code!

In case you want some haptic feedback or adding a UI is not an option (maybe you don’t want to occlude anything from your game and need the keyboard and mouse for the game control), adding a MIDI device might be an option. rtMidi is a small cross platform library that helps getting the MIDI commands from your device. A simple MIDI controller with nine analog sliders and knobs will set you back 50€. Each control will give you a 7bit value of the current position.

One downside of this setup is the fact that the device only sends the values of the controls when they change, this means that the initial state when starting your app is not reported. So you might want to reset all physical sliders or move each one slightly after your application started to send the current control value to your app.

The video below shows how a small MIDI board is used to adjust the lighting parameters of our beloved Stanford bunny:

zv7qrnb

, ,

2 thoughts on “Adding analog inputs to your graphics app
  • dark_sylinc says:

    Great post! I’ve been thinking of doing the same in my engine. Sliders are not the only useful MIDI stuff you can use

    * Mid range MIDI keyboards are able to measure the “velocity” in which you hit the key (i.e. if you hit it faster it’s like hitting it “stronger”, a cheap replacement for after touch feature) which can be great for mapping the spawning of particle & sound effects to keys.
    Just play the animation & press the key to record the particle to spawn. Want more particles? hit the key stronger. Want a subtle effect? Hit the key lighter.
    Recording a slider changes throughout time is also possible.

    * Indeed MIDI calibration is a PITA since there is no way to know current state. However higher end MIDI devices have motors to change the sliders & knobs to the desired position.

    • Robert says:

      Some mid-range keyboards have some knobs and keys, so you can use what fits best. I also played around with a full MIDI keyboard but the tiny controller are much more handy in my use-cases but thanks for pointing out the possibility of recording analog events with MIDI as well.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*