Source for drawing/textures.php:

<?php 
ini_set
('include_path'ini_get('include_path') . ':/home/benm/public_html');
include 
'http_header.php'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
    "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<?php $f "drawing/textures"
include 
'head.php'?>
<title>textures - drawing - ben's machinery</title>
</head>
<body>
<?php include 'title.php' ?>
<h2>Allegro Textures</h2>
<p class="box">Early on in the development of my <a href="bunker.php">Sauerbraten map</a>, I realised that Sauer's texture library, though impressive, included nothing appropriate for my purposes. I needed to make my own textures. Having, over time, become more familiar with <a href="http://alleg.sourceforget.net">Allegro</a>, I elected to make my textures not with graphics packages but with C programs.<br/>
To be fair, I had just updated to Mac OS X Leopard, breaking Photoshop and carrying an X11 buggy enough to render the GIMP useless, so it seemed like a good idea at the time. Anyway, below are reproduced the textures and source code.<br/>
Be aware, though, that no effort is made to ensure compatibility or provide diagnostic tools or even comments of any kind at all, since I had no intention while writing them to distribute these programs. It's something I might or might not work on more one day.<br/>
In addition, the images shown are the ones used in the map, not necessarily identical to those generated by the programs. I couldn't work out libpng sufficiently to output to that format, so they tend to write TGAs which I convert afterwards.</p>
<h3>Global files</h3>
<p class="box"><a href="textures.h">textures.h</a> is rather sparse at the moment, mostly just to specify the save location, common include files, and two function prototypes to aid use with shared.c.<br/>
<a href="shared.c">shared.c</a> defines two functions, <span class="code">program_close</span> and <span class="code">draw_tile</span>. <span class="code">program_close</span> is a simple callback for Allegro to respond to the close button or Quit command. It's recommended that close button callbacks just set a variable and check for it in the main loop, but I reckon these programs are simple enough to not need that kind of security.<br/>
The <a href="Makefile">Makefile</a> has rules to build every program on this page and one or two extras that I haven't got around to or have decided not to upload. <span class="code">make all</span> will therefore probably throw an error, so select specific targets from the output of <span class="code">make</span>.</p>
<h3>Floor (and ceiling)</h3>
<p class="box"><img src="floor.png" alt="Floor texture sample" class="left-image"/><a href="floor.c">floor.c</a> is an example of use of the <span class="code">draw_tile</span> function. If you want to try running it yourself, the first thing you have to do (and this applies to most of the following programs) is change the FILESAVE_PATH in textures.h to one that actually exists.<br/>
The <span class="code">srandom()</span> calls, presence of <span class="code">time.h</span> and <span class="code">dirty</span> function are the beginning of an as-yet unimplemented method to cover the tiles in believable and random mess. You can ignore them, and comment them out if they cause trouble (I forget whether <span class="code">time.h</span> is platform-independent). That possible functionality is also the reason the texture is created in 4 times the dimensions one would expect to be required.<br/>
The program maintains its presence onscreen through an infinite loop. I've heard this saps clock cycles unnecessarily and will look into other methods of hanging around.<br/>
In the map, this texture is used on virtually every horizontal surface. It is really only meant as a floor texture, but it also works well as a ceiling until I can make a better one.
<span class="clearer"/></p>
<h3>Striped corridor wall</h3>
<p class="box"><img src="stripes.png" alt="Striped wall sample" class="left-image"/>Is there any texture more evocative of the level?<br/>
<a href="stripes.c">stripes.c</a> was the first program I wrote in the series. It took some doing getting the tesselation exactly right (note the commented out mouse routines - if you uncomment them you might jsut get a simple drawing mechanism), and wasn't as simple as I had hoped, but ultimately the algorithm is pleasingly small. 
It's obvious from comparison shots that the grey needs to be lighter and the stripes narrower, but it's one of those things I haven't got around to handling yet.
<span class="clearer"/></p>
<h3>Strip lighting</h3>
<p class="box"><img src="striplight.png" alt="Strip lighting" class="left-image"/><a href="light.c">light.c</a> is mostly just another call to draw_tile, indeed its similarity to the floor texture was what led me to write the header file and shared file. It needs to be lightened in-game, and I need some diagonal ones as well, but mostly I'm pretty happy with this one.
<span class="clearer"/></p>
<!--
<a href="light.c"><img src="striplight.png" alt="Strip lighting"/></a></p>
-->
<?php include 'footer.php' ?>
</body>
</html>

View source for: