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

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.

Related

OpenGL ES 3.2 doesn't recognize gl_in in geometry shader

I have the following shader code:
#version 320 es
layout(points) in;
layout(points, max_vertices=1) out;
uniform mat4 transform;
void main() {
gl_Position = gl_in[0].gl_Position * transform;
EmitVertex();
EndPrimitive();
}
But when creating the shader program I get the following error:
'gl_in' : undeclared identifier
'gl_in' : left of '[' is not of type array, matrix, or vector
'gl_Position' : field selection requires structure, vector, or matrix on left hand side
'assign' : cannot convert from 'const highp float' to 'Position 4-component vector of highp float
But in https://www.khronos.org/registry/OpenGL/specs/es/3.2/GLSL_ES_Specification_3.20.html it explicitly states the existance of gl_in (as a built-in variable).
It is related to Intel UHD graphics not supporting OpenGLES explictly. When I checked what GLSL version was requested it was requesting OpenGL 2.0 which does not support gl_in as a built in.

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));
}

RenderMonkey opengles example compile failed with error C0118: macros prefixed with 'GL_' are reserved

I trying to use RenderMonkey 1.82 on Win10 PC, and graphics card is NVIDIA Geforce 405 v342.01. I cannot use the OpenGL ES examples that comes with it. I remember once I could do this on another machine. Is this an compatibility problem?
Vertex shader:
uniform mat4 view_proj_matrix;
uniform vec4 view_position;
attribute vec4 rm_Vertex;
attribute vec3 rm_Normal;
varying vec3 vNormal;
varying vec3 vViewVec;
void main(void)
{
gl_Position = view_proj_matrix * rm_Vertex;
// World-space lighting
vNormal = rm_Normal;
vViewVec = view_position.xyz - rm_Vertex.xyz;
}
Fragment shader:
precision mediump float;
uniform vec4 color;
varying vec3 vNormal;
varying vec3 vViewVec;
void main(void)
{
float v = 0.5 * (1.0 + dot(normalize(vViewVec), vNormal));
gl_FragColor = v * color;
}
The error message is:
OpenGL ES Preview Window: Compiling vertex shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Vertex Program/ ... failure
0(8) :
error C0118: macros prefixed with 'GL_' are reserved
OpenGL ES Preview
Window: Compiling fragment shader API(OpenGL ES)
/../Plastic_OpenGL_ES/Single Pass/Fragment Program/ ... failure
0(3) :
error C0118: macros prefixed with 'GL_' are reserved
RENDERING
ERROR(s): Vertex program 'Vertex Program' failed to compile in pass
'Single Pass'. See Output window for details Fragment program
'Fragment Program' failed to compile in pass 'Single Pass'. See
Output window for details
RenderMonkey adds a bunch of definitions onto the shaders before sending them to the GLSL compiler. You can verify this by running it through CodeXL, and then inspecting the text of the shaders. For my machine, this seems to be the standard (for vertex shaders, fragment shaders are similar):
#version 120
attribute float _J_K_;
void _VSh();void main()
{
_VSh(); gl_Position += (vec4(_J_K_) - vec4(_J_K_));
}
#define main _VSh
#define GL_ES
#define highp
#define mediump
#define lowp
#define invariant
#define gl_MaxVertexAttribs 15
#define gl_MaxVertexUniformVectors 224
#define gl_MaxVaryingVectors 8
#define gl_MaxVertexTextureImageUnits 0
#define gl_MaxCombinedTextureImageUnits 8
#define gl_MaxTextureImageUnits 8
#define gl_MaxFragmentUniformVectors 256
#define gl_MaxDrawBuffers 1
As you can see, on line 8, #define GL_ES is the error you are hitting (and this occurs on line 3 for fragment shaders).
In the GLSL ES spec, it states:
All macro names prefixed with “GL_” (“GL” followed by a single
underscore) are also reserved, and defining such a name results in a
compile-time error.
Thus, your driver is doing the correct thing, and rejecting this shader because it in fact violates the spec. Likely in very old Nvidia drivers, this error was not reported. You would need to recompile RenderMonkey to property resolve this issue, and the sources are not public.
However, you can hack RenderMonkey to get this to compile these shaders. These extra strings that are prepended are contained in the libGLESv2.dll in plain text, and you can use a hex editor to change them to something that doesn't start with GL_. They occur at offsets 0x16052E and 0x1606A0.
Or, instead just use the GL2 workspaces for developing your shaders, since GLSL and GLSL ES are very similar.

GLSL : Use of undeclared identifier 'gl_FragData'

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+

Do WebGL fragment shaders support outerProduct?

When compiling this WebGL fragment shader in both Chrome 22 and Firefox 15:
precision mediump float;
uniform vec2 u_resolution;
uniform sampler2D u_tex;
void main() {
vec2 texCoord = gl_FragCoord.xy / u_resolution;
vec4 floatColor = texture2D(u_tex, texCoord);
mat3 outerMat = outerProduct(floatColor.rgb,floatColor.rgb);
gl_FragColor = vec4(outerMat[0], 1);
}
I'm getting this error:
ERROR: 0:8: 'outerProduct' : no matching overloaded function found
ERROR: 0:8: '=' : cannot convert from 'const mediump float' to '3X3 matrix of float'
The OpenGL ES 2.0 GLSL spec indicates that mat3 outerProduct(vec3,vec3) is supported, and the WebGL spec says that it accepts ES shaders, so I'm not sure what's going wrong. Is outerProduct not supported in WebGL fragment shaders, or am I doing something wrong?
There is no outerProduct function in OpenGL ES 2.0 GLSL. Where did you read that there was? (or am I missing it?)
Here's the spec
http://www.khronos.org/registry/gles/specs/2.0/GLSL_ES_Specification_1.0.17.pdf
Try mat3 outerMat = outerProduct(vec3(floatColor.rgb),vec3(floatColor.rgb));
To expand, maybe giving it an explicit type is better than using .rgb.
it is now available with webGL2.
Check your system here: https://webglreport.com/?v=2

Resources