The simplest way to write your own screensaver for Linux is by creating a new module for the program xscreensaver. This way, all is needed is a program that draws something, while all the rest (activating the screen saver when needed, locking the screen, checking passwords, etc) is done by xscreensaver itself.
I assume that xscreensaver is installed and running on your computer. The following pages tell how to write stand-alone programs that draw something in the root window. When used as modules of xscreensaver, they draw to the screen whenever the screen saver is activated. These programs use only calls to Xlib, and provide a sort of basic tutorial on Xlib.
The following is a list of pages, each containing the explanation of a module. The first one is very simple. The next ones introduce, one by one, the concepts that are needed to write more complex modules.
The example modules are not very elaborated: they use Xlib alone (no toolkit and no resource managment); they can only draw in the root window (and not in a separate window); they determine the display to open using the environment variable $DISPLAY only. Some more tips can be found in the xscreensaver FAQ.
This is not an introduction to the X Window system programming, as it only covers what is needed for the purpose of writing a screensaver module. For more on Xlib alone, I suggest this page on Xlib. If you want to write a GUI, you should use some widget library, such as the Athena Widget or Motif. There is a good tutorial on Motif on the web. A good starting point about X Window in general is this list of X link.
I would like to hear what you think (comments/corrections are welcome). My email is liberato@dis.uniroma1.it.