include windows include GL glut void resize int width int height glVie

 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
#include <windows.h>
#include <GL/glut.h>
void resize(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-5, 5, -5, 5, 2, 12);
gluLookAt(0, 0, 5, 0, 0, 0, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(0, 1, 0);
glBegin(GL_QUADS);
glVertex3d(-4, -4, 0);
glVertex3d(-4, 4, 0);
glVertex3d(4, 4, 0);
glVertex3d(4, -4, 0);
glEnd();
/*
glColor3d(1,0,0);
auxSolidSphere(0.1);
*/
glFlush();
}
void main(int argc, char** argv)
{
float light_pos[4] = { 2,2,2, 0.5 };
float dir[3] = { -1, -1, -1 };
GLfloat mat_specular[] = { 1,1,1,1 };
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(500, 500);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(resize);
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, light_pos);
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, dir);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialf(GL_FRONT, GL_SHININESS, 128.0);
glLighti(GL_LIGHT0, GL_SPOT_EXPONENT, 0);
glLighti(GL_LIGHT0, GL_SPOT_CUTOFF, 90);
glutMainLoop();
}