Computer Graphics Course Notes

First Section: Basics of Drawing in C++

  • When programming, you need to call the standard library. This is done by including the header file. For graphics, you need graphics.h.

  • The screen is typically a DOS screen. However, for drawing, you need to set the graphics mode.

    • This is done using the initgraph() function.

initgraph() function
  • Used to initialize the graphics system.

  • Prototype: void initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);

    • graphdriver: pointer to the graphics driver.

    • graphmode: pointer to the graphics mode.

    • pathtodriver: path to the BGI files.

  • Must be called before any other graphics function.

detectgraph() function
  • Detects the graphics adapter and sets the graphics mode.

  • Prototype: void detectgraph(int far *graphdriver, int far *graphmode);

  • Example:

    • c++ detectgraph(&grd,&grm);

getgraphmode() function
  • Gets the current graphics mode.

  • Prototype: int getgraphmode(void);

  • Example:

    • ```c++
      int gm;
      gm = getgraphmode();
      printf(