This blog is under construction

Saturday 14 September 2013

setrgbpalette example in c

Header file:
    graphics.h

Synopsis:
      void setrgbpalette(int colornum, int red, int green, int blue);
     
Description:
     setrgbpalette() defines color for IBM-8514 graphics card.  Here, colornum is the palette entry to be loaded, while red, green and blue indicates the component color of the palette entry.


setrgbpalette function in c graphics



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

  int main(void) {
        /* set the driver and graphic mode */
        int graphicDriver = VGA, graphicMode = VGAHI;
        int err, i, x1, x2;
        struct palettetype palette;

        /* initialize graphics and local variables */
        initgraph(&graphicDriver, &graphicMode,
                                "C:/TURBOC3/BGI");

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

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

        /* grab a copy of the palette */
        getpalette(&palette);

        /* create gray scale */
        for (i=0; i<palette.size; i++)
                setrgbpalette(palette.colors[i], i*2, i*2, i*2);

        /* display the gray scale */
        x1 = 0, x2 = getmaxx() / 16;

        /* draws vertical bars with given fill styles */
        for (i=0; i<palette.size; i++) {
                setfillstyle(i % 12, i);
                bar(x1, 0, x2, getmaxy());
                x1 = x2;
                x2 = x2 + getmaxx() / 16;
                delay(400);
        }

        /* clean up */
        getch();
        closegraph();
        return 0;
  }





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


No comments:

Post a Comment