-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
94 lines (81 loc) · 2.09 KB
/
main.cpp
File metadata and controls
94 lines (81 loc) · 2.09 KB
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
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <iostream>
using namespace std;
void display();
void reshape(int, int);
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB);
//creating a window
glutInitWindowPosition(200,100);
glutInitWindowSize(500,500);
// create the window and add title name
glutCreateWindow("openGL assignment PS/CSC/18/0065");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
//change the color of the window
init();
glutMainLoop();
}
void display()
{
//clear frame buffer
glClear(GL_COLOR_BUFFER_BIT);
// reset the co-ordinate system
glLoadIdentity();
// draw on the screen
glColor3f(1.0,1.0,1.0);
glBegin(GL_TRIANGLES);
glVertex2f(0.0,5.0);
glVertex2f(4.0,-3.0);
glVertex2f(-4.0,-3.0);
glEnd();
// rotation, scaling and shearing
glRotatef(angle,0,0,1);
glScalef(0.5, 0.5, 0.5);
//shearing along the x-axis for homogeneous coordinate NB: Xnew = (x + sh * y) and y values remains constant
GLfloat m[16] = {
1.0f, 0.0f, 0.0f, 0.0f,
sh, 1.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f,
};
glMultMatrixf(m);
/* without the matrix multiplication, the vertices can be displayed as follows for the same shearing
glBegin(GL_TRIANGLES);
glColor3f(0.5,0.5,0.5);
glVertex2f((0.0 + sh*5.0),5.0);
glColor3f(0,0,1);
glVertex2f((4.0 + sh*-3.0),-3.0);
glColor3f(1,0,0);
glVertex2f((-4.0 + sh*-3.0),-3.0);
glEnd();
*/
glBegin(GL_TRIANGLES);
glColor3f(0.5,0.5,0.5);
glVertex2f(0.0,5.0);
glColor3f(0,0,1);
glVertex2f(4.0,-3.0);
glColor3f(1,0,0);
glVertex2f(-4.0,-3.0);
glEnd();
glFlush();
}
//respecify the clipping window after the user reshape the window
void reshape(int w, int h)
{
//view port
glViewport(0,0,(GLsizei)w,(GLsizei)h);
//projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(-10,10,-10,10);
glMatrixMode(GL_MODELVIEW);
}