forked from Manan07Ag/LogicLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvansh.cpp
109 lines (91 loc) · 2.86 KB
/
vansh.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <GL/glut.h>
#include <cmath>
#include <iostream>
class GraphicsApp {
public:
static void run(int argc, char** argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(800, 600);
glutCreateWindow("Static Scene");
glutReshapeFunc(reshape);
glutDisplayFunc(display);
glViewport(0, 0, 800, 600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glutMainLoop();
}
private:
static GLfloat angle;
static GLfloat triangleX;
static GLfloat triangleY;
static void reshape(int width, int height) {
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (width >= height) {
double aspect = static_cast<double>(width) / static_cast<double>(height);
glOrtho(-aspect, aspect, -1.0, 1.0, -1.0, 1.0);
} else {
double aspect = static_cast<double>(height) / static_cast<double>(width);
glOrtho(-1.0, 1.0, -aspect, aspect, -1.0, 1.0);
}
glMatrixMode(GL_MODELVIEW);
}
static void display() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 1.0f, 1.0f);
// Drawing the triangle
glPushMatrix();
glTranslatef(triangleX, triangleY, 0.0f);
glRotatef(angle, 0.0f, 0.0f, 1.0f);
glBegin(GL_LINE_LOOP);
glVertex2f(-0.2f, -0.2f);
glVertex2f(0.2f, -0.2f);
glVertex2f(0.0f, 0.2f);
glEnd();
glPopMatrix();
// Drawing lines
glBegin(GL_LINES);
glVertex2f(-0.4f, 0.1f);
glVertex2f(-0.2f, 0.1f);
glVertex2f(-0.4f, -0.1f);
glVertex2f(-0.2f, -0.1f);
glEnd();
// Drawing another line
glBegin(GL_LINES);
glVertex2f(0.3f, 0.0f);
glVertex2f(0.4f, 0.0f);
glEnd();
// Drawing a circle
glBegin(GL_LINE_LOOP);
for (int i = 0; i < 360; ++i) {
float angle = static_cast<float>(i) * 3.14159265f / 180.0f;
float x = 0.05f * std::cos(angle);
float y = 0.05f * std::sin(angle);
glVertex2f(0.25f + x, y);
}
glEnd();
// Drawing a stippled rectangle
glLineStipple(1, 0x00FF);
glEnable(GL_LINE_STIPPLE);
glBegin(GL_LINE_LOOP);
glVertex2f(-0.4f, -0.3f);
glVertex2f(0.4f, -0.3f);
glVertex2f(0.4f, 0.3f);
glVertex2f(-0.4f, 0.3f);
glEnd();
glDisable(GL_LINE_STIPPLE);
glFlush();
}
};
GLfloat GraphicsApp::angle = -90.0f;
GLfloat GraphicsApp::triangleX = 0.0f;
GLfloat GraphicsApp::triangleY = 0.0f;
int main(int argc, char** argv) {
GraphicsApp::run(argc, argv);
return 0;
}