forked from Manan07Ag/LogicLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc.cpp
53 lines (44 loc) · 1.28 KB
/
abc.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <GL/glut.h>
const int width = 800; // Width of the window
const int height = 600; // Height of the window
const int gridSize = 20; // Size of each grid cell
void drawGrid() {
glClear(GL_COLOR_BUFFER_BIT);
// Draw the grid
glBegin(GL_QUADS);
for (int x = 0; x < width; x += gridSize) {
for (int y = 0; y < height; y += gridSize) {
if ((x / gridSize + y / gridSize) % 2 == 0) {
glColor3f(1.0f, 0.0f, 0.0f); // Red
} else {
glColor3f(0.0f, 0.0f, 1.0f); // Blue
}
glVertex2i(x, y);
glVertex2i(x + gridSize, y);
glVertex2i(x + gridSize, y + gridSize);
glVertex2i(x, y + gridSize);
}
}
glEnd();
glFlush();
}
void display() {
drawGrid();
}
void reshape(int w, int h) {
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(width, height);
glutCreateWindow("Color Grid in OpenGL");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}