Mercurial > public > algo-animator
comparison main.c @ 3:e4003f606e07
draw multiple rectangles with loop
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Mon, 12 Jun 2023 20:13:04 +0100 |
parents | ea3c427d922d |
children | 035d3880da04 |
comparison
equal
deleted
inserted
replaced
2:ea3c427d922d | 3:e4003f606e07 |
---|---|
18 // Matrix projection and reset with identity | 18 // Matrix projection and reset with identity |
19 glMatrixMode(GL_PROJECTION); | 19 glMatrixMode(GL_PROJECTION); |
20 glLoadIdentity(); | 20 glLoadIdentity(); |
21 | 21 |
22 // Set the coordinates to be used with the viewport | 22 // Set the coordinates to be used with the viewport |
23 gluOrtho2D(-300, 300, 300, -300); | 23 gluOrtho2D(0, WIDTH, HEIGHT, 0); |
24 | |
25 glMatrixMode(GL_MODELVIEW); | |
26 glLoadIdentity(); | |
27 | |
28 } | 24 } |
29 | 25 |
30 | 26 |
31 void display() { | 27 void display() { |
32 glClear(GL_COLOR_BUFFER_BIT); | 28 glClear(GL_COLOR_BUFFER_BIT); |
33 glRectf(100.0f, 100.0f, 200.0f, 200.0f); | 29 glBegin(GL_QUADS); |
34 // glVertex2i(1920/2, 1080/2); | 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 | |
36 glVertex2f(160.0, 100.0); | |
37 glVertex2f(210.0, 100.0); | |
38 glVertex2f(210.0, 300.0); | |
39 glVertex2d(160.0, 300.0); | |
40 */ | |
41 | |
42 float rect_width = 5.0; | |
43 float space = 10.0; | |
44 | |
45 for (float pos_x = 100.0; pos_x < 500.0; pos_x += 10.0) { | |
46 glVertex2f(pos_x, 100.0); | |
47 glVertex2f(pos_x + rect_width, 100.0); | |
48 glVertex2f(pos_x + rect_width, 300.0); | |
49 glVertex2d(pos_x, 300.0); | |
50 } | |
51 | |
52 glEnd(); | |
35 glFlush(); | 53 glFlush(); |
36 } | 54 } |
37 | 55 |
38 | 56 |
39 int main(int argc, char** argv) { | 57 int main(int argc, char** argv) { |