Hacking «The GL Matrix»

To my second post.. ..I am going to show you (something that some may find quite useless) as change the color of my favorite screensaver (screensaver, screensaver) about xscreensaver, G.L.Matrix, which if you do not know it is a simulator of the typical symbols falling through the monitor in the Matrix style with beautiful 3D effects. Here is an image:

As I am quite annoying, and my computer is customized with the colors black and the characteristic blue of Arch Linux (which looks great with my blue backlit keyboard xD) .. ..the typical green of Matrix, it does not combine me (or as one would say around here and among children, it does not even hit with mucus).

To achieve this, we will meddle in the source code of the xscreensaver, do not panic the inexperienced, it is simple, and I will guide step by step so that they achieve it; with this I want to tell you, that I am not going to leave things already chewed, but that the idea is that they take a drink and put their hand..without fear.

Note: I'm not an expert at all ... so whatever mistakes I'm making, feel free to tell me ...

Let's do it..

1- Download source code of xscreensaver.

We can enter the xscreensaver page, and we download the latest version of source code (source code).

www.jwz.org/xscreensaver/download.html

Or we can download directly from the terminal with wget, always knowing the version of itIn this case 5.20:

 $ wget http://www.jwz.org/xscreensaver/xscreensaver-5.20.tar.gz

We unzip it:

 $ tar -xf xscreensaver-5.20.tar.gz

 2- Check your dependencies.

We are going to verify that we have the necessary packages so that the xscreensaver can be used, for this we will use the 'configure'. Must pay attention at the exit (output) that they give us, to know if we some package is missing, or is there some error. If a package is missing, look for it and download it (it can be through synaptics, apt, pacman, etc. - depending on likes and distros).

-We enter the newly unzipped folder:

 $ cd xscreensaver-5.20/

We execute the following:

 $ ./configure

3- We verify correct operation.

If no package is missing, nor have no mistake; we proceed to to install the xscreensaver, to verify that it works correctly.

We execute:

 $ make
Note: make usually takes a few minutes, since it generates all the files a .o (executables) from the .c (code), that is, it compiles the package.

If there are no errors in the make, as a user 'root' we install it:

 # make install
Note: No. I will explain in detail for those who do not understand what these commands do, for more information look about compilation and Makefiles.

We test:

 $ xscreensaver-demo

4- Modify /hacks/glx/glmatrix.c

They will talk with their text editor favorite (vim, nano, gedit, etc) in my case I saw, the file that we are going to modify in this case:

 $ vi ./hacks/glx/glmatrix.c

They have to find a block with the following crafts:
{
unsigned long p = XGetPixel (xi, x, y);
unsigned char r = (p >> rpos) & 0xFF;
unsigned char g = (p >> gpos) & 0xFF;
unsigned char b = (p >> bpos) & 0xFF;
unsigned char a = g;
g = 0xFF;
p = (r << rpos) | (g << gpos) | (b << bpos) | (a << apos);
XPutPixel (xi, x, y, p);
}

It is located approximately on line 760, but searching for "a = g" should find it right away

Y we add as follows the desired color:
{
unsigned long p = XGetPixel (xi, x, y);
unsigned char r = (p >> rpos) & 0xFF;
unsigned char g = (p >> gpos) & 0xFF;
unsigned char b = (p >> bpos) & 0xFF;
unsigned char a = g;
r = 0x71;
g = 0x93;
b = 0xD1;

p = (r << rpos) | (g << gpos) | (b << bpos) | (a << apos);
XPutPixel (xi, x, y, p);
}

Being in RGB Hexadecimal (red-green-blue)

E.g., the characteristic blue of Arch Linux is he: #1793D1, remaining:

r=0x71;
g=0x93;
b = 0xD1;

We keep the changes.

5- We recompile the new xscreensaver with the modified glmatrix.

At this point we will do practically the same as in the point 2, but this time to capture the changes we made.

We execute:

 $ make clean

Then:

 $ make

If no kind of error came up in make, as user 'root' we execute:

 # make install

6- We execute, verify, configure and enjoy.

We execute:

 $ xscreensaver-demo

In the list we choose G.L.Matrix:

GLMatrix Preview

And in the presentation it should already be seen in the color they chose.

Note: in some cases, it may be necessary to restart the computer in order for the changes to take effect both in the Preview and when it is run.

Configure to taste .. and enjoy 😉

7- Some examples of different colors. (+ TIP)

Hexadecimal Color: # 9F03D9

Hexadecimal Color: # D41213

Hexadecimal Color: # E5E311

TIP: to know a color en Hexadecimal i use GIMP, we open the color palette and figure as "HTML notation". We can also press the 'o'and take the color of an image to know what its color is in Hex.

I hope you have enjoyed trying and writing it as much as I did. Do not hesitate to consult with any questions.

Happy hacking ..


Leave a Comment

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

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   merlin the debianite said

    Well, if it looks pretty and everything, but there is nothing like the classic green color.

    1.    RAW-Basic said

      Thanks for your comment .. ..it is clear that classic is classic ..

      But the funniest thing about this (at least for me) and what prompted me to do it .. ..is knowing that having the source code in front of us .. is like saying “I have Linux, and how I want to change it. . ..may l!.."..

      Thanks for reading .. 😉

  2.   mr linux said

    Excellent article, who would have imagined that on a subject as elementary or simple as a screensaver, we were going to have a whole class of compilation, modification and installation of it.

    1.    RAW-Basic said

      Thank you! .. ..I am glad that you are interested ..

      For me it was quite a learning odyssey too;) ..

  3.   rots87 said

    is there any difference with using:

    $ sudo pacman -S xscreensaver

    1.    RAW-Basic said

      For what part? .. ..if you refer to points 2 and 3 to verify if it works .. in your case if you use Arch..yes, it is the same .. since we always have the latest version .. ..but for other distros may not be the same ..

      On the other hand..if you don't download the source code .. ..you could not do the color modification .. which is the objective of this post ..

      Did I answer your question?

      1.    rots87 said

        ok thanks for the tip ^ _ ^

  4.   rafagcg said

    Thank you so much!!
    The procedure is very interesting.

    Regards!

  5.   KZKG ^ Gaara said

    Thanks for the contribution 😀

  6.   BOLD said

    Is it possible for you to share the modified model with the color red? thank you