caedes' Notes

2015-04-13

How to integrate your SDL2 window icon (or any image) into your executable

Filed under: Programming,SDL — caedes @ 02:21
Tags: , , , ,

Let’s assume you have an image that you want to use as a window icon in your cross-platform application that uses libSDL2.
A suitable window icon is 64x64pixels big (other sizes should work as well, though) and has 32bit RGBA colors, which means it contains an alpha-channel.

Now it would be handy if the icon could just be part of the executable and if this could be achieved in a platform-independent way.
Furthermore it’d be great if it didn’t require additional dependencies (e.g. to decode image files).

In this tutorial I’ll show how to translate the image into C source file containing a struct that holds the image data + necessary metadata (width, height, color depth) and how to load that struct into a SDL_Surface* and to set that surface as a window icon.
(more…)

Advertisements

Create a free website or blog at WordPress.com.