Computer Graphics

Moderators: Sephiroth
Number of threads: 1263
Number of posts: 2665

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Coding 2D graphics in C, to be portable Posted by phishStix on 28 Jun 2009 at 11:14 AM
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?
Report
Re: Coding 2D graphics in C, to be portable Posted by anthrax11 on 28 Jun 2009 at 4:23 PM
Hi and welcome!

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 :)
Report
Re: Coding 2D graphics in C, to be portable Posted by phishStix on 29 Jun 2009 at 2:50 AM
No, I totally get it, making a library. My only intentions were to be educational; I was never planning on distributing it (or possibly finising it =]). Anyway, I could never even dream of making a library as good as OpenGL, or others. =] Thanks!
Report
Re: Coding 2D graphics in C, to be portable Posted by anthrax11 on 28 Jun 2009 at 4:23 PM
Duplicate post deleted.
Report
Re: Coding 2D graphics in C, to be portable Posted by Malcolm_McLean on 28 Jul 2009 at 8:40 AM
Write all your functions so they take a graphics context as the first argument.

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.
Report
This post has been deleted. Posted by SumitKumar on 25 Nov 2009 at 11:22 PM
This post has been deleted.



 

Recent Jobs