Home Docs
Graphics.h Documentation
Compiler

Getting Started

Hello Graphics Program

This page demonstrates a simple graphics.h program that initializes graphics mode, draws a shape, and waits for user input before closing. It is the graphical equivalent of a “Hello, World” program.

On This Page

Complete Example Program

Run This Program (DOS Output)

Open Full Compiler

DOS Output

Press "Run In DOS" to start the embedded Turbo C environment.

Step-by-Step Explanation

  1. 1. Include Headers

    #include <graphics.h> provides graphics functions and #include <conio.h> gives keyboard utilities like getch().

  2. 2. Declare Driver and Mode

    int gd = DETECT, gm; sets up graphics driver and mode variables. DETECT enables auto-detection.

  3. 3. Initialize Graphics

    initgraph(&gd, &gm, ""); switches to graphics mode, loads the driver, and prepares the screen for drawing.

  4. 4. Draw Shape

    circle(200, 200, 100); draws a circle centered at (200, 200) with radius 100.

  5. 5. Wait for Input

    getch(); keeps output visible until the user presses a key.

  6. 6. Close Graphics

    closegraph(); returns to text mode and releases graphics resources.

Coordinate system reminder: origin is top-left; X increases right, Y increases downward.

How to Run This Program

You can run this example using:

Before drawing, make sure graphics mode initializes successfully.

Related setup guide: Where to Run graphics.h.

What You Should See

  1. The screen switches to graphics mode.
  2. A circle appears near the center.
  3. The program waits for a key press.
  4. After key press, the program exits.

Common Beginner Mistakes

  • Forgetting to call initgraph().
  • Forgetting to call closegraph().
  • Not including graphics.h.
  • Incorrect BGI path in older Turbo C setups.
  • Using graphics.h in compilers that do not support it.

Next recommended topic: line() drawing function.

FAQ

Why is this called the graphics “Hello, World”?

It is the smallest meaningful graphics.h program: initialize graphics, draw one shape, wait, then close.

Can I run this with normal GCC without extra setup?

Not directly. graphics.h is not part of standard C toolchains and needs compatible environments.