This project demonstrates the implementation of three fundamental line drawing algorithms in 2D space using SDL:
- Bresenham Line Algorithm
- Midpoint Line Algorithm
- Parametric Line Algorithm
The project consists of two main files:
Algo.cpp
: Contains themain
function which sets up the SDL environment and handles rendering and input.Header.h
: Contains all the function implementations for line drawing, pixel drawing, clearing the back buffer, and handling input.
The program initializes SDL, creates a window and a renderer, and sets up the initial screen.
The ClearBackBuffer
function clears the screen to a specified color.
The DrawPixel
function draws a single pixel at a given position with a specified color.
The DrawMarker
function draws a square marker of a specified size and color at a given position.
The project implements three line drawing algorithms:
- Bresenham Line Algorithm: Efficiently draws lines using integer calculations.
- Midpoint Line Algorithm: Draws lines by determining the midpoint between two points.
- Parametric Line Algorithm: Draws lines using parametric equations.
When key 1, 2, or 3 are pressed, the program draws a random line of a specified color (red, green, or blue/purple) on the screen and marks the start and end points with yellow pixels.
When key 4 is pressed, all lines are cleared, and the screen is filled with randomly placed white pixels, simulating a sky full of stars.
video.mp4
The HandleInput
function captures keyboard input to draw lines or clear the screen based on the user's key presses.
To set up the SDL library in Visual Studio, follow the instructions provided in this YouTube tutorial.
- Clone this repository.
- Set up SDL in your development environment.
- Compile and run
Algo.cpp
.
- M.Tashfeen Abbasi
- Laiba Mazhar
For any questions or suggestions, feel free to contact at [[email protected]]
Enjoy experimenting with 2D line drawing algorithms!