libgraph --- Implementing Turbo C's graphics on GNU/Linux

<<Previous Next>>
List of Functions Bugs & Caveats


 Developer Section

If you are a developer wanting to contribute readon...



  • Files in Distribution:
  • In this package are :

    graphics.h : the default header that includes all the others required so that you don't have to do anything differently.

    libgraph.c : the code for functions in graphics.h. These are mainly the basic settings and initialization functions.

    grtext.h : the functions for text manipulation -- This basic part of this code has been borrowed from Karl Bartel's SFont library. We extended it to fit our needs.

    text.c : code for functions in grtext.h

    shapes.h : functions for drawing various shapes, filling and positioning.

    shapes.c : Code for the above definitions.

    polygon.h : functions for drawing and filling polygons.

    polygon.c : Code for above functions. These two functions were made into a separate module because the code for fillpoly() is pretty healthy all by itself and requires quite a few book-keeping non-trivial functions.

    Makefile : We don't know how to write Makefiles. This one has been hacked up from someone else software. If u know more than us on the subject please oblige by writing a custom Makefile for the package.

    README : That's what you are reading.

    grc : a no-brainer script to compile libgraph programs.

    ./Font : Directory containing font(.png) files. There are a number of different colors but of the same font. Default font is white. Font-color selection is still to be implemented. You can change the color by changing the FONT definition in graphics.h to a different color file and recompiling the library.

    sample.c : small sample file to try out the library. Just compile with $ ./grc sample and execute with $ ./sample


  • What you need to know....
  • I would suggest that you familiarize yourself with the basic SDL functions before scratching around. All the SDL functions are documented in man-pages. For a good intro, html documentation and samples refer the homepage at www.libsdl.org


  • Reqarding text functions...
  • The basic code for text functions has been borrowed from Karl Bartel's SFont library ( We can't seem to stress that point enough ). We actually don't understand much of the basic initialization. We just modified his output function to emulate terminal behaviour (eg. scrolling of text onto newline).

    The input functions although written from scratch also borrow heavily from Karl's code. Our code is not neatly organized or efficiently written. There are parts which we think are unnecessary but are afraid to remove lest we break something. The main challenge in this code ( and one that has not yet been met with ) is to emulate terminal behaviour by redirecting standard I/O functions to use the graphical screen.

    The reason for stressing this is that we often see/use code like

    initgraph( , , );
    ....
    printf("Hello",,);
    ...
    closegraph();

    Now this may seem normal in DOS but in SDL the drawing is done on a separate SDL_Surface structure while all I/O functions operate on stdin/stdout. Hence we check wether we are in graphics mode by setting and querying an environment variable --- "LIBGRAPHICS_ACTIVE=1". Correspondingly we use either our native functions or call variadic printf/scanf functions. You might want to look up the variadic call conventions in "$info libc".

  • To try new functions..
  • If you have implemented a function which has not yet been included, I suggest that you write it in a separate header or program and test. This way you can tweak it without recompiling the library. Once you are sure of it's correctness mail it to me and it will be added to the main source (with attribution).


  • Libtool :
  • If you read the Makefile you will find that libtool has been used to link the library. This is because libgraph itself links to a number of libraries and we do not want to specify each one at compile time. To see how many dynamic libraries actually get involved type

    $ldd <yourexecutable>

    To find more about libtool "$info libtool".


    <<Previous <Home> Next>>
    List of Functions Top Bugs & Caveats