comparison 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
comparison
equal deleted inserted replaced
2:ea3c427d922d 3:e4003f606e07
1 #include <stdio.h>
2 #include <GL/glut.h>
3
4
5 #define HEIGHT 1080
6 #define WIDTH 1920
7
8
9 void setup() {
10
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
18 // Matrix projection
19 glMatrixMode(GL_PROJECTION);
20 glLoadIdentity();
21
22
23 // Set the coordinates to be used with the viewport
24 gluOrtho2D(0, WIDTH, HEIGHT, 0);
25
26
27 glMatrixMode(GL_MODELVIEW);
28 glLoadIdentity();
29 }
30
31
32 void display() {
33 glClear(GL_COLOR_BUFFER_BIT);
34 glBegin(GL_QUADS);
35 glVertex2f(100.0f, 100.0f); // Bottom-left vertex of first rectangle
36 glVertex2f(200.0f, 100.0f); // Bottom-right vertex of first rectangle
37 glVertex2f(200.0f, 200.0f); // Top-right vertex of first rectangle
38 glVertex2f(100.0f, 200.0f); // Top-left vertex of first rectangle
39 glEnd();
40 glFlush();
41 }
42
43
44 int main(int argc, char** argv) {
45
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 }