简体   繁体   English

当我在顶点着色器中有一个“ out”时,OpenGL无法绘制

[英]OpenGL doesn't draw when I have an “out” in vertex shader

I have aa vertex shader and a fragment shader. 我有一个顶点着色器和一个片段着色器。 I am sending in a color variable in the buffer to the vertex shader, and then trying to pass it to the fragment shader. 我正在将缓冲区中的颜色变量发送到顶点着色器,然后尝试将其传递给片段着色器。 When I have an out vec4 out_color in my code, nothign is drawn. 当我的代码中有out vec4 out_color时,将绘制nothign。 My code is 我的代码是

"in vec4 in_position;\n"
"in vec4 in_color;\n"
"out vec4 out_color;"
"void\nmain()\n"
"{\n"
"  gl_Position = in_position;\n"
"out_color = in_color;"
"}\n\n";

Can anyone shed some light on this? 谁能对此有所启发?

You forgot the newline after the declaration of out_color in your shader string. 在着色器字符串中声明out_color后,您忘记了换行符。 So it is on the same line as void main() (in which you also have a newline, but that might not be a problem). 因此它与void main()在同一行上(在该行中您也有一个换行符,但这可能不是问题)。

For the sake of clarity, I would suggest you to always use one substring for a single line and always include a newline at the end of each substring, if you really want to use in-code shader code, anyway. 为了清楚起见,如果您确实想使用代码内着色器代码,建议您始终为一行使用一个子字符串,并在每个子字符串的末尾始终包含换行符。

And you should also always check if your shaders compiled correctly and the program linked correctly and query the info log in case they didn't. 而且,您还应该始终检查着色器是否正确编译,程序是否正确链接,并查询信息日志(如果不正确)。 This would have told you the error quite obviously (or at least would have given you a hint). 这显然会告诉您错误(或者至少会给您提示)。

原来我使用的着色语言版本错误,必须在两个着色器的顶部都包含代码

#version 140;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM