Posted by Chris Sun, November 16, 2008 18:24:36
I have spent a few wasted hours dabbling with this library and that library. I have drawn lines for myself, including anti-aliased lines, but not using very efficient code. I have looked at various algorithms but there are drawbacks in them all.
Feeling a bit gloomy about this and having tried and given up on all sorts of ideas I have kicked my heels for a couple of weeks, then I tripped over a message about libgd. I looked it up and it seems like my search for a graphics library is at an end.
I compiled the demo program which worked well so now I'm going to put my grea on hold and try using libgd in earnest. It has multi thickness lines, polygons, area fills font handling using freetype (including angled fonts), with anti-aliased It can save as png files. The one area that I have noticed seems to be missing is bezier curves - but i know to draw them so I could be onto a winner here.
Posted by Chris Sat, October 18, 2008 22:14:20
I've now added some font handling to my grea (graphics area). I used FreeType2 font routines. There was lots of information and a fairly good tutorial as part of the freetype-2.3.7 library download. I made the mistake of trying to follow the code in the source for the pngwriter library, which is a bit muddled (even though it works). When I worked through the tutorial and actually understood what I was doing it worked well.
I have not allowed for UTF8 encoding which is important for OpenStreetMap to render text in any language, so I'll look at that later. The routine copes with text rotation well. I've used the built-in antialias function of FreeType2 and merged it with my simple colour handling to produce good-looking text. I could yet make it look better by using kerning - another thing to look at. I need to write a routine to return the length (in pixels) of a piece of text so I can centre text and decide how to position it.
This has all taken a bit longer than I wanted, but I've learned a lot and I've rebuilt the grea class to make it much more robust. Now I've broken the back of text handling I will have a look at antialiased drawing of lines with a width setting - just to get a break from fonts. If that goes well I'll move on to a filled polygon.
Posted by Chris Fri, October 10, 2008 22:28:31
So I've taken a look at libpng. The first thing that jumped out at me was the dodgy error handling. It uses a long jump routine to trap errors, which doesn't really give many options. The good news is that the library seems very stable, so errors are rare.
I found a c++ wrapper called png++, but it is simply a header stuffed with templates. It seems to work, but it makes each compile take a long time and most of the stuff is not needed. So I've put a simple class wrapper around libpng and it seems to work. This creates an object type grea - short for graphics area. This where the graphics get drawn.
I've also taken a brief look at fonts, especially freetype. It looks quite manageable so I think I'll look at this next. The libfreetype documentation demonstrates the process of turning characters from a font file into a bitmap to be used on my grea. This includes using a matrix to transform the character. This is great because it will allow a rotation which is needed to draw a name along a road at any angle. I will need to draw each character separately because each one may be at its own angle. This is just how libfreetype seems to work.
If I can get fonts to work, then there's the issue of anti-aliasing and then bezier curves then icons, then line thickness and casings then ...
Posted by Chris Thu, October 02, 2008 21:30:29
I've now just bitten off much more than I think I chew. The tiles that make up a map are .png files. If I'm going to create a tile, I need to draw a .png file. I searched t'interweb and came up with libpng. It seems to be the definitive way to read and write png files, but it is pretty long-winded. I dug about a bit more and found pngwriter. This library seems much easier (I wrote a .png file with an image on it in a few minutes), but when I looked at the documentation a bit more there's some stuff missing - line thickness, dotted lines etc.
It looks like I might have to get into libpng and it might take a while ...
Posted by Chris Thu, October 02, 2008 21:12:56
So one useful idea is that for any given tile, what is the long & lat of the edges of the tile. I was working on this when I tripped over the code on the OSM wiki, in any (code) language you want, so I copied it into a simple class and it worked well.
Posted by Chris Thu, September 25, 2008 22:18:12
I decided that I'd make some of my examples available as a download. It may be interesting for someone, and it makes a backup for me. I've just cobbled together a flat html site to display pull this together, but I will need to replace it with something a bit more manageable.
I've moved my domain to ONE.COM who host a site with 3gb, a MySQl db and unlimited email accounts for very little money - I guess you found it because you're reading this blog, but the URI is www.cjhill.co.uk
. I think I'll create a little database and PHP app to display the list of files to download, but not just yet.
Posted by Chris Thu, September 25, 2008 12:32:13
I've been working on some code on and off for a few of weeks, but not with a blog to match. Rather than go through the whole stuff to date, I'll fill in the gaps as need be.
My background did not include Linux, but Open Street Map (OSM) is Linux orientated and especially open-source software. On a PC I would turn to Delphi or C# on Dot Net to create a program and I have experimented with such code, but it is largely spurned by the OSM community. Much of the coding for client PCs is in Perl - it works across different platforms but it doesn't float my boat. So I set out to reacquaint myself with C++.
I have a machine with Ubuntu 8.04 on it. I'm still learning more about Ubuntu, and I'm steadily becoming more confident and content with it. I installed g++ and created a few examples to get going again. It feels a bit clunky using a command line and it feels really hard work without code completion in an IDE, but I decided that I wanted to work from the ground up to be sure I understand.
OSM data is accessed from the server by HTTP and arrives as XML. The standard c++ libraries don't cover this, so I looked around for how other people do it. The Poco libraries stood out as covering a wide range of useful additional libraries. They are open-source so people should be fairly happy.
I have used the Poco XML SAX library to extract the OSM data into custom, simple objects. I'm fairly happy with this, it runs very quickly, the memory management is simple, but the documentation took me a few hours of head scratching to understand how to use the classes. I'm still not sure that I have used SAX the way it is intended. I used the Poco HTTP classes to access data from the API server and it worked first time.
Now I want to do some tile handling ...