Sunday, April 17, 2011

Dual Screen (TwinView) Gaming in Ubuntu/Linux

I just bought the latest Humble Bundle from Frozenbyte (there's still time for you too!) since I wanted a couple of games to play on my Linux machine. I already own Trine for Windows but at the cool price of $howevergenerousifeel, it saves me from rebooting my machine over to Windows (never a pleasant day). So I downloaded the game, put on my wizard hat and gaming goggles, and fired up the game. By default, I could see that the game was detecting the full resolution of my monitors combined (3840x1200). This should be expected if you're using TwinView to display both monitors. TwinView literally tricks your video card into thinking both monitors are really one giant display, making dual monitors even more awesome and/or difficult depending on your given situation.

In this situation, I only want to have the game be displayed on my left monitor (1920x1200). But when I launch the game at this resolution, it sits the game's display smack in the center of the intersection of the two displays, making me stare straight at the edges of the two monitors. Why? Because my video card thinks I am using one giant monitor and so it sits the game directly in the center according to that resolution. So how do we fix this? Well, one option is to not make the game full screen and just play the game maximized on the screen we want it to display on. But that's hardly a solution. Let's take a look at our X11 config file (/etc/X11/xorg.conf). If you scroll down to section "Screen", you'll see something that looks like the following:


Section "Screen"
Identifier "Screen0"
Device "Device0"
Monitor "Monitor0"
DefaultDepth 24
Option "TwinView" "1"
Option "TwinViewXineramaInfoOrder" "DFP-0"
Option "metamodes" "DFP-0: nvidia-auto-select +0+0,DFP-1: nvidia-auto-select +1920+0"
SubSection "Display"
Depth 24
EndSubSection
EndSection


If it looks a little different, don't worry. These settings are usually automatically created when you use NVIDIA X Server Settings or a similar tool to configure your dual monitors. So the settings of interest here is the metamodes. The format for this option is: "metamodes" "resolution of left most monitor, resolution of right most monitor". In my automatically created settings, my left most monitor has been titled DFP-0 and given an automatic resolution at location (0,0), and my right most monitor has been given an automatic resolution at location (1920,0). To solve our problem, we add two new "metamodes":

Option "metamodes" "DFP-0: nvidia-auto-select +0+0,DFP-1: nvidia-auto-select +1920+0;1920x1200,NULL;NULL,1920x1080"

Each semicolon indicates another "metamode". The "1920x1200,NULL" mode is used when a resolution of 1920x1200 is requested, resulting in the left most monitor only being used. The "NULL,1920x1080" mode is used when a resolution of 1920x1080 is request, resulting in the right most monitor only being used. In the case where both of your monitors are the same resolution, there would only be reason to create one extra mode instead of two since only one other type of resolution would ever be requested besides the default.

Now when I launch Trine at 1920x1200, I don't have to stare at the split between my two monitors! Leave a comment if this helps or you have any questions. Happy gaming Linux fans!

9 comments:

  1. I'm trying to get this done but it's not working right now. I'll see any errors i might have and post here, do you usually comment back? Thank you for the post

    ReplyDelete
  2. Thanks a lot, worked nicely!

    ReplyDelete
  3. Easy-peasy. Thanks! Is there way to apply these changes without a full restart of your display manager(lightdm, etc.)?

    ReplyDelete
    Replies
    1. Dave, you only need to restart X, so that'll depend on the shortcut in your distribution and setup. I know history that has been Ctrl + Alt + Backspace but I have also seen it as Alt + PrtScn/SysReq + K. The newer version of Xorg has disabled this shortcut to restart by default. It looks like you could restore that functionality as documented here: https://wiki.archlinux.org/index.php/Xorg#Ctrl.2BAlt.2BBackspace_does_not_work

      Delete
  4. 3 stars blog post !
    Thanks to it and the good ranking in google for 'metamodes' 'nvidia' 'linux' 'gaming' keywords, I could finally play non-windowed my game and so, enjoy a high FPS. So cool for Nexuiz :D

    ReplyDelete
  5. It doesn't work for me. I think I'm doing something wrong. My games are still over both screens.

    ReplyDelete
  6. Thanks - this was helpful. Unfortunately, I needed to do more research since my system doesn't have an xorg.conf file by default.

    ReplyDelete