Skip to content

Repository files navigation

🎨 Computer Graphics Algorithms in C++

A collection of fundamental Computer Graphics algorithms and transformations implemented in C++ using the graphics.h / WinBGIm library.

This repository is useful for Computer Graphics laboratory practicals, academic learning, and understanding basic graphics algorithms.

📂 Project Structure

Computer-Graphics-Algorithms-Cpp/
│
├── .vscode/
│   └── tasks.json
│
├── graphics-library/
│   └── graphics.zip
│
├── 01_Implementation_of_DDA_Algorithm.cpp
├── 02_Implementation_of_Bresenham_Line_Algorithm.cpp
├── 03_Implementation_of_Midpoint_Circle_Algorithm.cpp
├── 04_Implementation_of_Midpoint_Ellipse_Algorithm.cpp
├── 05_2D_Transformations.cpp
├── 06_Composite_2D_Transformations.cpp
│
├── README.md
└── .gitignore

📚 Algorithms Included

🟢 Line Drawing Algorithms

  • Digital Differential Analyzer (DDA) Algorithm
  • Bresenham's Line Drawing Algorithm

🔵 Circle and Ellipse Algorithms

  • Midpoint Circle Generating Algorithm
  • Midpoint Ellipse Generating Algorithm

🟡 Two-Dimensional Transformations

  • Translation
  • Rotation
  • Scaling
  • Reflection
  • Shearing

🟠 Composite Transformations

Multiple transformations are applied sequentially to a 2D object.

Examples:

Translation → Scaling → Rotation

or:

Scaling → Rotation → Shearing

🛠️ Requirements

To run these programs, you need:

  • Windows
  • Visual Studio Code
  • MinGW C++ Compiler
  • C/C++ Extension for VS Code
  • WinBGIm Graphics Library

🔧 Check Your C++ Compiler

Open the VS Code terminal and run:

g++ --version

You should see your GCC compiler information.

You can also check the MinGW installation path:

where.exe g++

Example:

C:\MinGW\bin\g++.exe

📦 Installing the Graphics Library

The repository includes the required graphics library ZIP file.

Download or extract:

graphics-library/graphics.zip

You need these files:

graphics.h
winbgim.h
libbgi.a

Copy the header files:

graphics.h
winbgim.h

to:

C:\MinGW\include

Copy:

libbgi.a

to:

C:\MinGW\lib

After installation, your MinGW folders should contain:

C:\MinGW
│
├── include
│   ├── graphics.h
│   └── winbgim.h
│
└── lib
    └── libbgi.a

▶️ Compile and Run

For programs using graphics.h, use:

g++ "filename.cpp" -o program.exe -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Example:

g++ "04_Implementation_of_mid-point_circle_generating_Algorithm.cpp" -o circle.exe -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Then run:

.\circle.exe

⚡ VS Code Automatic Run Configuration

The .vscode/tasks.json file can be configured to compile graphics programs automatically.

Open your C++ file and use:

Ctrl + Shift + P

Then select:

Tasks: Run Task

Choose:

Run Graphics C++

The task will automatically compile the program with the required WinBGIm libraries.

📝 Example: Midpoint Circle

Example input:

Enter center coordinates (xc yc): 300 250
Enter radius: 100

The program uses the 8-way symmetry property of a circle to generate the complete circle efficiently.

📝 Example: Midpoint Ellipse

Example input:

Enter center coordinates (xc yc): 400 300
Enter X-axis radius (rx): 200
Enter Y-axis radius (ry): 100

The algorithm divides the ellipse into two regions and uses 4-way symmetry.

📝 Example: 2D Transformations

Example polygon input:

Enter number of vertices: 4

Enter x1 y1: 300 300
Enter x2 y2: 400 300
Enter x3 y3: 400 400
Enter x4 y4: 300 400

Translation

Choice: 1
tx ty: 150 100

Rotation

Choice: 2
Angle: 45

Scaling

Choice: 3
sx sy: 1.5 1.5

Shearing

Choice: 5
shx shy: 0.5 0

🚀 How to Clone the Repository

git clone https://github.com/Ronit049/Computer-Graphics-Algorithms-Cpp.git

Open the project:

cd Computer-Graphics-Algorithms-Cpp

📌 Important Notes

  • Install the WinBGIm library before running graphics programs.
  • The programs use graphics.h, which is not included in the standard C++ library.
  • Do not upload compiled .exe files to the repository.
  • Add new Computer Graphics algorithms to this repository as you learn them.

🤝 Contributions

Contributions, improvements, and suggestions are welcome.

If you find this repository useful, consider giving it a ⭐.

👨‍💻 Author

Ronit Raj


If this repository helps you, don't forget to star it!

About

A collection of fundamental Computer Graphics algorithms and transformations implemented in C++ using the graphics.h / WinBGIm library.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages