I’ve been messing around with that evolution simulation code. There’s a few things in the code that I don’t yet understand but that’s common when trying to understand the inner workings of code you didn’t write. For instance, some values related to behavior rules are initialized using random values based on statistics information. Statistics is one things that I understand in simple terms but don’t understand in more complex and code-related terms.

What is a standard deviation?

What I wanted to write about is my experimentation with Windows GDI+, GDI, and the GLUT library. First, GDI+ has a problem rendering text on my system. Maybe a restart will fix it but right now, it won’t render text to a bitmap. Lines and circles work fine but text no longer appears. I fought with this yesterday for at least an hour because I thought it was a mistake in my code. Once I reverted to code that had worked an hour earlier, I found that text was still missing. On the other hand, GDI+ does anti-alias lines and circles.

GDI+ text rendering, when it did work, was a bit odd. I could create a GDI+ font using only GDI+ font function calls and the font would render normally and not anti-aliased. Then I turned on anti-aliasing and it rendered badly. What the hell did Microsoft do? It is as if the text is rendered .5 pixels off from where I want it and it’s fairly ugly because of the anti-aliasing. On the other hand, I could create the font using a LOGFONT structure, which also needs to be accompanied by a device context for some odd reason, and the anti-aliasing option in that LOGFONT structure works as expected. It makes the font look good. It makes it look good as long as the GDI+ anti-aliasing is turned off while the text renders.

So no GDI+. I didn’t want to waste time on something that was unpredictable and also on something that started to fail without any indication of why it failed. Sure, I may have failed to free some resource but everything else in the system seems fine.

The existing simulation code uses GLUT or Glut. It’s an openGL library or is somehow related to openGL and is cross-platform. That’s a good thing as long as you don’t want the program to look quite right on some platforms. It doesn’t support any controls and is just for rendering and works great with this program. It’s not all that great if scroll bars, buttons, etc…, are needed in the window.

Since Glut isn’t native to Windows and makes it hard to add a dialog box or code of that sort, I tried experimenting with GDI. Circles in GDI are ugly. The circle algorithm makes them a bit square at certain sizes. The circles in Glut looked better but I didn’t think to do a direct comparison by the time I got to GDI. I can draw about 450 simulation creatures on a bitmap and then blt that to the window at 30 to 60 frames per second, depending on the graphics subsystem in use.

In the end, I’m just going to rewrite all of the code to suite my style and windowing needs. I can then make things more object oriented and also make most of the program constants into variables that can be tuned at run time. The reproduction rate, how much food is eaten by herbivores, etc…, all need to be easily modified so that the simulation can be tuned to produce interesting results. Note that this is not an experiment since the code is tuned to get the desired results. It is more of an evolution simulation toy.

Then I’ll add physical evolution instead of behavior evolution. Why not allow a create to be faster at the expense of a shorter life or at the expense of having no sense of smell?