-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwork template.cpp
105 lines (79 loc) · 2.11 KB
/
work template.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
#include <GL/gl.h>
#include <GL/glut.h>
float _cameraAngle = 0.0;
void plot(double x, double y){
glVertex3f(x,y, 0);
}
void drawHeart(float x, float y){
vector
glColor3f(1,0,0);
glBegin(GL_POINTS);
plot(0.075,0); // <- plot the heart here
glEnd();
}
// this is where all drawing code belongs
void drawScreen(){
glColor3f(1,0,0);
glBegin(GL_LINE_LOOP);
plot(0,0);
plot(.15,0);
plot(.15,.15);
plot(.0,.15);
glEnd();
drawHeart();
}
void update(int value) {
glutPostRedisplay(); //Tell GLUT that the display has changed
//Tell GLUT to call update again in 25 milliseconds
glutTimerFunc(10, update, 0);
}
//DO NOT TOUCH THIS
// put drawing code in drawScreen function
void updateScreen(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); //Switch to the drawing perspective
glLoadIdentity(); //Reset the drawing perspective
glRotatef(-_cameraAngle, 0.0, 1.0, 0.0); //Rotate the camera
glTranslatef(0.0, 0.0, -7.0); //Move forward 5 units
glPushMatrix(); //Save the transformations performed thus far
drawScreen();
glPopMatrix(); //Undo the move to the center of the triangle
glutSwapBuffers();
}
//Called when the window is resized
void handleResize(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(45.0, (double)w / (double)h, 1.0, 200.0);
}
void idle(){
glutPostRedisplay();
}
void setCallbacks(){
glutDisplayFunc(updateScreen);
glutReshapeFunc(handleResize);
// glutIdleFunc(idle);
}
//Initializes 3D rendering
void initRendering() {
glPointSize(5);
glMatrixMode(GL_PROJECTION);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
int main(int argc, char** argv){
//Initialize GLUT
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(800,700);
glutInitWindowPosition(300,50);
glutCreateWindow("Portal 2D");
// glutFullScreen();
initRendering();
setCallbacks();
glutTimerFunc(25, update, 0);
glutMainLoop();
return 0;
}