Mercurial > public > algo-animator
comparison main.c @ 4:035d3880da04
render text with number of elements on screen
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Mon, 12 Jun 2023 23:10:08 +0100 |
parents | e4003f606e07 |
children | 6be2faa7ed6e |
comparison
equal
deleted
inserted
replaced
3:e4003f606e07 | 4:035d3880da04 |
---|---|
1 #include <stdio.h> | 1 #include "utils.h" |
2 #include <GL/glut.h> | |
3 | 2 |
4 | 3 |
5 #define HEIGHT 1080 | 4 #define HEIGHT 1080 |
6 #define WIDTH 1920 | 5 #define WIDTH 1920 |
7 | 6 |
25 | 24 |
26 | 25 |
27 void display() { | 26 void display() { |
28 glClear(GL_COLOR_BUFFER_BIT); | 27 glClear(GL_COLOR_BUFFER_BIT); |
29 glBegin(GL_QUADS); | 28 glBegin(GL_QUADS); |
30 /* | |
31 glVertex2f(100.0, 100.0); // Top left | |
32 glVertex2f(150.0, 100.0); // Top right | |
33 glVertex2f(150.0, 300.0); // Bottom right | |
34 glVertex2f(100.0, 300.0); // Bottom left | |
35 | 29 |
36 glVertex2f(160.0, 100.0); | 30 float x = 1; |
37 glVertex2f(210.0, 100.0); | 31 float rect_width = 5.0; |
38 glVertex2f(210.0, 300.0); | 32 float space = 5.0; |
39 glVertex2d(160.0, 300.0); | 33 int max_rects = floor((WIDTH - rect_width) / (rect_width + space)) + x; |
40 */ | |
41 | 34 |
42 float rect_width = 5.0; | 35 int rect_counter = 0; |
43 float space = 10.0; | 36 while (rect_counter < max_rects) { |
37 glVertex2f(x, 100.0); | |
38 glVertex2f(x + rect_width, 100.0); | |
39 glVertex2f(x + rect_width, HEIGHT - 300); | |
40 glVertex2d(x, HEIGHT - 300); | |
44 | 41 |
45 for (float pos_x = 100.0; pos_x < 500.0; pos_x += 10.0) { | 42 x += rect_width + space; |
46 glVertex2f(pos_x, 100.0); | 43 rect_counter++; |
47 glVertex2f(pos_x + rect_width, 100.0); | |
48 glVertex2f(pos_x + rect_width, 300.0); | |
49 glVertex2d(pos_x, 300.0); | |
50 } | 44 } |
51 | 45 |
52 glEnd(); | 46 glEnd(); |
47 | |
48 char text[256]; | |
49 sprintf(text, "Number of elements: %i", rect_counter); | |
50 render_text(text, 20.0, HEIGHT - 200); | |
53 glFlush(); | 51 glFlush(); |
54 } | 52 } |
55 | 53 |
56 | 54 |
57 int main(int argc, char** argv) { | 55 int main(int argc, char** argv) { |