Mittwoch, 11. März 2015

Remove video tearing from nVidia GTX 600/700/Titan series on Linux

Background Story:
A few days back I switched from KUbuntu to Arch Linux, mainly because wanted more control over my System and also because I was not to Happy with KDE anymore.
On Arch Linux the first Window Manager I tried was Plasma5, and I managed to fix a screen tearing issue with the help of some of its setting. But overall I found Plasma to be a bit buggy on some parts and felt that I needed some other Window Manager, wich was why I switched to XFCE one or two days later.
The problem: Screen tearing in XFCE, no matter what I tried to fix it (Using compton, some edits in the .xinitrc file ...), it just stayed and after something I changed it even got quite a bit worse. After searching the web for a while I found this little change to your xorg.conf that fixed it right away:

The Solution:
I found a way to fix my problem at this page:
https://wiki.manjaro.org/index.php?title=Remove_video_tearing_from_nVidia_GTX_600/700/Titan_series

It says to add this line to your screen section in /etc/X11/xorg.conf:
Option "metamodes" "nvidia-auto-select +0+0 { ForceFullCompositionPipeline = On }" A problem I had with that was the following: I use three monitors and also I used nvidia-settings to generate my xorg.conf file.
nvidia-settings seems to auto-generate the part Option "metamodes" "nvidia-auto-select +0+0 so you just need to add the part in the curly brackets. Also, if you have multiple monitors, this thing will look slightly different:
Option "metamodes" "VGA-0: nvidia-auto-select +0+0, DVI-D-0: nvidia-auto-select +3200+0 , HDMI-0: nvidia-auto-select +1280+0" So as you can see the option has one part for each monitor. You then just need to add the {ForceFullCompositionPipeline=On} part to every monitor, so my end result was this line:
Option "metamodes" "VGA-0: nvidia-auto-select +0+0 {ForceFullCompositionPipeline=On}, DVI-D-0: nvidia-auto-select +3200+0 {ForceFullCompositionPipeline=On} , HDMI-0: nvidia-auto-select +1280+0 {ForceFullCompositionPipeline=On}"

Montag, 28. Juli 2014

Roller Shutter project: GPIO Relay Initialization on system boot

For my roller shutter controller project, I needed to ensure that the GPIO Pins for the Relay board get correctly exportet on system boot. I had a script called init.sh in the directory /home/pi/relay. When I executed the script everything worked and I could trigger the relays with my webinterface I made before. Now there was a problem:
How to get this to work on system boot?
I found several different ways to do this on the internet, and tried two different ways to do it:
The first was an entry in the /etc/rc.local, the second a crontab entry (via sudo crontab -e) with @reboot for execution. Both of those methods failed even though I could see at least the rc.local was getting executed, because for a test I put the command touch /home/pi/somefile in it, wich got executed on boot. (I did not try this for crontab)
After some trial and error and looking around in the internet I found the problem:
I was using the program gpio in my init.sh file, wich is located at /usr/local/bin/gpio. When you execute a program with just the executable name, the system searches for an executable with that name in your $PATH variable wich gets set while starting up the system. And thats exactly the problem: It gets set after rc.local is executed or cron executes the jobs marked with @reboot.
So to fix my problem I just had to change my calls from gpio to /usr/local/bin/gpio and everything worked like a charm.

Next problem:
In my scripts to move the roller shutter down and up I use another script wich stops the shutters (turns both relays off). I call that before turning anything on because I don't know how the roller shutter reacts when it gets a signal for up and down at the same time. When I just use the scripts from the console this works fine, meaning you will never see both relays on. But here is my problem: I have a web interface setup, wich has links to php-files that use shell_exec to execute my scripts. When I use the web interface the stop script does not seem to get executed, and so I can get both relays on.

Change the Raspberrypi hostname

I'm currently creating my on control system for two of my electric roller shutters.
They will be time controlled, maybe have a light sensor and two physical buttons to control them. But more important: There will be a webinterface to move them up and down and to set the times for the shutters to go down or up.
Since I use multiple raspberry pis in my house and also wanted a logical hostname to access the pi, I needed to change the hostname of the pi.
To do this you need to edit two files:

1. /etc/hostname
This file contains only one line with the hostname. The default with Raspbian should be raspberrypi, so edit it to whatever your new name should be. (Remember: You need root access to edit these files, so you have to use sudo nano /etc/hostname for example!)

2. /etc/hosts
This file has multiple lines. The interesting part for us is the last line:
127.0.1.1      raspberrypi
Change raspberrypi to the exact same hostname you used for the first file and you are good to go!
Restart your Pi and from now on you should be able to access it with your new name.

Donnerstag, 10. Juli 2014

Tile bleeding in LibGDX using the Tiled MapEditor

I'm currently developing my first bigger game in LibGDX using Maps made with Tiled and Box2D for physics.
It went pretty good so far, but I stumbled across a strange problem: There was some nasty tile bleeding in some areas of my game.
The first solution I found was to round the camera coordinates wich seemed to fix my problem at first, but then it happened again.
Then I found the real solution for this problem:
What you need to do is to add a so called gutter to your spritesheet. A gutter is padding between the single tiles but instead of just beeing transparent pixels the padding will be filled with the edge pixels of each tile.
You can do this with a nice little GIMP python script:
http://registry.gimp.org/node/26044

Once you have installed that script, load up your sheet file with GIMP and select "Add Gutter" from the Sprite Sheet submenu in the Filter menu.
You will see a window like this one:

Use a padding of 1, make sure to put the right tile size and enable the Generate Gutter option. When you hit OK it will do its magic and you have your sheet with padding in no time.
The next step is to add the Tileset to Tiled. Select Map>New Tileset. You will see a window like this:

The margin is the border of each tile that will be ignored for the mapping. Spacing is the distance between each tile in the image. It is important that you set the Margin to 1, to get rid of the 1 pixel border we just created around each tile with gimp. But notice: The spacing will be 2 because we have a one pixel border around each tile, and between two tiles are two borders (one from each tile) so you need to use a spacing of 2.
If your map has a transparency color be sure to set that to.

Now you are finished: You have your nice sheet in the Tiled editor and will not experience any tile bleeding while playing your game!

Have fun with this little hint!

Sources:
StackOverflow answer