This blog is under construction

Saturday, 14 September 2013

setgraphbufsize example in c

Header file:

      unsigned setgraphbufsize(unsigned bufsize);
     setgraphbufsize() returns size of the previous buffer and set the given size for the internal graphic buffer.

setgraphbufsize function in c graphics

  #include <graphics.h>
  #include <stdlib.h>
  #include <stdio.h>
  #include <conio.h>

  #define BUFSZ 1024 /* internal graphics buffer size */

  int main(void) {
        /* request auto detection */
        int graphicDriver = DETECT, graphicMode;
        int err, midx, midy, prevsz;
        char str[64];

        /* setting the size of the interal graphic buffer */
        prevsz = setgraphbufsize(BUFSZ);

        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,

        /* read result of initialization */
        err = graphresult();

        if (err != grOk) {
                /* an error occurred */
                printf("Graphic Error: %s\n", grapherrormsg(err));
                return 0;

        /* mid position in x and y axis */
        midx = getmaxx() / 2;
        midy = getmaxy() / 2;

        /* output some messages */
        sprintf(str, "Current Graphics Buffer Size: %d", BUFSZ);
        settextjustify(CENTER_TEXT, CENTER_TEXT);
        outtextxy(midx, midy, str);

        sprintf(str, "Previous Graphics Buffer Size: %d", prevsz);
        outtextxy(midx, midy+textheight("H"), str);

        /* clean up */
        return 0;

Output: (setgraphbufsize built-in function in c graphics.h)

No comments:

Post a Comment