-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_version.cpp
More file actions
119 lines (99 loc) · 3.37 KB
/
Copy pathcheck_version.cpp
File metadata and controls
119 lines (99 loc) · 3.37 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <GL\glew.h> // the opengl library wrapped by extended features
#include <GL\freeglut.h> // library cross-platform toolkit windows and managing input operations
#include <iostream>
#include <sstream>
using namespace std;
/**
* analyse the version
*/
string makeMeString (GLint versionRaw) {
stringstream ss;
ss << versionRaw; // transfers versionRaw value into 'ss'
return ss.str ();
}
/**
* Format the string as expected
*/
void formatMe (string *text) {
string dot = ".";
text->insert (1, dot); // transforms 30000 into 3.0000
text->insert (4, dot); // transforms 3.0000 into 3.00.00
}
/**
* Message
*/
void consoleMessage () {
char *versionGL;
/* there is some error when checking glut version.
* so I commented it for now.
*/
// GLint versionFreeGlutInt;
versionGL = (char*) (glGetString (GL_VERSION));
// versionFreeGlutInt = (glutGet (GLUT_VERSION));
// string versionFreeGlutString = makeMeString (versionFreeGlutInt);
// formatMe (&versionFreeGlutString);
cout << endl;
cout << "OpenGL version: " << versionGL << endl << endl;
// cout << "FreeGLUT version: " << versionFreeGlutString << endl << endl;
cout << "GLEW version: "
<< GLEW_VERSION << "."
<< GLEW_VERSION_MAJOR << "."
<< GLEW_VERSION_MINOR << "."
<< GLEW_VERSION_MICRO << endl;
}
/**
* Manager error
*/
void managerError () {
if (glewInit ()) { // checks if glewInit() is activated
cerr << "Unable to initialize GLEW." << endl;
while (1); // let's use this infinite loop to check the error message before closing the window
exit (EXIT_FAILURE);
}
// FreeConsole();
}
/**
* Manage display (to be implemented)
*/
void managerDisplay ()
{
glClear (GL_COLOR_BUFFER_BIT); // clear the screen
glutSwapBuffers ();
}
/**
* Initialize FREEGLUT
*/
void initFreeGlut (int ac, char *av[]) {
// A. init
glutInit (&ac, av); // 1. inits glut with arguments from the shell
glutInitDisplayString (""); // 2a. sets display parameters with a string (obsolete)
glutInitDisplayMode (GLUT_SINGLE); // 2b. sets display parameters with defines
glutInitWindowSize (600, 600); // 3. window size
/* these lines produce error */
// glutInitContextVersion (3, 3); // 4. sets the version 3.3 as current version (so some functions of 1.x and 2.x could not work properly)
// glutInitContextProfile (GLUT_CORE_PROFILE); // 5. sets the version 3.3 for the profile core
glutInitWindowPosition (500, 500); // 6. distance from the top-left screen
// B. create window
glutCreateWindow ("BadproG - Hello world :D"); // 7. message displayed on top bar window
}
/**
* Manage keyboard
*/
void managerKeyboard (unsigned char key, int x, int y) {
if (key == 27) // 27 = ESC key
exit(0);
}
/**
* Main, what else?
*/
int main (int argc, char** argv) {
initFreeGlut (argc, argv); // inits freeglut
managerError (); // manages errors
consoleMessage (); // displays message on the console
// C. register the display callback function
glutDisplayFunc (managerDisplay); // 8. callback function
glutKeyboardFunc (managerKeyboard);
// D. main loop
glutMainLoop (); // 9. infinite loop
return 0;
}