GLSL : Use of undeclared identifier 'gl_FragData' - macos

I'm debugging a really big project shading a tree, in that project the author used glsl file to shader the tree, but I have trouble compiling the glsl file:
Here is the error log:
compile: code/trees/TreeRender/Shader/Graph40.vert.glsl
ERROR: 0:4: '' : syntax error: #version
ERROR: 0:15: 'layout' : syntax error: syntax error
the Graph40.vert.glsl:
#version 120 core //the original file use version 400
#define VERT_POSITION 0
#define VERT_NORMAL 1
#define VERT_COLOR 2
#define VERT_TEXTURE 3
uniform mat4x4 matModel;
uniform mat4x4 matView;
uniform mat4x4 matProjection;
layout(location = VERT_POSITION) in vec4 Position;
layout(location = VERT_NORMAL) in vec4 Normal;
layout(location = VERT_COLOR) in vec4 Color;
layout(location = VERT_TEXTURE) in vec4 Texture;
out vec4 VertPosition;
out vec4 VertNormal;
out vec4 VertColor;
out vec4 VertTexture;
void main()
{
VertPosition = Position;
VertNormal = Normal;
VertColor = Color;
VertTexture = Texture;
gl_Position = matProjection * matView * matModel * vec4(Position.xyz, 1);
}
Another error log:
compile: code/trees/TreeRender/Shader/Default.vert.glsl
ERROR: 0:11: 'matModel' : syntax error: syntax error
The Default.vert.glsl:
#define VERT_POSITION 0
#define VERT_NORMAL 1
#define VERT_COLOR 2
#define VERT_TEXTURE 3
uniform mat4x4 matModel;
uniform mat4x4 matView;
uniform mat4x4 matProjection;
layout(location = VERT_POSITION) in vec4 Position;
layout(location = VERT_NORMAL) in vec4 Normal;
layout(location = VERT_COLOR) in vec4 Color;
layout(location = VERT_TEXTURE) in vec4 Texture;
out vec4 VertPosition;
out vec4 VertNormal;
out vec4 VertColor;
out vec4 VertTexture;
void main()
{
VertPosition = Position;
VertNormal = Normal;
VertColor = Color;
VertTexture = Texture;
gl_Position = matProjection * matView * matModel * vec4(Position.xyz, 1);
}
I tried to google the error, but found no feasible solution.
I use mac osx, xcode 7.0, the OpenGL and glut are all default versions. Glew version is 1.13.0.
Is that because of the version not match with the original version that the author used? Because I checked the original version, he used GLEW 1.9.0 and GLUT 3.7.6.
/////update//////
The original glsl files have:
#version 400 core
but there will be an error :
ERROR: 0:4: '' : version '400' is not supported
ERROR: 0:4: '' : syntax error: #version
so I commented that line. But other errors still there.
I checked my OpenGL version, using OpenGL Extension viewer, it's 4.1 in my mac, but versions older than that are also supported and should work too. But when I change to #version 410 core, it has the same error, saying that 410 is not supported.
///////////update////////////
It turned out that the version mac supported is NOT the version my context using. I printed in my code using GL_VERSION, it's 2.1 I'm using. Now I have changed into 4.1, according to [this][1]. But there is still errors:
trees/TreeRender/Shader/DefaultDepth.frag.glsl
helloERROR: 0:20: Use of undeclared identifier 'gl_FragData'
the DefaultLight.frag.glsl:
#version 400 core
in vec4 VertPosition;
in vec4 VertNormal;
in vec4 VertColor;
in vec4 VertTexture;
uniform vec3 lightPos;
void main()
{
float moment1 = gl_FragCoord.z;
float moment2 = moment1 * moment1;
gl_FragData[0] = vec4(moment1, moment2, 0.0, 1.0);
}

Version 120 does not support core profiles (only OpenGL 3.2+)
Layout quallifiers are also only available in OpenGL 3.2+

Related

CGAL 5.3: Example program to draw a triangulation doesn't work

I've installed the CGAL 5.3 and tried to build and run the example program from this page. That's what I did:
cd $HOME/CGAL-5.3/release/examples/Triangulation_2
cmake -DCMAKE_BUILD_TYPE=Release -DCGAL_DIR=../../lib/cmake/CGAL .
make draw_triangulation_2
./draw_triangulation_2
However, I've got a lot of error messages in the console window - mostly complaints about OpenGL shaders, please see below:
QOpenGLShader::compile(Vertex): 0:3(1): error: `in' qualifier in declaration of `vertex' only valid for function parameters in GLSL 1.10
0:4(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.10
0:9(1): error: `out' qualifier in declaration of `fColor' only valid for function parameters in GLSL 1.10
*** Problematic Vertex shader source code ***
#define lowp
#define mediump
#define highp
#line 1
in highp vec4 vertex;
in highp vec3 color;
uniform highp mat4 mvp_matrix;
uniform highp float point_size;
out highp vec4 fColor;
void main(void)
{
gl_PointSize = point_size;
fColor = vec4(color, 1.0);
gl_Position = mvp_matrix * vertex;
}
***
Compiling vertex source FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
linking Program FAILED
QOpenGLShader::compile(Vertex): 0:3(1): error: `in' qualifier in declaration of `vertex' only valid for function parameters in GLSL 1.10
0:4(1): error: `in' qualifier in declaration of `normal' only valid for function parameters in GLSL 1.10
0:5(1): error: `in' qualifier in declaration of `color' only valid for function parameters in GLSL 1.10
0:11(1): error: `out' qualifier in declaration of `fP' only valid for function parameters in GLSL 1.10
0:12(1): error: `out' qualifier in declaration of `fN' only valid for function parameters in GLSL 1.10
0:13(1): error: `out' qualifier in declaration of `fColor' only valid for function parameters in GLSL 1.10
*** Problematic Vertex shader source code ***
#define lowp
#define mediump
#define highp
#line 1
in highp vec4 vertex;
in highp vec3 normal;
in highp vec3 color;
uniform highp mat4 mvp_matrix;
uniform highp mat4 mv_matrix;
uniform highp float point_size;
out highp vec4 fP;
out highp vec3 fN;
out highp vec4 fColor;
void main(void)
{
fP = mv_matrix * vertex;
highp mat3 mv_matrix_3;
mv_matrix_3[0] = mv_matrix[0].xyz;
mv_matrix_3[1] = mv_matrix[1].xyz;
mv_matrix_3[2] = mv_matrix[2].xyz;
fN = mv_matrix_3* normal;
fColor = vec4(color, 1.0);
gl_PointSize = point_size;
gl_Position = mvp_matrix * vertex;
}
***
Compiling vertex source FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
linking Program FAILED
QOpenGLShader::link: error: linking with uncompiled/unspecialized shader
QOpenGLShaderProgram::attributeLocation(vertex): shader program is not linked
and so on... The viewer window, however, appeared but was empty:
The exactly same sequence of actions with CGAL 5.2.3 has given me a correct window with the triangulation and no error messages - so the OpenGL and Qt5 installations on my box look correct. The transition from the CGAL 5.2.3 to the CGAL 5.3 might be a culprit (???).
How to overcome this?
(I'm on Ubuntu 20.04.3 LTS, with standard kernel 5.11.0-27, and all the standard versions of OpenGL and Qt5)
UPDATE. I've opened an issue on the CGAL bug tracker.
I'm answering my own question. According to CGAL developers it's a bug in the Qt5-based visualization code, and there is no way to overcome it directly. The bug has been already fixed in the code repository, so the fix will be included in the next CGAL release.

OpenGL ES3: no matching overloaded function found for packUnorm2x16

I am trying to pack 2 float values into 1 uint value using packUnorm2x16 method of OpenGL ES3 GLSL. But the compilation of the shader fails with 'packUnorm2x16': no matching overloaded function found error.
This is my fragment shader:
varying highp vec2 vDisplacement;
void main() {
gl_FragColor = vec4(packUnorm2x16(vDisplacement), vec3(0.0));
}
I am trying to render a result to a GL_R32UI texture.
packUnorm2x16 is supported since OpenGL ES 3.0. You've to add the version qualifier #version 300 es to the first lien of the fragment shader:
#version 300 es
varying highp vec2 vDisplacement;
void main() {
gl_FragColor = vec4(packUnorm2x16(vDisplacement), vec3(0.0));
}

Unnecessary grid lines in sobel filter Opengl ES

My aim is to create sobel filter in Opengl ES. I am using Netbeans IDE. Everything is working fine in debug mode but in release mode I am getting grid lines. The code is running on raspberry pi.
Can anyone help me get rid of these lines?
This is the fragment shader code.
varying vec2 tcoord;
uniform sampler2D tex;
uniform vec2 texelsize;
void main(void)
{
vec4 tm1m1 = texture2D(tex,tcoord+vec2(-1,-1)*texelsize);
vec4 tm10 = texture2D(tex,tcoord+vec2(-1,0)*texelsize);
vec4 tm1p1 = texture2D(tex,tcoord+vec2(-1,1)*texelsize);
vec4 tp1m1 = texture2D(tex,tcoord+vec2(1,-1)*texelsize);
vec4 tp10 = texture2D(tex,tcoord+vec2(1,0)*texelsize);
vec4 tp1p1 = texture2D(tex,tcoord+vec2(1,1)*texelsize);
vec4 t0m1 = texture2D(tex,tcoord+vec2(0,-1)*texelsize);
vec4 t0p1 = texture2D(tex,tcoord+vec2(0,-1)*texelsize);
vec4 xdiff = -1.0*tm1m1 + -2.0*tm10 + -1.0*tm1p1 + 1.0*tp1m1 + 2.0*tp10 + 1.0*tp1p1;
vec4 ydiff = -1.0*tm1m1 + -2.0*t0m1 + -1.0*tp1m1 + 1.0*tm1p1 + 2.0*t0p1 + 1.0*tp1p1;
vec4 tot = sqrt((xdiff*xdiff)+(ydiff*ydiff));
vec4 col = tot;
col.a = 1.0;
gl_FragColor = clamp(col,vec4(0),vec4(1));
}
This is Debug image.
Release image.
This is only a partial answer. I did notice a wrong sign in your shader:
vec4 t0m1 = texture2D(tex,tcoord+vec2(0,-1)*texelsize);
vec4 t0p1 = texture2D(tex,tcoord+vec2(0,-1)*texelsize);
Those two would be the same value. Following the pattern of the other values, this should be:
vec4 t0m1 = texture2D(tex,tcoord+vec2(0,-1)*texelsize);
vec4 t0p1 = texture2D(tex,tcoord+vec2(0,1)*texelsize);
I don't believe this would explain the grid lines, though. But it should certainly improve the quality of the result.
Is this the full code of fragment shader? This looks like it may be caused by low precision.
According to p. 4.5.3 of GLSL ES tech specs you must explicitly specify float precision for fragment shaders - certain OpenGL ES drivers can even fail to compile fragment shaders w/o float precision.
You can set precision with this instruction at the very beginning of shader:
precision highp float;

openGL ES shaders wrong uniforms location

vertex shader looks like this:
uniform mat4 projectionMatrix;
uniform mat4 modelMatrix;
uniform mat4 viewMatrix;
attribute vec4 vPosition;
attribute vec4 vColor;
varying vec4 vDestinationColor;
void main(void)
{
gl_Position = projectionMatrix * modelMatrix * viewMatrix * vPosition;
vDestinationColor = vColor;
}
Objective-C code:
_projectionMatrixSlot = glGetUniformLocation(_programHandle, "projectionMatrix");
_modelMatrixSlot = glGetUniformLocation(_programHandle, "modelMatrix");
_viewMatrixSlot = glGetUniformLocation(_programHandle, "viewMatrix");
_positionAttribSlot = glGetAttribLocation(_programHandle, "vPosition");
_colorAttribSlot = glGetAttribLocation(_programHandle, "vColor");
here _projectionMatrixSlot _viewMatrixSlot _modelMatrixSlot equals 4294967295
while _positionAttribSlot and _colorAttribSlot is fine
The compiler is free to throw away variables that are not used in the code. Therefore, even if a uniform is declared in the shader, as long as it is not used, its reported location can be -1 or max int or unsigned int.
You may have attached wrong vertex shader, not this one which you post here.

clash between J3DI, Win7 and Nvidia Geforce

I have done a sphere using J3DI (which is a webGL library) under WIN 7 64bit as OS
and Nvidia Geforce GT330 M as graphic card .
firstly I have done it in blue color and it appeared correctly.
then, I tried to make a texture on it but the sphere appeared like in this image:
http://s1.postimage.org/1ekqrgolg/earth.jpg
while it has appeared in Mac like this :
http://s1.postimage.org/1eksf0138/error.jpg
so, what is the problem? is it from the OS, J3DI or from the graphic card?
for an additional information, the shader script i used this:
notice:this code has been taken from OpenGL and HTML5 (video course from O'reilly)
VertexShader:
uniform mat4 u_modelViewProjMatrix;
uniform mat4 u_normalMatrix;
uniform vec3 lightDir;
attribute vec3 vNormal;
attribute vec4 vTexCoord;
attribute vec4 vPosition;
varying float v_Dot;
varying vec2 v_texCoord;
void main()
{
gl_Position = u_modelViewProjMatrix * vPosition;
v_texCoord = vTexCoord.st;
vec4 transNormal = u_normalMatrix * vec4(vNormal, 1);
v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);
}
PixelShader:
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D sampler2d;
varying float v_Dot;
varying vec2 v_texCoord;
void main()
{
vec2 texCoord = vec2(v_texCoord.s, v_texCoord.t);
vec4 color = texture2D(sampler2d, texCoord);
color += vec4(0.1, 0.1, 0.1, 1);
gl_FragColor = vec4(color.xyz * v_Dot, color.a);
}
the context function is:
function(context){
// setup VBOs
context.enableVertexAttribArray(0);
context.enableVertexAttribArray(1);
context.enableVertexAttribArray(2);
context.bindBuffer(context.ARRAY_BUFFER, context.sphere.normalObject);
context.vertexAttribPointer(0, 3, context.FLOAT, false, 0, 0);
context.bindBuffer(context.ARRAY_BUFFER, context.sphere.texCoordObject);
context.vertexAttribPointer(1, 2, context.FLOAT, false, 0, 0);
context.bindBuffer(context.ARRAY_BUFFER, context.sphere.vertexObject);
context.vertexAttribPointer(2, 3, context.FLOAT, false, 0, 0);
context.bindBuffer(context.ELEMENT_ARRAY_BUFFER, context.sphere.indexObject);
//constract the model-view * projection matrix
var mvpMatrix = new J3DIMatrix4(context.perspectiveMatrix);
mvpMatrix.setUniform(context, context.getUniformLocation(context.program, "u_modelViewProjMatrix"), false);
//bind texture
context.bindTexture(context.TEXTURE_2D, this.texture);
context.drawElements(context.TRIANGLES, context.sphere.numIndices, context.UNSIGNED_SHORT, 0);
}
I'm really concern about this issue.
You're almost there. In:
v_Dot = max(dot(normalize(transNormal.xyz), normalize(lightDir)), 0.3);
Change 0.3 at the end to 1.0, that should work (edit: at least for Windows, MAC could be outdated drivers).

Resources