无法从glGetShaderInfoLog检索错误消息 [英] Unable to retrieve an error message from glGetShaderInfoLog
问题描述
我正在尝试构建一个由单个片段着色器组成的简单OpenGL 3.2程序,但是我似乎无法实际编译该着色器.我相当确定我的着色器语法正确,但是即使不正确,我也无法使用glGetShaderInfoLog
检索错误消息.
I am attempting to build a simple OpenGL 3.2 program which consists of a single fragment shader, but I do not seem to be able to actually compile the shader. I'm fairly sure that my shader syntax is correct, but even if it's not, I am unable to retrieve an error message using glGetShaderInfoLog
.
我已经开发了一个简短的程序来演示此操作:
I have developed a short program that shows this in action:
GLuint shader = glCreateShader(GL_FRAGMENT_SHADER);
const char *shaderData =
"#version 120\n"
"void main()\n"
"{\n"
" gl_FragColor = gl_Color;\n"
"}\n";
glShaderSource(shader, 1, &shaderData, NULL);
GLint status;
glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
if (status == GL_FALSE)
{
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
GLchar* strInfoLog = new GLchar[infoLogLength + 1];
glGetShaderInfoLog(shader, infoLogLength, NULL, strInfoLog);
fprintf(stderr, "Compilation error in shader %s: %s\n", this->name, strInfoLog);
delete[] strInfoLog;
}
这将产生消息:
着色器片段着色器中的编译错误:
Compilation error in shader Fragment Shader:
问题似乎是每次调用getShaderiv
来检索GL_INFO_LOG_LENGTH
值都返回0,因此我分配了一个空字符串.我曾尝试将此值硬编码为100,但仍然没有从getShaderInfoLog
接收任何信息.
The issue seems to be that the call to getShaderiv
to retrieve the GL_INFO_LOG_LENGTH
value returns 0 every time, so therefore I allocate an empty string. I have tried hard-coding this value to 100, but I still receive nothing from getShaderInfoLog
.
我这里关心的不是修复着色器(如果错误,我可以自己做),而是获取调试信息.我知道可以做到,因为我使用了 Shader Maker 简要地开发着色器,我可以获得非常详细的调试消息.例如:
My concern here is not to fix the shader (I can do that myself if it is wrong), but to get the debug information. I know that this can be done, because I have used Shader Maker to develop shaders briefly, and I am able to get very detailed debug messages. For example:
ERROR: 0:11: 'undefined_variable' : syntax error syntax error
除非Shader Marker内部拥有自己的验证工具,否则我确信它必须使用与尝试使用的方法相同的方法.我在互联网上看到了几个例子,人们以相同的方式检索着色器的错误消息,因此,我相当确定自己做得正确.
Unless Shader Marker has its own validation tool internally, I'm sure it has to be using the same method that I am trying to use. I have seen several examples on the internet in which people retrieve the error message for a shader in the same way, so I'm fairly sure I'm doing it correctly.
现在,我收到一个编译时警告,它可能潜在地解释了这个问题:
Now, I am getting a compile-time warning which could potentially explain this problem:
#warning gl.h and gl3.h are both included. Compiler will not invoke errors if using removed OpenGL functionality.
进行全文搜索后,找不到在任何地方调用#include <OpenGL/gl.h>
的地方,因此我猜测NSOpenGL*
类之一包含了此标头.我相当确定我不会在这个简短的程序中使用任何已删除的功能,并且这个问题在Google上只有5个匹配,但我想还是应该提一下.
After doing a full text search, I cannot find anywhere where I call #include <OpenGL/gl.h>
, so I am guessing that this header is being included by one of the NSOpenGL*
classes. I'm fairly sure that I'm not using any removed functionality in this short program, and this issue only has about 5 hits on Google, but I thought I'd better mention this anyway.
推荐答案
如先前的注释所述,glCompileShader
调用丢失了.
As noted in a previous comment, the glCompileShader
call was missing.
这篇关于无法从glGetShaderInfoLog检索错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!