Hello all,
Well, this is my first post in Programmer's Heaven.
Recently, I began developing my own programming library, written in C. When I got to the graphics, I became stumped, because I want the library to be portable, on both OS, and hardware. Every way I think of creating graphics, a different architecture or software platform is excluded. For example, if I used the Windows API, only windows, or possibly Wine can run it; if I use assembler, only one architecture can run it, and I REALLY don't want to re-write the assembly routines for multiple architectures (don't think I could do it for many at all =]...). Any ideas?
Comments
I'm not exactly sure what you might need, but you're probably looking for something like SDL or OpenGL:
http://www.libsdl.org/
http://en.wikipedia.org/wiki/OpenGL
I wonder why you would want to make your own library for this. It's great for learning, but not very practical when other libraries already exist that do a great job at it. I also don't think it's sensible to make a library that does everything (at least not all by yourself). That would be reinventing the wheel. Not to discourage or anything, just wondering
The graphics context should contain the members
int width;
int height;
long (*getpixel)(int x, int y, void *ptr);
void (*putpixel)(int x, int y, long color, void *ptr);
void *ptr;
width and height are self-explantory. getpixel and putpixel anre fuunction pointers which read and write single pixels to the screen. ptr is a general-purpose hook so the functions don't have to rely on global data.
These days you can pretty much guarantee truecolour graphics. However you'll have to add extra members if you wish to support paletted images nicely.
Using this abstraction layer, all your algorithms can work perfectly portably.