opengl helloworld
1 #include <GL/glut.h>
2 #include <GL/gl.h>
3 void cube (void) {
4 glutWireCube(2);
5 }
6 void display(void)
7 {
8 glClearColor(0.0, 0.5, 0.0, 1.0);
9 glClear(GL_COLOR_BUFFER_BIT);
10 glLoadIdentity();
11 gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
12 cube();
13 glFlush();
14 }
15 void reshape (int w, int h) {
16 glViewport (0, 0, (GLsizei)w, (GLsizei)h);
17 glMatrixMode (GL_PROJECTION);
18 glLoadIdentity ();
19 gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
20 glMatrixMode (GL_MODELVIEW);
21 }
22 void keyboard (unsigned char key, int x, int y) {
23 if (key==27) { //ESC
24 exit (0);
25 }
26 }
27 void main(int argc, char **argv)
28 {
29 glutInit(&argc, argv);
30 glutInitDisplayMode(GLUT_SINGLE);
31 glutInitWindowSize(400, 400);
32 glutInitWindowPosition(0, 0);
33 glutCreateWindow("hello opengl");
34 glutDisplayFunc(display);
35 glutReshapeFunc (reshape);
36 glutKeyboardFunc(keyboard);
37 glutMainLoop();
38 }
2 #include <GL/gl.h>
3 void cube (void) {
4 glutWireCube(2);
5 }
6 void display(void)
7 {
8 glClearColor(0.0, 0.5, 0.0, 1.0);
9 glClear(GL_COLOR_BUFFER_BIT);
10 glLoadIdentity();
11 gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
12 cube();
13 glFlush();
14 }
15 void reshape (int w, int h) {
16 glViewport (0, 0, (GLsizei)w, (GLsizei)h);
17 glMatrixMode (GL_PROJECTION);
18 glLoadIdentity ();
19 gluPerspective (60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
20 glMatrixMode (GL_MODELVIEW);
21 }
22 void keyboard (unsigned char key, int x, int y) {
23 if (key==27) { //ESC
24 exit (0);
25 }
26 }
27 void main(int argc, char **argv)
28 {
29 glutInit(&argc, argv);
30 glutInitDisplayMode(GLUT_SINGLE);
31 glutInitWindowSize(400, 400);
32 glutInitWindowPosition(0, 0);
33 glutCreateWindow("hello opengl");
34 glutDisplayFunc(display);
35 glutReshapeFunc (reshape);
36 glutKeyboardFunc(keyboard);
37 glutMainLoop();
38 }