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
|
#include <stdlib.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <GL/glew.h>
5 #include <GL/freeglut.h>
6 #define WINDOW_TITLE_PREFIX "Chapter 1"
7
8 int CurrentWidth = 800,
9 CurrentHeight = 600,
10 WindowHandle = 0;
11
12 void Initialize(int, char*[]);
13 void InitWindow(int, char*[]);
14 void ResizeFunction(int, int);
15 void RenderFunction(void);
16
17 int main(int argc, char* argv[])
18 {
19 Initialize(argc, argv);
20
21 glutMainLoop();
22
23 exit(EXIT_SUCCESS);
24 }
25
26 void Initialize(int argc, char* argv[])
27 {
28 InitWindow(argc, argv);
29
30 fprintf(
31 stdout,
32 "INFO: OpenGL Version: %s\n",
33 glGetString(GL_VERSION)
34 );
35
36 glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
37 }
38
39 void InitWindow(int argc, char* argv[])
40 {
41 glutInit(&argc, argv);
42
43 glutInitContextVersion(4, 0);
44 glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
45 glutInitContextProfile(GLUT_CORE_PROFILE);
46
47 glutSetOption(
48 GLUT_ACTION_ON_WINDOW_CLOSE,
49 GLUT_ACTION_GLUTMAINLOOP_RETURNS
50 );
51
52 glutInitWindowSize(CurrentWidth, CurrentHeight);
53
54 glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
55
56 WindowHandle = glutCreateWindow(WINDOW_TITLE_PREFIX);
57
58 if(WindowHandle < 1) {
59 fprintf(
60 stderr,
61 "ERROR: Could not create a new rendering window.\n"
62 );
63 exit(EXIT_FAILURE);
64 }
65
66 glutReshapeFunc(ResizeFunction);
67 glutDisplayFunc(RenderFunction);
68 }
69
70 void ResizeFunction(int Width, int Height)
71 {
72 CurrentWidth = Width;
73 CurrentHeight = Height;
74 glViewport(0, 0, CurrentWidth, CurrentHeight);
75 }
76
77 void RenderFunction(void)
78 {
79 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
80
81 glutSwapBuffers();
82 glutPostRedisplay();
83 }
|