Writing a Library

Hello,

I was just wondering what programmers do when the write a library. For example, how did programmers write openGL , and how hard is it to write a custom library?

Thanks for any help,

Muhasaresa
OpenGL isn't a library, it's a specification. However, there are libraries such as Mesa 3D that implement OpenGL.

and how hard is it to write a custom library?

That depends on what kind of library you're writing. It ranges from so easy that a rock could write it (a library with no functionality) to impossible (e.g. a library that destroys the universe).
A library is just a collection of reusable functions and datatypes - you don't have to do anything special to write one.

How "hard" this is depends entirely on what exactly you want to do.
So if i wanted to write a very simple 2d graphics library that can draw a white square, how can that be done. Would I have to say which pixels go white?
If you were to write a graphics library that would really not be anything simple. Not even close to simple. A simple example would be a library that provides a few functions for analytic geometry, like classes for vectors and matrices and stuff.

Writing a library is no different from any other programming, so basically ask yourself "can I do this?" - and then you know whether you can write a library for it or not.
Last edited on
Thanks! That clears it up a bit, but now the only thing I don't know is how does the computer know it's graphical or not?
Last edited on
A 2D library isn't particularly hard, as there's no complex logic or math involved. You just need to make sure all pixels end up where they belong. A 3D library is another matter, though.
Either way, in the end your library will have to use functions provided by your OS to draw something on the screen.

Thanks! That clears it up a bit, but now the only thing I don't know is how does the computer know it's graphical or not?

It doesn't know and doesn't care.
So what exactly do you mean?
use functions provided by your OS to draw something on the screen.


Thanks :D

I think that was what I meant when I asked if the computer knows what it's meant to do.

Kind Regards,

Muhasaresa
Last edited on
Writing a 2D graphics library would require some sort of hardware communication to get things done with reasonable speed. You could greatly simplify this by building on top of something else, like OpenGL or D3D, but as the question was referring to how THESE are written I certainly wouldn't say it is "simple".
This is kind of a loaded question that would need more than a post to answer I think.
Thanks everyone for your help :D

Muhasaresa
Topic archived. No new replies allowed.