Friday, February 23, 2007

Adding an Icon to your SDL application

One of the most frustrating things for me about creating games using SDL and JEDI-SDL is that they do not behave like standard Delphi windowed applications. While they are actual Windows applications, they are just not VCL applications. The window that SDL creates is a fully fledged Windows window, only a lot of it's internals/messages are hidden inside SDL's framework. This of course means that they are smaller in size than most Delphi application, but also they are developed in a non visual way and do not have icons to represent them.

Now users of programs always use the icon to recognise a program and if it just shows a blank white icon they need to actually read the text (when last did you read the description of any of the icons on your desktop?). So in a way this has become a big problem - especially as my biggest fans are my kids aged 4,7 and 9 - the smaller two just dont read english the way I do (They go to an Afrikaans school).

Now it is possible to set an icon to be displayed in the Task bar using:
Pascal Code:

SDL_WM_SetIcon( SDL_LoadBMP( 'Icon.bmp'),0);

And this should probably be done for all your applications as a matter of course, but this does not help a child find the game on the windows desktop as the icon is only set when the game is actually being run.

But it is possible to add an icon to your final distributable.

Using the delphi Image Editor create a new .res file. (A .res file is a resource file that can contain bitmaps, strings and icons). Add a new icon to the resource file. Name the icon the same as the executable to make it easier to remember. Draw a nice pretty piture for your icon. Save the .res file to the same directory as your project file.

In side the delphi project file add the following line
Pascal Code:

{$R .res}


And recompile your program. Suddenly your program will have an icon linked to it.

http://www.pascalgamedevelopment.com/viewarticle.php?a=58&p=1#article