Mercurial > public > algo-animator
comparison README.md @ 21:8a5a7aee69ce
add description
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 27 Jun 2023 20:04:25 +0100 |
parents | 074bde2db09a |
children | bebd95177e96 |
comparison
equal
deleted
inserted
replaced
20:fc44102980fb | 21:8a5a7aee69ce |
---|---|
1 # algo-animator | 1 # algo-animator |
2 | 2 |
3 ## Compile and run | 3 This project is inspired by - off course - the video by Timo Bingmann called [15 sorting algorithms in 6 minutes](https://www.youtube.com/watch?v=kPRA0W1kECg). |
4 | |
5 ## Compile | |
6 | |
4 ```bash | 7 ```bash |
5 gcc main.c -lglut -lGL -lGLU -lm -I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype | 8 gcc main.c -lglut -lGL -lGLU -lm -I/usr/local/include/freetype2 -L/usr/local/lib -lfreetype |
6 ./a.out | |
7 ``` | 9 ``` |
10 | |
11 ## To improve | |
12 | |
13 Since `GLUT` is single-thread, I cannot call `glutPostRedisplay()` within `while` or `for loops` to redraw the screen in every | |
14 step of the selected sorting algorithm. I guess the solution is multi-threading, so I can perform the sorting in the second thread | |
15 and post notifications to the main thread to redraw the screen. | |
16 | |
17 Since this is my first OpenGL project and just my second program in C, I am tired and I don't want to spend more time in this project, | |
18 but maybe in the future I'll do it. Right now there are just two algorithms supported. I've implemented them in a way that every function | |
19 call is a single step of the sorting. So, storing the "state" outside the function, I can use `idle()` as the loop of the sorting algorithm. | |
20 | |
21 Let's say we selected `bubble sort`. Once you press `ENTER`, the process will be like this: | |
22 | |
23 ```c | |
24 run = true; | |
25 bubble_sort(); | |
26 glutPostRedisplay; | |
27 bubble_sort(); | |
28 glutPostRedisplay; | |
29 bubble_sort(); | |
30 glutPostRedisplay; | |
31 | |
32 // Continue until the array is sorted | |
33 run = false; | |
34 ``` |