Closed makichiis closed 6 months ago
What does glGetString(GL_VERSION)
return?
Hello Dav1dde, thank you for responding so quickly.
glGetString(GL_VERSION)
returns "4.6.0 Core Profile Context 24.1.1.231127"
, I think as expected.
Mh that should work, can you debug into glad_gl_find_core_gl
either via a debugger or just add a few printf
's, I am mainly interested in the version
string before the GLAD_IMPL_UTIL_SSCANF
call and the major
, minor
variables after.
Thank you for the advice. I was able to find the source of the problem. As it turns out, glad_gl_find_core_gl
and GLAD_IMPL_UTIL_SSCANF
are not called at any point.
It seems that GLAD_GL_IMPLEMENTATION
must be defined before gl.h
is included in order to be called, so I assume the version is not set otherwise. After adding #define GLAD_GL_IMPLEMENTATION
before #include <glad/gl.h>
, the version is properly set:
Should I fork and PR the example with the definition of GLAD_GL_IMPLEMENTATION
?
Revised source file:
#include <stdlib.h>
#include <stdio.h>
#define GLAD_GL_IMPLEMENTATION
#include <glad/gl.h>
#include <GLFW/glfw3.h>
const GLuint WIDTH = 800, HEIGHT = 600;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mode) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void) {
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); // GL version edited for version test
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
GLFWwindow* window = glfwCreateWindow(WIDTH, HEIGHT, "[glad] GL with GLFW", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSetKeyCallback(window, key_callback);
int version = gladLoadGL(glfwGetProcAddress);
printf("GL %d.%d\n", GLAD_VERSION_MAJOR(version), GLAD_VERSION_MINOR(version));
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
glClearColor(0.7f, 0.9f, 0.1f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers(window);
}
glfwTerminate();
return 0;
}
Issue possibly resolved by fork in PR #464. Please let me know if there are any issues.
Thank you @Dav1dde
As discussed in https://github.com/Dav1dde/glad/pull/464#issuecomment-2041496499 we cannot re-produce the issue, closing it until reproducible.
The GL/GLFW example located at
example/c/gl_glfw.c
(shown below) loads GL withglfwGetProcAddress
:However, when loading with GLFW (and glad2) for OpenGL 4.6,
gladLoadGL(GLADloadfunc)
returns1
. Thus, when retrieving the major and minor versions of OpenGL,"0.1"
is generated.I'm not sure if this is intentional, because I would expect this to return either the current GLAD version or the current GL version, however only
1
is ever returned fromgladLoadGL
.I don't think this issue is cause for any immediately obvious problems with the loader, but I worry about portability in the future. Is this the incorrect way to retrieve the OpenGL version loaded by glad? If so, what should be done instead?
Thank you for reading.
Contents of
example/c/gl_glfw.c