Next Previous Contents

5. LibGGI initialization example

A primitive tutorial on how to start using LibGGI, since many people seem to have trouble with this. For more practical usage, please see demo.c.


#include <ggi/libggi.h>

int main(void)
{
        ggi_visual_t vis;
        ggi_mode mode;
        int err;

        /* first initialize LibGGI */
        ggiInit();

        /* Get the default visual to work on */
        vis = ggiOpen(NULL);

        /* You can also do some drawing to memory, like this: 
           (don't forget the ending NULL!)

        vis = ggiOpen("display-memory", NULL);
        */

        if(vis==NULL) {
                fprintf(stderr, "No visual!\n");
                exit(1);
        }

#ifdef AUTO_SELECT_MODE
        /* This automatically selects the default mode */
        err = ggiSetGraphMode(vis, GGI_AUTO, GGI_AUTO, GGI_AUTO, GGI_AUTO);

#else
        /* OR you can select your own */

        /* Check for mode: 320x200x8 320x200.
           After this call, mode will now have our mode,
           OR the suggested mode if our mode cannot be satisfied.
        */
        ggiCheckGraphMode(vis, 320, 200, 320, 200, GT_8BIT,
                &mode, NULL);

        /* Now set the mode */
        err = ggiSetMode(vis, &mode);
#endif

        if(err) {
                fprintf(stderr, "Cannot set mode!\n");
                exit(2);
        }

        /* do some stuff */

        ggiClose(vis);

        ggiExit();

        return 0;
}


Next Previous Contents