-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_gl_info.cpp
79 lines (58 loc) · 1.95 KB
/
get_gl_info.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
75
76
77
78
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include <iostream>
void errorCallback(int error, const char* description) {
std::cerr << error << ": " << description << std::endl;
exit(EXIT_FAILURE);
}
GLint getInt(GLenum name) {
GLint temp = 0;
glGetIntegerv(name, &temp);
return temp;
}
template<class KT, class VT> void output(KT key, VT val) {
std::cout << " \"" << key << "\": \"" << val << "\",\n";
}
int go(int argc, char* argv[]) {
glfwWindowHint(GLFW_RESIZABLE, 0);
#ifdef __APPLE__
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#endif
GLFWwindow* window = glfwCreateWindow(640, 480, "Get gl info", NULL, NULL);
if(!window) {
return EXIT_FAILURE;
}
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc) glfwGetProcAddress);
glfwSwapInterval(1);
std::cout << "{\n";
output("GL_VERSION", glGetString(GL_VERSION));
output("GL_MAJOR_VERSION", getInt(GL_MAJOR_VERSION));
output("GL_MINOR_VERSION", getInt(GL_MINOR_VERSION));
output("GL_SHADING_LANGUAGE_VERSION", glGetString(GL_SHADING_LANGUAGE_VERSION));
output("GL_VENDOR", glGetString(GL_VENDOR));
output("GL_RENDERER", glGetString(GL_RENDERER));
GLuint glslNumVersions = (GLuint) getInt(GL_NUM_SHADING_LANGUAGE_VERSIONS);
std::cout << " \"Supported_GLSL_versions\": [";
if(glslNumVersions > 0) {
std::cout << "\"" << glGetStringi(GL_SHADING_LANGUAGE_VERSION, 0) << "\"";
for(GLuint i=1; i < glslNumVersions; ++i) {
std::cout << ", \"" << glGetStringi(GL_SHADING_LANGUAGE_VERSION, i) << "\"";
}
}
std::cout << "]\n";
std::cout << "}" << std::endl;
return EXIT_SUCCESS;
}
int main(int argc, char* argv[]) {
glfwSetErrorCallback(errorCallback);
if(!glfwInit()) {
exit(EXIT_FAILURE);
}
int res = go(argc, argv);
glfwTerminate();
return res;
}