我在从openGL获取调试信息时遇到了一些问题。我不知道它是否有任何区别,但我正在使用glfw3和glew(动态链接)
我似乎无法编译着色器和我得到的错误消息只是胡言乱语。
以下是示例代码:
shader.ID = glCreateShader(shader.type);
const GLchar *source = (const GLchar *)shader.source.c_str();
glShaderSource(shader.ID, 1, &source, 0);
glCompileShader(shader.ID);
GLint compiled = 0;
glGetShaderiv(shader.ID, GL_COMPILE_STATUS, &compiled);
if (compiled == GL_FALSE) {
GLint logLength = 0;
glGetShaderiv(shader.ID, GL_INFO_LOG_LENGTH, &logLength); //won't update logLength
//std::cout << logLength << std::endl;
GLchar* infoLog = new char[logLength + 1];
glGetShaderInfoLog(shader.ID, logLength, NULL, infoLog);
std::cerr << infoLog << std::endl;
delete[] infoLog;
glDeleteShader(shader.ID);
}
glGetShaderiv 不会更新logLength,我得到的输出将是这样的:
═²²²²½½½½½½½½■ε■
这是我第一次尝试编译着色器,我错过了什么?
编辑:上下文创建
#include <GL\glew\glew.h>
#include <GL\GLFW\glfw3.h>
void setupGLFW() {
//glfwSetErrorCallback(glfwErrorCallback);
if (GL_FALSE == glfwInit()) {
std::cerr << "Error Initializing GLFW" << std::endl;
exit(-1);
}
GLFWwindow* window = glfwCreateWindow(640, 480, "TEST", NULL, NULL);
glfwMakeContextCurrent(window);
glfwSwapInterval(1);
}
void setupGLEW() {
glewExperimental = GL_TRUE;
const GLenum glewErr = glewInit();
if (glewErr != GLEW_OK) {
cerr << "GLEW failed to initialize." << endl;
exit(-1);
}
}
void testshaderLoader()
{
setupGLFW();
setupGLEW();
glEnable(GL_DEBUG_OUTPUT);
ShaderLoader sloader;
string pathToShader = "absolute/path/to/shader"
GLenum shaderType = GL_FRAGMENT_SHADER;
sloader.loadShader(pathToShader, shaderType);
}
int main()
{
testshaderLoader();
return 0;
}