Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site

Entries by Rob (3094)

Tuesday
Dec092008

You Can't Beat a bit of Rehearsal

Went to Doncaster today. The University of Hull validates a couple of their degree programs (Integrated Technology and Business Computing and so I had a couple of meetings to attend, followed by a presentation to their students. The meetings went well and then I had to do my talks about the University and what we do, with particular reference to projects. They were a great audience, and asked loads of sensible questions. I wish I'd taken the trouble to read through my slides before I started the talk, I'd used them before but kept having déjà-vu moments, where I put up a slide all about something I'd just said. Oh well, next time I'll give them a read through first.

Thanks for making us so welcome folks, and I'm looking forward to seeing the projects next year.

Monday
Dec082008

Programming Pop Quiz

These two snippets of code are supposed to advance a pointer along a buffer until they find a double quote character or reach the end of the buffer.

while (input[startPos] != '"' && startPos < input.Length) startPos++;

or

while (startPos < input.Length && input[startPos] != '"') startPos++;

One of them works fine. One throws an exception sometimes. Why?

Sunday
Dec072008

Lousy Software

I hate bad software. It gives us all a bad name. I particularly dislike it when the program makes a job that could be simple a lot more difficult, whilst at the same time trying to seem friendly.

Yesterday I got a couple of photo album and paper things from HP. The idea was that I would print out some pictures and make some nice personalised gifts. I was further encouraged in this when I found that the package came with some HP Photosmart software that would arrange the pictures for me and put them into some nice looking templates.

That was the plan. I had this simple minded idea that I would pick pages from a template, drop pictures into them from my hard disk and then print out what I wanted.

Not so. First off the program insisted in cataloguing all my pictures. And I have rather a lot so that took a while. In fact, it got so slow that in the end I made up some directories holding a subset of my photos and turned it lose on that. Next it forced me to select from a slow moving and hard to use menu which pictures I wanted in my album. It then stuffed these into the album pages in no particular order, forcing me to move them all into the right place. I had no way of choosing the order of the pages, or deleting excess ones. But of course it saved the best bit until last.

Just as I was finishing off my design I noticed a "settings" option in the top right hand corner. Thinking that this might let me re-arrange pages or delete them I clicked it. It had some fairly useless options that were no good for what I wanted, so I tried to get back to my design. Which had vanished. All my work had gone away, without so much as a warning. Wah.

Sometimes there is great satisfaction to be had watching the uninstaller do it's business.

Saturday
Dec062008

Zombie Fragfest

3092716409

One of these people is a zombie....

Dropped in on the Hull Com. Soc. Frag Fest today. I was in a bit of a hurry, so I didn't take my machine with me. After I saw what they were playing I rather wished I had though. It was a hilarious mod for Half-Life 2, which pits survivors against a zombie horde which increases steadily as each human player falls prey to the creeping death. I had a quick go and, needless to say, I got zombified really early on each time, but it was still great fun. I took the camera with the toy lens (of which more later) and got some nice pictures.

3093552260

Nobody who is anybody has a machine with the lid still on......

Friday
Dec052008

Converting Windows Bitmaps to XNA

If you have ever wondered how to convert Windows Bitmaps into XNA textures then wonder no more. This method will do it for you. It is not particularly elegant (or fast) but it will let you take images off your PC (or the web) and put them into textures for use in XNA programs. Note that this will only work on XNA programs that are running on a Windows PC, the Xbox is not allowed to do this kind of thing at all. You need to add a reference to System.Drawing to your project and use the System.Drawing namespace.

Some of the code is a bit messy because of namespace clashes, and I'm sure there is a neater way of doing this. But it does work.

private Texture2D XNATextureFromBitmap(
              
System.Drawing.Bitmap b, GraphicsDevice device)
{
    Texture2D xnaTexture =
               new Texture2D(device, b.Width, b.Height);

    Microsoft.Xna.Framework.Graphics.Color[] dots =
         new Microsoft.Xna.Framework.Graphics.Color
                                           [b.Width * b.Height];

    int x;
    int y;
    int pos = 0;

    for (y = 0; y < b.Height; y++)
    {
        for (x = 0; x < b.Width; x++)
        {
            System.Drawing.Color sourceColor = b.GetPixel(x, y);
            dots[pos].A = 0xff;
            dots[pos].R = sourceColor.R;
            dots[pos].G = sourceColor.G;
            dots[pos].B = sourceColor.B;
            pos++;
        }
    }

    xnaTexture.
           SetData<Microsoft.Xna.Framework.Graphics.Color>(dots);

    return xnaTexture;
}