When switching to GLSL 300, met the following error

隐身守侯 提交于 2019-12-21 04:42:06

问题


when I switch to use OpenGL ES 3 with GLSL 300, I met the following error in my frag shader

undeclared identifier gl_FragColor

when using GLSL 100, everything is fine.


回答1:


Modern versions of GLSL do fragment shader outputs simply by declaring them as out values, and gl_FragColor is no longer supported, hence your error. Try this:

out vec4 fragColor;
void main()
{
    fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}

Note that gl_FragDepth hasn't changed and is still available.

For more information see https://www.opengl.org/wiki/Fragment_Shader




回答2:


The predefined variable gl_FragColor does not exist anymore in GLSL ES 3.00. You need to define your own out variable for the output of the fragment shader. You can use any name you want, for example:

out vec4 FragColor;

void main() {
    ...
    FragColor = ...;
}

This follows the Core Profile of full OpenGL. The reason for not having a pre-defined fragment shader output is that it does not scale well for multiple render targets, and for render targets that need types other than float vectors.



来源:https://stackoverflow.com/questions/26695253/when-switching-to-glsl-300-met-the-following-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!