Demo Tutorial 1

This tutorial will be the first of a series I’ll write about creating demos. I’m going to start off with simple topics and introduce concepts and ideas you’ll need when coding graphics on a computer.

What’ll we do then?
I’m going to use the PTC library to demonstrate how to do graphical effects on your computer. I’m developing this tutorial on Linux so any instructions on compiling the example programs will obviously be for that platform. If anyone feels like contributing or changing anything please feel free to do so!
Before we get started you’ll have to download the PTC library from the link above. Do that now and click back to get back here when it’s downloading.
Unpack and compile the library somewhere (Make sure you read the INSTALL file. There are notes there on optimising the compilation.)
Assuming that all went well, change directory to the PTC “examples” directory and create a directory there called “tut01”.
What about writing a point to the screen? Cut and paste the following into a file called Tut01.cc in the tut01 directory.

#include “ptc.h”

int main()
{
    try {  
        // create format
        Format format(32,0x00FF0000,0x0000FF00,0x000000FF);
    
        // create console
        Console console;
        console.open(“tut01”,320,200,format);
    
        // create surface
        Surface surface(320,200,format);

        // loop until a key is pressed
        while (!console.key()) {
            // lock surface
            int32 *buffer = (int32*) surface.lock();
 
            // draw a white pixel at (160,100).
            buffer[160+100*320]=(255< <16)+(255<<8)+255;

            // unlock surface
            surface.unlock();

            // copy to console
            surface.copy(console);

            // update console
            console.update();
        }
        // exit
        return 0;
    } catch (Error error) {
        // report error
        error.report();
    }
}

The following is the Makefile you’ll use:

# GNU Makefile for the X11 part of the PTC 2.0 C++ API
# Copyright (c) 1998 Christian Nentwich (brn@eleet.mcb.at)
# The PTC 2.0 C++ API is (c) 1998 Glenn Fiedler (ptc@gaffer.org)
# This package is licensed under the GNU LGPL
#
# Please refer to the file COPYING.LIB contained in the
# distribution for licensing conditions

include ../../Makefile.config

PROG1 = Tut01

all: $(PROG1)

$(PROG1): $(PROG1).o

$(CC) $(PROG1).o $(PTCLIB) $(PTC_X_LIBRARIES) -o $(PROG1)

.cc.o:

$(CC) -c $(CFLAGS) $< clean:

rm -f *.o

distclean:

rm -f *.o

rm -f $(PROG1)

Now compile Tut01.cc by typing make.
If you have previously compiled the example programs that came with PTC this should compile without problems.
Now run it from an xterm by typing:

er see a small window with a white dot in the middle of it, or your screen will go black and a white dot will appear in the middle.
Press a key to escape out of the program

You’ve started on the road to creating a demo!

How it works.
(lots of info taken from the PTC Intro)
Format format(32,0x00FF0000,0x0000FF00,0x000000FF); – The Format class holds information about how pixels are composed. ie. 8 bit, 16 bit, 32 bit colour. The above code creates a 32 bit colour format.

Console console; – This is “your interface to the world. It contains the routines to access the framebuffer, and some simple keyboard routines.”

console.open(“tut01”,320,200,format); – This either opens a window or sets the screen resolution to 320 pixels across by 200 down. PTC will attempt to change screen colour depth to the closest one available to match your format.

Surface surface(320,200,format); – “A Surface is a memory area (in system memory, not in video memory) that you can draw into if you don’t want to draw directly to the screen.”
This command creates a 32 bit colour surface which is 320 pixels across and 200 pixels down

while (!console.key()) {

}

– While no key is pressed do the following…
When you lock the surface to write to it you get a pointer to it in memory. Then the program draws a single white pixel on it.
The surface is then unlocked, and copied to the console before the console is finally updated (meaning the image in “buffer” is drawn to the screen.

Notes

I presume you know how to code in C++. If you don’t you’ll be lost. Mail me if you want to know the _very_ basics and I’ll include some docs on that.
The above example was derived from examples in the PTC examples/ directory. Take a look there!
You do all your drawing to a special part of memory called a buffer. When all your drawing is finished that buffer is copied to the screen to be displayed. This way of drawing avoids the choppy updates you see in some demos and games where the image you see appears to update right in the middle of the screen.
The buffer you draw to is a 32 bit colour image of the screen. Even if your video mode isn’t 32 bit the conversion will be handled by PTC before it displays your buffer on the screen.
Make sure you read the docs on the PTC homepage. There isn’t much there, but it’s informative, and of course, you have the source code to the library to play with too. Make sure you take advantage of the “GPL” and learn from the code!

Want to code demos? I've star …

Want to code demos? I’ve started a tutorial on demo coding. If you’ve done any coding at all it won’t be anything new to you but for those others have a look. A knowledge of C++ is presumed, and is almost essential. Although I’m developing this in Linux, the code should compile just as well in Win32 with that platforms’ port of PTC.
Check the “Tutorials” link on the left side for more details!
Censor have a really nice site. Lots of screenshots of their old C64 stuff!
Also check out www.c64.com for lots of old C64 games!

Sad news. The Hornet archive w …

Sad news. The Hornet archive will soon close up shop and the Hornet group will disband. For those who don’t know, Hornet is probably the largest demo archive in the world but due to fading interest the group won’t continue to support the archive. There’s also an announcement available explaining what happened. The archive will be given over to scene.org so hopefully it will continue to exist.
As a final note, there are still Hornet CDs available. If you’re into demos it might be worth buying a copy of each.. I will.
I found a music tracker for Linux on freshmeat today.
Check out Sound Tracker which is described as a music tracker for the X window system. It looks promising.
Somehow by coincidence I come across another tracker for Linux. Have a look at Keg Tracker. Nice screenshot too!
Totally unrelated but interesting nevertheless. A friend discovered how to get access to any file on a WinNT machine even without being admin on the machine. Take a look at IE4 (Internet Options) and you might figure it out.. (This is probably an old hack but I haven’t heard about it before..)

I'm kept busy these days. Apa …

I’m kept busy these days. Apache+mod_perl+DBI is amazingly fast! 100 concurrent queries only took 2-3 seconds! (tested with “ab”)
PCPlus is out again this month featuring Linux stuff such as NS 4.06, Interbase 4, and Blender. It also has a snapshot of the Mozilla source code from last August. Well worth getting (even if you only want Delphi 2 which is on the other CD!!)
I finally compiled PTC and the included demos run very nicely. The “RealTunnel” demo is quite nice. Just as I compile it a new version comes out! Check out the homepage above!
Having trouble getting email to work as you’d like it to in Linux? Check out my install script which I wrote after finally getting qmail working! It’ll probably work for you but I ony guarantee it’ll take up room on your computer!
I updated my desktop page with a 4 screens wide screenshot of my Window Maker desktop. Have a look. The jpeg is only 18k!
Woo! I broke 10,000 hits! Celebrate! *grin*

Finally I'm using Linux at wo …

Finally I’m using Linux at work! I can do some kick-ass work on perl scripting, database connectivity, and do some cool automation to update the site everyday! 🙂
The Beginners Linux Guide has moved home to www.linux.ie, so go over there and check out some of the new docs Owen has written!
Mesa has reached version 3.0 which is old news by now but worth mentioning anyway!
I got an email yesterday from someone asking about coding in assembly. I used to code demos using ASM, but that was quite a while ago. In this day and age I would recommend using C/C++ with _maybe_ inline assembly in low level classes/functions to get things going fast. With new processors coming out and different operating systems running on them/on old processors coding an application/demo restricts your potential audience greatly! Still, asm has it’s advocates and benefits but the disadvantages outweigh these IMO.
Oh yes. My site is a few hits short of 10,000 hits! If someone sends me the gif of that hit I’ll give them a mention on the page!
Another big announcement recently was the release of Scitech Display Doctor. This may very well encourage demo coders to move to Linux but it’s proof of the awful architecture of the PC, especially when it comes to the video sub-system. The screenshot on the above page looks very familiar..

Two little tips for Netscape:
Middle-mouse button clicking on a link brings the link up in a new window.
Copy a URL to the clipboard and click the middle-mouse button in Netscape (on a clear part of the page) to load the URL in the browser.
Second tip was courtesy of the ILUG mailing list
Download squid to improve your browsers’ perceived responsiveness. It works great and you don’t get any of the Netscape stalls when you pressed ESC when it was “Looking for host:…” because it doesn’t look! Squid does!
This essay makes quite good reading, especially if you think that everyone should use Linux and Linux is perfect for everything. Again, I got this link from the ILUG mailing list.
I think I’ll buy a Microsoft wheel mouse for home. I got the one in work to function in X and it rocks in Netscape. The wheel even acts as a middle mouse button when pressed down!
A friend pointed out this article by Cringely. Interesting reading on the freedom of utilities and consumer goods, and the goings-on of Microsoft.. Thanks Mark.

All you mp3 fans should get ov …

All you mp3 fans should get over to the Blade enc. homepage. It’s something like 25-30% faster than the 8hz encoder and while source isn’t available, there are glibc2 and libc5 version for i386 Linux. Other platforms are supported too and well worth downloading.
The Mesa openGL library has finally reached version 3 although I guess you all knew about this thanks to slashdot and freshmeat. 😉
Check out Linux Games for a link to screenshots to a version of Xmame using openGL. Looks cool!

I found a few things of intere …

I found a few things of interest on freshmeat today.
First off is FxEngine which is a graphics lib for the 3dfx using 3dfx glide. It originally appeared on Win32 but a slightly earlier version was ported to Linux. So, if you want to do a 3dfx demo in win32 and Linux then this may be the answer.
The screenshots are impressive on the homepage although if the fps in them is true I wonder if it’s slow..
A new release of Prometheus Truecolour is out too. Supposedly it has a ton of new changes so get it if you’re interested in this!
On a final note, I installed Quake2 on a friends’ Linux box tonight. The 3dfx mini-port was ported from Windows95 and the game now flies. I was amazed at how fast it was on a P133. I remember it had been impressive before, but now.. *phew*

According to Linux Games there …

According to Linux Games there’s a new game using openGL called BFRIS. It’ll apparently be released on Linux too and the screenshots look pretty tasty!
You may have seen links to NewsNow popping up around the place. It’s a very good site for grabbing the latest headlines. You can even grab the latest Linux headlines! Unfortunetly their database hasn’t been updated at this time since Sep. 11th so news is actually old, but when they have it running properly again you can expect up to the hour news! Check out NewsNow if you want to be the first to post an article on Slashdot 🙂

A bit late with this update. T …

A bit late with this update. The Babylon Project was featured on Slashdot a while back. It has an ambitious aim, it “aims to become a standard development platform for Computer Games (and possibly other software in the future) allowing the developer to make one executable that can run on any x86 based microprocessor, regardless of operating system (thus freeing the developer to concentrate on developing the GAME, and not having to worry about platform specific problems).”

They’re going to use Linux as a base OS, one reason being is the availability of the OS on many different architectures. It seems they hope to use the idea of booting Linux to play games using some Linux loader (loadlin?). This would have worked in the days of DOS but nowadays people expect things to work by just clicking..
Several new versions of PTC came out in the last while. Check them out at the link below somewhere.
My machine isn’t so out of date anymore! I now have a P200MMX chip, 64 megs of ram, 13 gigs of space (heh.. gotta try out Suse and BeOS again!) and I invested in a tv tuner which unfortunetly doesn’t work very well with my S3 chip in X 🙁
‘Course, some friends have PII 400s and masses of ram and lots of other stuff, but then, they’re running an MS OS 😉
A note to all you Irish guys! There may be a Quake meet in Dublin on the 19th of the month (next week!) I want to be there, will you? email me about it!
It appears that a large minority of you would like some help in demo coding.. Anyone interested in a series on coding in X? My aim will be portability, and I might veer off to weird stuff like networked demos and the like.. I’ll be thinking about it. It might require a whole new site though!
I was just checking through The Linux Scenezone when I stumbled across the Optimum homepage. Unfortunetly it’s in French but it has a nice bit of Javascript that makes some circling balls follow the mouse around the browser.. *cool* IMO 🙂 Besides that the page has tiny fonts 🙁 One more thing to note is they host the Linux DemoScene Ring. I joined. If you have a Linux demoscene related site why not join too?

**Late News**
It seems like the Babylon project had to rename itself because the name was being used already. It’ll now be called the Babel project and can be found at http://celsius-software.hypermart.net/babel

I updated the plan with a litt …

I updated the plan with a little rant.

I read with interest a review of a beta version of Visual Studio for Windows, and was struck by the amount of fancy names and acronyms for simple computer programs/services. Active-this and Active-that.. Of course! How silly of me! It’s completely impossible to do the same thing with a bit of perl and a decent database (MySQL anyone?) because they haven’t got ActiveXXX built in. I remember listening to a classmate of mine last year about how great a MS app was because methods were exposed and you could call this or that. Dumb! Then there was the two execs at a company I overheard saying you could do a reverse query down the pipe with MS SQL Server! Fancy words! When you get down to it, what’s the best solution? Alternative solutions have been doing the same thing for years! Sockets have “exposed” services to other computers for ages! Libraries have offered functions for longer than MS has been around! How did the world get by without MS for so long?! *gasp*
Next time you hear someone talk about how great an MS or corporate product is, don’t be over-awed by the fancy terminology, just ask what it _actually_ does. Is it useful and reliable? Will it actually help the programmer be _creative_ and offer the freedom to manipulate the computer to do exactly what you want in a timely and efficient manner? Is that “component” your manager is saying you should use actually useful or are you wasting your time?

I used to think that MP3s were “just as good as CDs”. I don’t now. 🙁 Even at 128k/sec there’s that slight annoying warble, and high pitched female voices sound kinda tinny. That’s one of the side effects in investing in a decent stereo system. At least I can play my CDs without sacrificing a CDROM now!
Lots of demos released at ASM ’98. I downloaded some of them, mostly the ones mentioned on The PC Demos Fanclub homepage. They’re all big monsters but I’d only recommend one myself, the 4k demo called Mesha. Excellent stuff and blew me away with the amount of code and effects they squeezed into 4k! Have a look in the demos incoming directory of Hornet for more demos. Especially check out the 4k directory in the ASM directory. Some very good demos there.
After checking out the latest games featured on the PCW CD, I’m yet again wondering where demo coders hope to go with their huge 5-6 meg 3D demos. If they don’t use a 3DFX or any hardware acceleration demos just will not impress anymore.
Me? I want to do a scroller.. 🙂