-
Notifications
You must be signed in to change notification settings - Fork 1
/
sphere.cpp
74 lines (62 loc) · 1.99 KB
/
sphere.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
#include <cstdlib>
#include <GL/glut.h>
#include <GL/glut.h>
#include <unistd.h>
void display()
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
//Set fill color (R,G,B):
glColor3f(1.0,1.0,1.0);
glOrtho(-2.0,2.0,-2.0,2.0,-2.0,1.0);
//(angle of rotation, (x, y, z) of a vector)
glRotatef(45,1,0.5,1);
//Just draw the triangles edges:
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
// GLdouble radius = 1.0;
// GLint slices = 20;
// GLint stacks = 20;
glPushMatrix();
glutSolidSphere(1.0, 20, 20);
glPopMatrix();
glFlush();
}
const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat light_position[] = { 2.0f, 0.0f, 0.0f, 0.0f };
const GLfloat mat_ambient[] = { 0.7f, 0.7f, 0.7f, 1.0f };
const GLfloat mat_diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f };
const GLfloat mat_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
const GLfloat high_shininess[] = { 100.0f };
void keyboard(unsigned char key, int x, int y)
{
if (key == 'q' || key == 'Q')
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
{
// Initialize GLUT
glutInit(&argc, argv);
// Create a window
glutCreateWindow("OpenGL Cube");
// Register display callback
glutDisplayFunc(display);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_SHININESS, high_shininess);
// Register keyboard callback
glutKeyboardFunc(keyboard);
// Enter main event loop
glutMainLoop();
return (EXIT_SUCCESS);
}