OpenGL gotcha: depth buffer distortion
Posted by Peter | Filed under Programming
While I’m on the topic of OpenGL gotchas, I thought I’d mention another which caught me out a couple of years ago. I was working on some prototypes with some friends, and you can see a screenshot on the right (click it for a full view).
Notice areas where polygons overlap — you can see a striped or checked pattern of the occluded polygon showing through. In this case, it was 2d graphics and a 3d camera (so that we could make some interesting visual effects). However, the problem manifests just as badly in full 3d.
It took quite a while to figure out the problem, and it’s one I’ll never forget.
OpenGL gotcha: mipmaps only please!
Posted by Peter | Filed under Programming
Here’s an OpenGL gotcha which caught me out for quite a while. I was writing code to load textures, but it only worked if I was using the GLU function to build mipmaps. After lots of hair-pulling, I realised that it was entirely my mistake.
Using GDI+ in C++ Win32 programming
Posted by Peter | Filed under Programming, Software
If you do any Win32 programming in C++, then I strongly recommend you learn about GDI+. It’s been around for a while now, but not everybody knows about it. It can be great to have on hand even just to illustrate tests and prototypes.
Why is it so good? It provides an object-oriented way to draw graphics using the GDI, which is much nicer and easier to user than the basic C-style GDI functions and resources that used to be the norm. It also provides a lot of additional functionality which otherwise was not possible (or at least not easy) with the regular GDI functions alone, such as proper alpha blending, matrix transformations, file input/output, and loads more. It’s quite easy to setup too, as I will explain…
Read the rest of this entry »
Working with COM and DirectShow
Posted by Peter | Filed under Programming
I’m doing some work with webcams just now, and in the pursuit of efficiency, I am turning to DirectShow — that is, the part of Microsoft’s DirectX which handles things like videos and webcams. Surprisingly, I have hardly used DirectX at all before, except briefly in 1st year as an undergrad, so it’s fairly new ground for me. However, I quickly found that it really is well worth spending time getting familiar with the technology, as it can be amazingly useful.
Flash for the open source lover
Posted by Peter | Filed under Programming, Software
I may be a number of months behind the game in this one, but in my meanderings about the web, I ran across the beautiful “swftools“, which is a collection of open source (GPL) tools for doing stuff with SWF files. In other words, Flash… and you don’t need any piracy shenanigans to do it. (That’s been the one hurdle that stopped me from making Flash content before… I don’t have the money to buy the official software, and I refuse to stoop to piracy for it).
Being a bit of a programmer, my favourite part is definitely the “swfc” component, which lets you do some nice scripting to make stuff happen. Rock on… I might manage some web-game development yet!
From a serious educational point-of-view, I think this could be great for folks learning programming, especially if it’s in a games/media setting. We see plenty of Java floating around colleges and universities, but seriously, when was the last time you saw a good web application coded in Java? There are certainly some, but most of the time, it’s SWF. It’s not exactly the conventional ActionScript development that Adobe would probably want everybody to do, but nonetheless, it can be used to produce something that is relevant in a modern context… and that’s got to be good when trying to encourage folks to face their fear of computer code!
As a side note, I have seen various other neat (and free) bits of software out there which can automatically generate SWF files, be it for image slideshows or interactive graphs. All this has happened since Adobe opened up the format back in May this year. Shame it took so long to get there, but I salute the decision! ![]()
“DroidBattles” — makes learning assembler fun!
Posted by Peter | Filed under Programming, Software
OK, so it’s not exactly a ‘real’ assembly language, but DroidBattles seems to be an awesome bit of software anyway. The concept is really very simple — you program ‘bots’ (or droids) using an assembler-style language, and pit them against each other in an arena.
You start by selecting which components your bot will use, including CPUs, engines, armour, weapons, scanners, and so on. You then code it all up using the built-in language, assemble it, and you’re ready to go. The simple quick-start tutorial is a great starting point, showing you how to create a simple bot that goes in circles and shoots whenever something is in front of it.
The graphics are very basic, but certainly sufficient, so I’d recommend it as a fun way to help people learn more about assembler programming.
(I’m running it on Linux, but apparently it works on Windows too.)
llDetectedTouchNormal
Posted by Peter | Filed under Programming
Today I’ve been trying out one of the new LSL functions in Second Life ®. The function is llDetectedTouchNormal, which returns a vector representing the normal of a surface at the point it was touched. (You need SLClient 1.21 to use these functions).
The aim of my endeavour was to make an object which detects where you touch it, and moves a stack of small spheres to point at that location. The reason the normal is useful here is because it will make this stack work on all sides of the object, even if it is a complex, deformed, rotated object.
Here is the script for the main object:
default
{
touch_start(integer num)
{
// Ignore touches on anything but this prim
if (llDetectedLinkNumber(0) != llGetLinkNumber()) return;
// Determine the exact local position and normal of the touch
rotation rootrot = llGetRootRotation();
vector pos = (llDetectedTouchPos(0) - llGetPos()) / rootrot;
vector nml = llDetectedTouchNormal(0) / rootrot;
// Encode the information, and send it out to our pointer objects
llMessageLinked(LINK_SET, 0, (string)pos + "|" + (string)nml, NULL_KEY);
}
}
Notice that we have to correct for the main object’s orientation? This is very important, in case it is rotated in any way. Here is the script to put inside each ‘pointer’ object:
default
{
link_message(integer sender, integer num, string sval, key kval)
{
// Determine our position and normal vectors
list parts = llParseString2List(sval, ["|"], []);
if (llGetListLength(parts) < 2) return;
vector pos = (vector)llList2String(parts, 0);
vector nml = (vector)llList2String(parts, 1);
// Determine the offset of this pointer
float offset = (float)llGetObjectDesc();
// Update the position of this pointer
llSetPos(pos + (nml * offset));
}
}
You will perhaps notice that the pointer object uses its object description. When you create your pointer objects, enter a number into each one’s description field. This number (or ‘offset’) indicates how far (in metres) you want that object to be from the surface of the main object. My original example had four pointer objects, stacked with offsets of 0, 0.25, 0.5, and 0.75 (the pointers themselves were spheres with diameter 0.2m).
You can adjust the offset values to whatever you prefer. A value of 0 will centre the pointer directly on wherever you touch the main object, while negative values will make the pointers go the opposite direction.
Here’s a screenshot of my implementation:
This example is fairly simple, and could certainly be improved upon significantly. One particularly useful feature to add would be determine the rotation for an object to make it point along the normal (so you could e.g. use arrows instead of spheres). Feel free to IM me in-world if you’d like a copy of my demo (full perm, of course!). My avatar is Pedro McMillan.
Programmer Productivity
Posted by Peter | Filed under Programming
Quick link here to an interesting article:
It’s about the difference between different ‘levels’ of programmer… some are good, others are totally mind-blowing. I’ve certainly known a number of people in the bottom couple of categories (drones and idiots)… not that I say that to be insulting… it’s merely that some people are simply not cut out for it. (Let’s face it… if I tried to become a hospital nurse or a painter, I would fail miserably!)
The workhorses are always good to have around though. Programming is a job, and that’s it. So long as they produce something usable, readable, and effective, then we can be happy.
The top two categories are a different breed altogether though. The trailblazer and the visionary. I’ve never been much of a visionary in anything, but I have a great deal of respect for those who really can hold and pursue a brand new vision with all diligence.
I reckon I would be somewhere between workhorse and trailblazer… depending on how good/bad a day I’m having!
I love to make elegant and effective solutions, but sometimes I do need to simply step back and say “it’s just a job!”.
When tabs go bad
Posted by Peter | Filed under Programming, SLOODLE, Websites
I am a Firefox fan-boy… and more than that, a tabbed-browsing junkie. It comes in very handy when working on the Sloodle project, and I’ve got our main site’s forums open in one tab, alongside documentation, a webmail folder (or 5), and a locally hosted Moodle site for testing on.
One thing I’ve learned the hard way recently though is to be really sure of what tab you’re using at what moment. Having tried a few things out in the Sloodle code on my local installation, I wanted to uninstall it from my local Moodle, and re-install it to see if my changes worked properly. Unfortunately, the Moodle tab I had open at the time wasn’t the one on my local machine… but rather, the one on my web-server. I didn’t realise until a fraction of a second too late!
I didn’t lose any seriously important data… this time… but it was quite a nuisance anyway.
I now simply don’t keep more than one Moodle open in the same instance of Firefox at the same time. It’s not worth the risk!

Project[N]ReSource
Posted by Peter | Filed under Programming, Websites
Two fantabulous announcements in one. First of all, Project[N]ReSource has had a face-lift, and our new site is chock to the brim full of features and forums. We’re building a collection of info about our projects, various resources, book reviews, tutorials, links… and more… all relating to computer games and how to make them!
Also in the news is our very first game to be released! Hurrah! “Yokai Valley” is a simple strategy game set in ancient Japan. You have to take charge of a band of villagers, defending the valley from the evil invading Yokai.
Mosey on over to the site to check it out and try out our game and our forums:
http://www.projectnresource.com
;D

