I’m interested in the interaction of PNG and SDL.
What I desire, is an architecture like Quake’s, where the engine has
control over many things, and the driver merely provides a portable
"hardware" environment to program to.
However, I wish to raise the level of that driver API just a bit.
Instead of providing a framebuffer, I wish to provide generics graphics
primitives (drawLine, fillRectangle, etc.) as inspired by X Windows.
Specifically, I’d like to provide a sort of XPutImage, but I obviously
can’t use the XImage structure in a generic driver.
So, I’d like to use PNG. I figure PNG is portable, and so can be the
graphics format of my engine. By using libpng, I can freely promote the
image structure to the level of engine, and require that the driver know
how to deal with PNG images. This lets me avoid moving all the image
handling code into the driver, and using void* all through the engine.
Therefore, I might have a putImage function that takes a PNG structure.
An SDL driver would have to handle this PNG image and correctly draw it
to an SDL surface.
Now, I see that SDL_image handles conversion to and from PNG. But my
question is a little more subtle. Obviously, I can’t convert a PNG image
to an SDL surface during each call to putImage. How do I ensure that
everything is fast, within the constraints I have set?
Well, the most unobtrustive method is simply to have the SDL driver
convert a PNG image the first time it is put. Then, it is cached, so
subsequent calls skip the conversion. However unobtrusive this is, it
wastes space, storing each image and its converted representation, even
if it may never be drawn again.
I could make the engine convert the loaded PNG to the proper bit depth
etc. This might make the conversion less painful, but it still has to
occur. Is this going to be too much overhead to do during each putImage
I hope I’m being clear. Basically, I’d like to load PNG images using
libpng directly in the engine, and have the driver (SDL or otherwise)
provide a putImage(png_structp, src_x, src_y, dest_x, dest_y, width,
height) function that draws the image onto the “global” screen surface.
What is the best way of approaching this?–
Minion open source game, RTS game programming, etc.