Mercurial > public > algo-animator
annotate 34 @ 3:e4003f606e07
draw multiple rectangles with loop
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Mon, 12 Jun 2023 20:13:04 +0100 |
parents | main.c@ea3c427d922d |
children |
rev | line source |
---|---|
0 | 1 #include <stdio.h> |
2 #include <GL/glut.h> | |
3 | |
4 | |
5 #define HEIGHT 1080 | |
6 #define WIDTH 1920 | |
7 | |
8 | |
9 void setup() { | |
2
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
10 |
0 | 11 // Set background dark |
12 glClearColor(0.0, 0.0, 0.0, 1.0); | |
13 | |
14 // Set point color and size to 1 pixel | |
15 glColor3f(0.0, 1.0, 0.0); | |
16 glPointSize(5.0); | |
17 | |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
18 // Matrix projection |
0 | 19 glMatrixMode(GL_PROJECTION); |
20 glLoadIdentity(); | |
2
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
21 |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
22 |
0 | 23 // Set the coordinates to be used with the viewport |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
24 gluOrtho2D(0, WIDTH, HEIGHT, 0); |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
25 |
2
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
26 |
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
27 glMatrixMode(GL_MODELVIEW); |
ea3c427d922d
draw a weird filled rectangle
Dennis C. M. <dennis@denniscm.com>
parents:
0
diff
changeset
|
28 glLoadIdentity(); |
0 | 29 } |
30 | |
31 | |
32 void display() { | |
33 glClear(GL_COLOR_BUFFER_BIT); | |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
34 glBegin(GL_QUADS); |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
35 glVertex2f(100.0f, 100.0f); // Bottom-left vertex of first rectangle |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
36 glVertex2f(200.0f, 100.0f); // Bottom-right vertex of first rectangle |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
37 glVertex2f(200.0f, 200.0f); // Top-right vertex of first rectangle |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
38 glVertex2f(100.0f, 200.0f); // Top-left vertex of first rectangle |
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
39 glEnd(); |
0 | 40 glFlush(); |
41 } | |
42 | |
43 | |
44 int main(int argc, char** argv) { | |
3
e4003f606e07
draw multiple rectangles with loop
Dennis C. M. <dennis@denniscm.com>
parents:
2
diff
changeset
|
45 |
0 | 46 glutInit(&argc, argv); |
47 glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); | |
48 glutInitWindowSize(WIDTH, HEIGHT); | |
49 glutCreateWindow("OpenGL Window"); | |
50 setup(); | |
51 glutDisplayFunc(display); | |
52 glutMainLoop(); | |
53 | |
54 return 0; | |
55 } |