-
Notifications
You must be signed in to change notification settings - Fork 0
/
cubeShadowLighting.c
74 lines (51 loc) · 1.38 KB
/
cubeShadowLighting.c
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
#include<GL/glut.h>
GLfloat T = 0;
void Spin()
{
T = T + 0.1;
if(T > 360)
T = 0;
//to redraw the window to keep the animation going
glutPostRedisplay();
}
void CustomInit()
{
glEnable(GL_DEPTH_TEST);
//sets the matrix stack to that corresponding to projection mode
glMatrixMode(GL_PROJECTION);
//identity matrix is loaded onto the matrix stack
glLoadIdentity();
//six parameters specifying the clipping planes:- left, right, top, bottom , near, far
glFrustum(-1, 1, -1, 1, 2, 10);
//mode responsible for transforming 3D scenes in respect to viewer's perspective
glMatrixMode(GL_MODELVIEW);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void Draw()
{
GLfloat Pos[] = {0, 1, 0, 1};
GLfloat Col[] = {1, 1, 1, 0};
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//glLightfv(GL_LIGHT0, GL_POSITION,Pos);
//glLightfv(GL_LIGHT0, GL_DIFFUSE, Col);
gluLookAt(0, 1, 3, 0, 0, 0, 0, 1, 0);
glRotatef(T, 1, 1, 0);
glutSolidCube(1);
glutSwapBuffers();
}
int main(int argc, char * argv[])
{
glutInit(&argc ,argv);
glutInitWindowPosition(100, 100);
glutInitWindowSize(600, 600);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutCreateWindow("Table");
CustomInit();
glutDisplayFunc(Draw);
//to register an callback function that will be called when there are no events to process
glutIdleFunc(Spin);
glutMainLoop();
return 0;
}