-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
134 lines (91 loc) · 2.55 KB
/
main.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
* Windmill
*
* Written by Soomanib Kamruzzaman, 2019
*
*/
#include <windows.h>
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include <cmath>
#define PI 3.14159
#include "texture.cpp"
#include "declaration.cpp"
RGBpixmap pix[10];
void Init()
{
glEnable(GL_TEXTURE_2D);
pix[0].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\grass2.bmp");
pix[0].setTexture(1);
pix[1].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\brick.bmp");
pix[1].setTexture(2);
pix[2].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\floor.bmp");
pix[2].setTexture(3);
pix[4].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\bgnd.bmp");
pix[4].setTexture(4);
pix[4].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\glass.bmp");
pix[4].setTexture(5);
pix[4].readBMPFile("D:\\Graphics-Lab\\simple GL environment - Linear\\table_top.bmp");
pix[4].setTexture(6);
}
static void resize(int width, int height)
{
const float ar = (float) width / (float) height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-ar, ar, -1.0, 1.0, 2.0, 100.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity() ;
}
static void display(void)
{
const double t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
const double a = t*90.0;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
camera();
glPushMatrix();
glTranslated(tx, ty, tz);
glRotated(rx, 1, 0, 0);
glRotated(ry, 0, 1, 0);
glRotated(rz, 0, 0, 1);
glScaled(sx, sy, sz);
environment();
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glutSwapBuffers();
}
static void idle(void)
{
glutPostRedisplay();
}
/* Program entry point */
int main(int argc, char *argv[])
{
glutInit(&argc, argv);
glutInitWindowSize(1366,768);
glutInitWindowPosition(0,0);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Windmill Project");
glutReshapeFunc(resize);
glutDisplayFunc(display);
glutKeyboardFunc(key);
glutIdleFunc(idle);
glClearColor(0,0,0,1);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
//Enabling Light
glEnable(GL_NORMALIZE);
glEnable(GL_LIGHTING);
//Texture
Init();
glutMainLoop();
return EXIT_SUCCESS;
}