<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>20papercups :: Michael Marner&#039;s Website &#187; Linux</title>
	<atom:link href="http://www.20papercups.net/tag/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.20papercups.net</link>
	<description>The (awesome) website of Michael Marner</description>
	<lastBuildDate>Tue, 15 Nov 2011 01:09:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How OpenNI Nearly Spoiled The Show</title>
		<link>http://www.20papercups.net/programming/how-openni-nearly-spoiled-the-show/</link>
		<comments>http://www.20papercups.net/programming/how-openni-nearly-spoiled-the-show/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 10:37:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Border Project]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[Half Real]]></category>
		<category><![CDATA[kinect]]></category>
		<category><![CDATA[OpenNI]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=420</guid>
		<description><![CDATA[So, for the last few months I&#8217;ve taken a break from the PhD to do some work for a theatre show for The Border Project, Half Real. There&#8217;s a lot of technology in the show. In particular, most of the set is projected, and we are using a Microsoft Kinect to track the actors on [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.20papercups.net/wp-content/uploads/2011/09/halfreal-1.jpg"><img class="alignleft size-thumbnail wp-image-424" title="Half Real" src="http://www.20papercups.net/wp-content/uploads/2011/09/halfreal-1-150x150.jpg" alt="Half Real" width="150" height="150" /></a>So, for the last few months I&#8217;ve taken a break from the PhD to do some work for a theatre show for <a title="The Border Project" href="http://www.theborderproject.com" target="_blank">The Border Project</a>, <a title="Half Real" href="http://www.theborderproject.com/project-half-real.html" target="_blank">Half Real</a>.</p>
<p>There&#8217;s a lot of technology in the show. In particular, most of the set is projected, and we are using a Microsoft Kinect to track the actors on stage, and modifying the projections based on their location.</p>
<p>I&#8217;m working on Linux, and using <a title="OpenNI" href="http://www.openni.org/" target="_blank">OpenNI</a> for interfacing with the Kinect. Things <em>almost</em> worked perfectly. In this post I will document the trials and tribulations of getting the Kinect to work for Half Real.</p>
<p><span id="more-420"></span>I often fall into <a title="Not Invented Here Syndrome" href="http://en.wikipedia.org/wiki/Not_Invented_Here" target="_blank">Not Invented Here Syndrome</a>, and so slowly I&#8217;m trying to get out of it. Obviously, interfacing with hardware like the Kinect is not something I really wanted to do during a 3 month theatre development. My Spatial Augmented Reality framework is built on Linux, so I basically had the option of <a href="http://openkinect.org/wiki/Main_Page" target="_blank">Libfreenect</a> or <a href="http://www.openni.org/" target="_blank">OpenNI</a>. OpenNI appears to be more mature, and so that&#8217;s what I went with.</p>
<p><iframe src="http://www.youtube.com/embed/4nowWxi75jE" frameborder="0" width="640" height="360"></iframe></p>
<p>As you can see, I&#8217;m only really tracking the position of the actors &#8211; we aren&#8217;t using any of the gesture recognition stuff.</p>
<p>During development everything looked peachy. However, during production week when we started running through the whole show, a <em>major</em> issue popped up. It turns out there is a bug buried deep in OpenNI that eventually rears its ugly head if you have a few people running around at the same time:</p>
<pre>Program received signal SIGSEGV, Segmentation fault.
 0x00007ffff215574d in Segmentation::checkOcclusion(int, int, int, int)</pre>
<p>This is a big problem. See, this is a theatre show, where the entire set is projected. If the system crashes, the stage goes black. The operator has to restart and bring the projections up to the right point in the show. It turned out that in our tech previews, the software was crashing 2-3 times per show. This was simply unacceptable.</p>
<p>Thankfully, I was only interested in the positions of the actors. This meant I could run the tracking in a completely different process and send the data to the projection system without too much overhead. So, on the day before I finished working for the project, I had to completely rewrite how the tracking worked.</p>
<h3>The Data We Need</h3>
<p>As I said, we only need position. I didn&#8217;t have to send through any camera images, gesture information, etc. All I needed was:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">struct</span> KinectMessage
<span style="color: #008000;">&#123;</span>
    <span style="color: #0000ff;">uint8_t</span> actor_id<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">float</span>   quality<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">float</span>   x<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">float</span>   y<span style="color: #008080;">;</span>
    <span style="color: #0000ff;">float</span>   z<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The process that interfaces with the Kinect simply sent these messages over a TCP connection to the projection system for every actor on stage. TCP worked pretty well. Both processes run on the same system, and the Kinect only updates at 30fps anyway. So you know, there&#8217;s only 510 bytes per second, per actor that needed to be transferred. If I was transferring images, a better <a href="http://en.wikipedia.org/wiki/Inter-process_communication" target="_blank">IPC</a> technique would be required.</p>
<h3>While True</h3>
<p>At this point, the hard work was done. Simply wrap the tracking process in a shell script that loops forever, rerunning the process when the segfault occurs. The projectors never go to black, and the worst case is the tracking lags for a a couple of seconds. Not perfect, but infinitely better.</p>
<p>I guess the moral of this post is to be wary of relying on 3rd party libraries that are not particularly mature. And if you have to (you don&#8217;t have much choice if you want to talk to the Kinect), wrap it up so it can&#8217;t screw you over. TCP worked for me, because I didn&#8217;t need to transfer much data. Even if you were doing the skeleton tracking and gestures, there isn&#8217;t a lot of data to send. If you need the images from the camera, TCP <em>may</em> not be for you. But there are plenty of other IPC techniques that could handle that amount of data (even pipes would do it). I guess the good news is OpenNI is Open Source, so in theory someone can get around to fixing it.</p>
<p>Hope this helps someone.</p>
<p>Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/programming/how-openni-nearly-spoiled-the-show/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What I think of Ubuntu 10.4</title>
		<link>http://www.20papercups.net/linux/what-i-think-of-ubuntu-10-4/</link>
		<comments>http://www.20papercups.net/linux/what-i-think-of-ubuntu-10-4/#comments</comments>
		<pubDate>Mon, 24 May 2010 13:24:07 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=327</guid>
		<description><![CDATA[I&#8217;ve been using Ubuntu since the 6.06 beta. It is my main operating system on my desktop at home, computer in the lab, and my laptop. Normally, I do distribution upgrades. This shields me from a lot of the changes happening around me; the user experience doesn&#8217;t change that much when I&#8217;ve already got everything [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.20papercups.net/wp-content/uploads/2010/05/Ubuntu-logo.gif"><img class="alignleft size-thumbnail wp-image-328" title="Ubuntu-logo" src="http://www.20papercups.net/wp-content/uploads/2010/05/Ubuntu-logo-150x150.gif" alt="" width="124" height="124" /></a>I&#8217;ve been using Ubuntu since the 6.06 beta. It is my main operating system on my desktop at home, computer in the lab, and my laptop. Normally, I do distribution upgrades. This shields me from a lot of the changes happening around me; the user experience doesn&#8217;t change that much when I&#8217;ve already got everything setup how I want. However, I just had to do a fresh install on my desktop. While my home directory is backed up, I am currently looking at a default user desktop. So, what do I think?<span id="more-327"></span></p>
<p>To be honest, I am not all that impressed with 10.4. Why you ask?</p>
<h3>Font rendering in Firefox is broken</h3>
<p>The first thing I notice with fresh Linux distribution is both the choice of default fonts, and the default font rendering. This is no problem, Gnome&#8217;s appearance dialog lets me easily configure anti-aliasing and sub-pixel smoothing how I want. There&#8217;s just one problem: Firefox completely ignores these settings!</p>
<p>To be more specific, it ignores the font smoothing settings and does it&#8217;s own, dog ugly version. There is a bug report for this <a href="https://bugs.launchpad.net/ubuntu/+source/firefox/+bug/559149">here</a>. By the looks of things, there is a workaround, but I haven&#8217;t tried that yet. The workaround involves removing config files in /etc, and running a console command to reconfigure fontconfig.</p>
<p>This is a ridiculous oversight when Firefox is one of the flagship applications shipping with Ubuntu.</p>
<h3>Update Manager thinks it&#8217;s the most important app on the system</h3>
<p>This technically was introduced in an earlier version, I&#8217;m just surprised they haven&#8217;t changed the default behaviour by now. See, Update Manager pops up it&#8217;s main window if it finds updates it thinks you should install, on top of whatever you happen to be doing. This is both intrusive, and annoying. I don&#8217;t have any data, but I&#8217;m willing to bet users are more likely to dismiss the dialog instead of installing updates when it gets in their way.</p>
<p>This is a similar problem with Windows deciding it needs to reboot after an update, nomatter what you think to the contrary. I understand the Ubuntu devs are worried that the bright red icon in the notification area isn&#8217;t enough to get people to click. However, putting it in their face is even worse, as Windows has shown with the Cancel/Allow UAC dialogs. People don&#8217;t read dialogs! A much better solution would be to put the lovely new notification system to use. Just a subtle notification message every 10 minutes or whatever would be much more affective, without getting in everyone&#8217;s way.</p>
<h3>Nautilus&#8217;s Address Bar is missing!</h3>
<p>What the hell!? Stop with this Apple induced breadcrumb navigation nonsense. I want to type a path into an address bar. In previous versions of Ubuntu, there was a button to toggle between breadcrumbs and textual address bar. In 10.4, that button is gone. The only solution is to enter the following into a console:</p>
<pre>
<pre><code>gconftool-2 --type=Boolean --set /apps/nautilus/preferences/always_use_location_entry true</code></pre>
</pre>
<p>Of course, you need to enter a similar command to get back to breadcrumbs. Here&#8217;s what I really don&#8217;t understand: Ubuntu is a distribution that specifically tries to remove the need to go to the command prompt. By removing a single toggle button, they have removed the ability to enter paths directly, something that most of the people migrating to Ubuntu (Windows users) have always been able to do. Just put the button back.</p>
<h3>My iPod doesn&#8217;t show up in Banshee</h3>
<p>Arg! I&#8217;ve been having this problem intermittently for a while. I also admit that Banshee isn&#8217;t a program installed by default. But I don&#8217;t like Rhythmbox, and would really like Banshee to work again.</p>
<h3>Window controls on the left</h3>
<p>I hate this on Macs, and I hate it here too. Please give an easy option in Appearance Properties to flip the location of the buttons. Luckily, New Wave, my theme of choice still has the controls on the right.</p>
<h3>The mish-mash 10.4 theme</h3>
<p>I <em>love</em> the look of Ubuntu in 9.10. The grey was a cool getaway from the orange. 10.4 kind of builds on this, and in other ways pulls it in another direction. Now there&#8217;s added purple!. The login screen is the ugliest Ubuntu login screen ever. The default Ubuntu theme seems to be a mashup of three different themes: The cool black stuff from 9.10, the new purple stuff, and the old orange Human theme. Pick one, and refine it please.</p>
<h3>Still need to open gconf-editor to get Computer, Home, Trash icons on desktop</h3>
<p>If you aren&#8217;t familiar with gconf-editor, it is basically regedit for all of Gnome&#8217;s settings. Apparently in Ubuntu 10.4, you still need to use this to get icons such as Computer, Home, and Trash to appear on the desktop. This is incredibly confusing to new people (I just happened to remember what keys needed to be set). In my opinion, opening gconf-editor is worse than using the console, something the Ubuntu UI guys are dead against.</p>
<p>While we&#8217;re on the topic, the way you change the massive icon size on the desktop is to edit the <em>Default Zoom Level</em> in Nautilus&#8217;s settings. This is also incredibly unintuitive.</p>
<h3>Is there anything good?</h3>
<p>I like getting new versions of all the programs I use every day. Again, Ubuntu 10.4 doesn&#8217;t disappoint here. Everything is nice and fresh. There&#8217;s nothing really surprising here.</p>
<h3>Conclusion</h3>
<p>This is my least favourite default Ubuntu install since 6.06. I feel some of these things are so obvious it&#8217;s almost strange mentioning them. I&#8217;ll again point out that Ubuntu is my OS of choice for <em>actually getting work done</em>. I have a Windows virtual machine for the sole purpose of running Office and Photoshop. I use Ubuntu every day, and really want to see it get better. I speak up, because I care. So with that, please keep the flaming to a minimum, and sorry about the rant.</p>
<p>Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/linux/what-i-think-of-ubuntu-10-4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shameless Plug: Martin&#8217;s Linux VTMs</title>
		<link>http://www.20papercups.net/linux/shameless-plug-linux-vtms/</link>
		<comments>http://www.20papercups.net/linux/shameless-plug-linux-vtms/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 00:24:38 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[video]]></category>
		<category><![CDATA[vtm]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=156</guid>
		<description><![CDATA[Hey everyone, hope you are enjoying the holidays! Anyway, today I thought I would distract everyone from my lack of videos by pointing you to some videos made by someone else. And so I present: Martin&#8217;s Linux VTM. These videos are aimed at the Linux beginner, but they very quickly get into great depth. I [...]]]></description>
			<content:encoded><![CDATA[<p>Hey everyone, hope you are enjoying the holidays!</p>
<p>Anyway, today I thought I would distract everyone from my lack of videos by pointing you to some videos made by someone else. And so I present: <strong><a href="http://www.hatchlane.com/blog/?p=8" target="_blank">Martin&#8217;s Linux VTM.</a></strong></p>
<p><strong><a href="http://www.hatchlane.com/blog/?p=8" target="_blank"></a></strong><span id="more-156"></span></p>
<p>These videos are aimed at the Linux beginner, but they very quickly get into great depth. I am still getting my head around some of the more advanced Bash scripting videos. There is actually two releases of videos, so here are the links:</p>
<p><a href="http://www.hatchlane.com/blog/?p=8" target="_blank">Release 1</a></p>
<p><a href="http://www.hatchlane.com/blog/?p=9" target="_blank">Release 2</a></p>
<p>Enjoy!</p>
<p>Michael</p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/linux/shameless-plug-linux-vtms/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OpenSceneGraph, Dual Screens &amp; TwinView</title>
		<link>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/</link>
		<comments>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 06:07:24 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[dual screen]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[openscenegraph]]></category>

		<guid isPermaLink="false">http://www.20papercups.net/?p=145</guid>
		<description><![CDATA[So some of my work at uni involves programming using OpenSceneGraph. Now, anybody who has used OSG before will know that as powerful as it may be, it is seriously lacking in the documentation department. So, this article describes how to do dual screen graphics on Linux using OpenSceneGraph. First we&#8217;ll look at the X [...]]]></description>
			<content:encoded><![CDATA[<p>So some of my work at uni involves programming using <a title="OpenSceneGraph Website" href="http://www.openscenegraph.org" target="_blank">OpenSceneGraph</a>. Now, anybody who has used OSG before will know that as powerful as it may be, it is seriously lacking in the documentation department. So, this article describes how to do dual screen graphics on Linux using OpenSceneGraph. First we&#8217;ll look at the X Screens approach, which is easier but probably not the best solution. Then we&#8217;ll look at a method that works with a single X screen.<span id="more-145"></span></p>
<h3>Multiple X Screens</h3>
<p>The easiest way to do dual screen output is if you have your X server configured so each output is its own X screen. The first thing you need to do is make sure you have enough screens. Finding this out is easy enough:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> getNumScreens<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">WindowingSystemInterface</span><span style="color: #000040;">*</span> wsi <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">getWindowingSystemInterface</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">ScreenIdentifier</span> si<span style="color: #008080;">;</span>
    si.<span style="color: #007788;">readDISPLAY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #0000ff;">return</span> wsi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getNumScreens<span style="color: #008000;">&#40;</span>si<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>You should do this before attempting to create your screens to make sure the X server is configured correctly. Otherwise OSG will throw an error when you try and create a graphics context for a screen that doesn&#8217;t exist. Setting up the viewers is fairly straight forward:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//Create main scene viewer</span>
&nbsp;
ref_ptr<span style="color: #000080;">&lt;</span>osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">CompositeViewer</span><span style="color: #000080;">&gt;</span> compositeViewer <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">CompositeViewer</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// create first view</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v0 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
v0<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setUpViewOnSingleScreen<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// add view to the composite viewer</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v0<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// do the same with the second view</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v1 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
v1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setUpViewOnSingleScreen<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>And thats it. You also need to set the scene data for each of your views and a couple of things I&#8217;ve missed, but that is the basic idea. The problem with this method is it creates 2 graphics contexts, which in most cases will cause a performance hit.</p>
<h3>Single X Screen, Single Context</h3>
<p>I looked into this method because I use TwinView on my Linux desktop boxes. Of course, TwinView means that there is only 1 XScreen that spans both monitors. Therefore, the getNumScreens function above will return 1. I have also set up our projector setup to use TwinView, so I don&#8217;t need to have one lot of code for testing on the desktop and then do something completely different when using the projectors. The other benefit of this approach is you only create one graphics context.</p>
<p>First thing we do is get the dimensions of the screen, which will be the combination of both screens.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// get the total resolution of the xscreen</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">WindowingSystemInterface</span><span style="color: #000040;">*</span> wsi <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">getWindowingSystemInterface</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">unsigned</span> width, height<span style="color: #008080;">;</span>
wsi<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getScreenResolution<span style="color: #008000;">&#40;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">ScreenIdentifier</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span>, width, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Once that is done we can create our (single) graphics context.</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// create a context that spans the entire x screen</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>x <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>y <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>width <span style="color: #000080;">=</span> width<span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>height <span style="color: #000080;">=</span> height<span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>windowDecoration <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>doubleBuffer <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>sharedContext <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
traits<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>overrideRedirect <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #000080;">&gt;</span> gc <span style="color: #000080;">=</span> osg<span style="color: #008080;">::</span><span style="color: #007788;">GraphicsContext</span><span style="color: #008080;">::</span><span style="color: #007788;">createGraphicsContext</span><span style="color: #008000;">&#40;</span>traits.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The important one here is overrideRedirect. Some window managers (I&#8217;m looking at you Gnome) will redirect the position of your graphics context, so it won&#8217;t appear where you want it. The overrideRedirect option is kindof new, it does not exist in the version of OSG shipping with Ubuntu 8.10. Therefore, I am running the latest stable release (2.6) compiled from source.</p>
<p>To get the equivalent of 2 screens to draw on, we create 2 views like before. However, we have to set their viewport manually. Here we just make v0 use the left half of the screen, and v1 use the right half. Easy enough?</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//first screen</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v0 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">Camera</span><span style="color: #000080;">&gt;</span> cam <span style="color: #000080;">=</span> v0<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getCamera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setGraphicsContext<span style="color: #008000;">&#40;</span>gc.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setViewport<span style="color: #008000;">&#40;</span><span style="color: #0000dd;">0</span>, <span style="color: #0000dd;">0</span>, width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">//second screen</span>
osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #000040;">*</span> v1 <span style="color: #000080;">=</span> <span style="color: #0000dd;">new</span> osgViewer<span style="color: #008080;">::</span><span style="color: #007788;">View</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
osg<span style="color: #008080;">::</span><span style="color: #007788;">ref_ptr</span><span style="color: #000080;">&lt;</span>osg<span style="color: #008080;">::</span><span style="color: #007788;">Camera</span><span style="color: #000080;">&gt;</span> cam2 <span style="color: #000080;">=</span> v1<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>getCamera<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setGraphicsContext<span style="color: #008000;">&#40;</span>gc.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
cam2<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>setViewport<span style="color: #008000;">&#40;</span>width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, <span style="color: #0000dd;">0</span>, width<span style="color: #000040;">/</span><span style="color: #0000dd;">2</span>, height<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
compositeViewer<span style="color: #000040;">-</span><span style="color: #000080;">&gt;</span>addView<span style="color: #008000;">&#40;</span>v1<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>setViewport sets the viewport of the camera. The first 2 parameters are the position in the context&#8217;s window, the next 2 are the dimensions. So, each view gets width/2 for the width, and the second screen&#8217;s position is offset by half the screen width meaning it starts on the second monitor.</p>
<h2>Conclusion</h2>
<p>And there you have it. Two methods for dual screen using OpenSceneGraph. Looking at the code, it is fairly simple. However, after browsing the doxygen docs for OSG it was not at all obvious to me. Of course, the osg-users mailing list was a big help here. In fact, <a href="http://groups.google.com/group/osg-users/browse_thread/thread/684fb727c4ab6ee2/daaa720956ae17e1" target="_blank">here</a> is the thread from the mailing list</p>
<p>Cheers<br />
Michael</p>
<p><center><script type="text/javascript"><!--
google_ad_client = "pub-9376349336558898";
google_ad_slot = "0815367707";
google_ad_width = 468;
google_ad_height = 60;
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
</center></p>
]]></content:encoded>
			<wfw:commentRss>http://www.20papercups.net/programming/openscenegraph-dual-screens-twinview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

