[linux-graphics-dev] C++, XLib and PNG

David Olofson david at olofson.net
Sun Mar 20 16:17:27 EST 2005


On Sunday 20 March 2005 21.42, jody wrote:
> Hi
> I need to write a C++-program with which i can manipulate and
> display 
> PNG images.
> I mastered the parts of libpng that i need to load an image, and
> access its pixel data.
> 
> Now about displaying it... i need some help here.
> Has anyone got a simple sample Xlib prog which shows how
> to fill a window with RGB pixels?

IIRC, the closest I've been to direct Xlib coding was when I studied 
the XKobo code before porting it to...


> Or would it be advisable not to use xlib directly,
> but some other libary?

...SDL!

 http://libsdl.org

Probably the easiest and most portable way of dealing with graphics 
and sound.

Well, if you're familiar with some GUI toolkit, it *might* be easier 
to use some widget that can load and show an image, but then you lose 
some portability (AFAIK, no single GUI toolkit runs on anywhere near 
as many platforms as SDL), fullscreen modes and stuff... Depends on 
what kind of application you're working on, though. If you're already 
using GTK+, FLTK or something, you should probably research the 
widgets a bit first.

As to SDL, the add-on library SDL_image can load PNGs (and a bunch of 
other formats) directly into a SDL surfaces, so you don't have to 
mess directly with pixel data at all. Alpha channels are supported 
for the formats that can have them. (Now that you've already figured 
that bit out and all... ;-)


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---


More information about the linux-graphics-dev mailing list