Opengl: error(#97) no program main found - opengl

this is the error I get when my application starts:
Vertex shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error(#97) No program main found
fragment link error: INVALID_OPERATION.
ERROR: error(#97) No program main found
I couldn't find any mistake, but the shaders are correctly (fully) loaded and compiled without any errors. Here are my shaders:
vertex shader:
#version 330
layout (location = 0) in vec3 position;
void main()
{
gl_Position = vec4(position, 1.0);
}
fragment shader:
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0, 0.5, 0.2, 1.0);
}

Errors like these are usually caused by glShaderSource not receiving a correct source code string.
The cause of your issue is most likely that your shader code wasn't loaded properly and an incorrect string (or char array) is passed to glShaderSource

Related

Link error with geometry shader (driver bug?)

I have a GLSL program that works on some machines, but fails to link on on one particular machine. I suspect a driver bug, but hope that someone will recognize something I'm doing as being poorly supported, and suggest an alternative.
If I omit the geometry shader, the vertex and fragment shaders link successfully.
The error log after the link error says:
Vertex shader(s) failed to link, fragment shader(s) failed to link, geometry shader(s) failed to link.
ERROR: error(#275) Symbol 'gl_AtiVertexData' is defined with 2 different types between two stages
ERROR: error(#275) Symbol 'gl_AtiVertexData' is defined with 2 different types between two stages
ERROR: error(#275) Symbol 'gl_AtiVertexData' is defined with 2 different types between two stages
My code does not contain the symbol gl_AtiVertexData, and Google finds no hits for it.
The GL_RENDERER string is "ATI Mobility Radeon HD 4670", GL_VERSION is "3.3.11672 Compatibility Profile Context", and GL_SHADING_LANGUAGE_VERSION is 3.30.
I've trimmed down my shader programs as much as possible, so that they no longer pretend to do anything useful, but still reproduce the problem.
Vertex shader:
#version 330
in vec4 quesaVertex;
out VertexData {
vec4 interpolatedColor;
};
void main()
{
gl_Position = quesaVertex;
interpolatedColor = vec4(1.0);
}
Geometry shader:
#version 330
layout (triangles) in;
layout (triangle_strip, max_vertices=3) out;
in VertexData {
vec4 interpolatedColor;
} gs_in[];
out VertexData {
vec4 interpolatedColor;
} gs_out;
void main() {
gl_Position = gl_in[0].gl_Position;
gs_out.interpolatedColor = gs_in[0].interpolatedColor;
EmitVertex();
gl_Position = gl_in[1].gl_Position;
gs_out.interpolatedColor = gs_in[1].interpolatedColor;
EmitVertex();
gl_Position = gl_in[2].gl_Position;
gs_out.interpolatedColor = gs_in[2].interpolatedColor;
EmitVertex();
EndPrimitive();
}
Fragment shader:
#version 330
in VertexData {
vec4 interpolatedColor;
};
out vec4 fragColor;
void main()
{
fragColor = interpolatedColor;
}
Later information:
When I tried renaming the interface block VertexData to IBlock, then the error message talked about a symbol gl_AtiIBlock instead of gl_AtiVertexData, so that symbol name was a red herring.
If I don't use interface blocks, then the program links correctly. That's a bother, because I'll need to write the vertex or fragment shader differently depending on whether there is a geometry shader between the vertex and fragment shaders, but maybe that's what I need to do.

QGLShaderProgram OpenGL shaders

I'm getting the following error when I try link my fragment shader,
QGLShader::compile(Fragment): 0(4) : error C0000: syntax error, unexpected '.', expecting "::" at token "."
I'm just trying to implement a simple fragment shader that sets colour to be green.
The code for my vertex shader (which is working) file name shader.vert
#version 430
in layout(location=0) vec2 position;
void main()
{
gl_Position = vec4(position, 0.0, 1.0);
}
The code for my fragment shader shader.frag
#version 430
out vec4 finalColour;
void main()
{
finalColour = vec4(0.0, 1.0, 0.0, 1.0);
}
The code that links the QGLShaderProgram mProgram
//Add Shaders
if (!mProgram.addShaderFromSourceFile(QGLShader::Vertex, "shader.vert")) {
error_msg("Vertex shader load failed");
}
if (!mProgram.addShaderFromSourceCode(QGLShader::Fragment, "testShader.frag")) {
error_msg("Fragment shader load failed");
}
if (!mProgram.link()) {
error_msg("Cannot link shaders");
}
mProgram.bind()
The second parameter of addShaderFromSourceCode(, code)
you must provide the content of file not the name of file itself
here you can put this code in a function and use it to load the file
Read whole ASCII file into C++ std::string

GLSL - program link error: Slot 0 unavailable from layout location request

I'm trying to draw a textured quad copying some code from a tutorial but I'm afraid there is a problem with the shaders.
Both the vertex shader and the fragment shader compilation works, but when linking the program I get the error:
ERROR: Active attribute aliasing. Slot 0 unavailable for 'vertex' from
layout location request.
Shouldn't the location of the second vector be (location = 1)?
I use SDL2 window - OpengGL context: OpenGL Version: 4.1 INTEL-10.6.20 (MAC OSX)
These are the shader files:
vertex.glsl
#version 330 core
layout(location = 0) in vec3 vertex;
layout(location = 0) in vec2 uv;
// will be used in fragment shader
out vec2 uv_frag;
void main(){
uv_frag = uv;
gl_Position = vec4(vertex, 1.0);
}
fragment.glsl
#version 330 core
// has to have same name as vertex shader
in vec2 uv_frag;
// our texture
uniform sampler2D tex;
// actual output
// gl_FragColor is deprecated
out vec4 frag_color;
void main(){
frag_color = texture(tex, uv_frag);
}
Well, the situation is very clear. You already gave the answer yourself.
Shouldn't the location of the second vector be (location = 1)?
Yes. Or less specific: it should be something else than 0. Attribute locations must be unique in a single program, for obvious reasons. The code you copied from wherever is just invalid.

JOGL, opengl 4.3, passing color vector from geometry shader, to fragment shader

I am using a book called Opengl SuperBible 6th edition. I am using JOGL 2.5.1 API. Everytihing was working fine, until I created geometry shader (exercise on page 37). When I try to pass color vector from geometry shader to fragment shader, the Java virtual machine crashes. I have also implemented GLSL error check at shader creation and it shows nothing. I really want to know what is the catch here. here is my code from vertex shader to fragment shader. Funny thing is the program crashes only when i send color from geometry shader to fragment shader. If i set color manualy in fragment shader the program works.
VERTEX SHADER:
#version 430 core
layout (location = 0) in vec4 offset;
layout (location = 1) in vec4 color;
out vec4 vs_color;
void main(void){
const vec4 vertices[3] = vec4[3](vec4( 0.25, -0.25, 0.5, 1.0),
vec4(-0.25, -0.25, 0.5, 1.0),
vec4( 0.25, 0.25, 0.5, 1.0));
gl_Position = vertices[gl_VertexID] + offset;
vs_color = color;
}
TESSELATION CONTROL SHADER:
#version 430 core
layout (vertices = 3) out;
in vec4 vs_color[];
out vec4 tsc_color[];
void main(void){
if (gl_InvocationID == 0){
gl_TessLevelInner[0] = 5.0;
gl_TessLevelOuter[0] = 5.0;
gl_TessLevelOuter[1] = 5.0;
gl_TessLevelOuter[2] = 5.0;
}
gl_out[gl_InvocationID].gl_Position = gl_in[gl_InvocationID].gl_Position;
tsc_color[0] = vs_color[0];
}
TESSELATION EVALUATION SHADER:
#version 430 core
layout (triangles, equal_spacing, cw) in;
in vec4 tsc_color[];
out vec4 tse_color[];
void main(void){
gl_Position = (gl_TessCoord.x * gl_in[0].gl_Position +
gl_TessCoord.y * gl_in[1].gl_Position +
gl_TessCoord.z * gl_in[2].gl_Position);
tse_color[0] = tsc_color[0];
}
GEOMETRY SHADER:
#version 430 core
layout (triangles) in;
layout (points, max_vertices = 3) out;
in vec4 tse_color[];
out vec4 geo_color;
void main(void){
int i;
for (i = 0; i < gl_in.length(); i++)
{
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
geo_color = tse_color[0];
}
FRAGMENT SHADER:
#version 430 core
in vec4 geo_color;
out vec4 color;
void main(void){
//color = vec4(0.0f, 0.8f, 1.0f, 1.0f); for manual setting
color = geo_color;
}
THE ERROR THAT OCCURES:
glLinkProgram(<int> 0x6)GLDebugEvent[ id 0x7d1
type Error
severity High: dangerous undefined behavior
source GLSL or extension compiler
msg glLinkProgram failed to link a GLSL program with the following program info log: 'Vertex shader(s) failed to link, tessellation control shader(s) failed to link, tessellation evaluation shader(s) failed to link, geometry shader(s) failed to link, fragment shader(s) failed to link.
Vertex link error: INVALID_OPERATION.
ERROR: error(#275) Symbol "tse_color" is defined with 2 different types between two stages
tessellation control link error: INVALID_OPERATION.
ERROR: error(#275) Symbol "tse_color" is defined with 2 different types between two stages
tessellation evaluation link error: INVALID_OPERATION.
ERROR: error(#275) Symbol "tse_color" is defined with 2 different types between two stages
geometry link error: INVALID_OPERATION.
ERROR: error(#275) Symbol "tse_color" is defined with 2 different types between two stages
fragment link error: INVALID_OPERATION.
ERROR: error(#275) Symbol "tse_color" is defined with 2 different types between two stages
'
when 1401907851402
source 4.4 (Core profile, arb, debug, ES2 compat, ES3 compat, FBO, hardware) - 4.4.12874 Core Profile/Debug Context 14.100.0.0 - hash 0x14e08f00]
Tessellation Evaluation Shaders only output 1 vertex. I do not know why you have declared out vec4 tse_color[];, but that is a mistake.
// out vec4 tse_color[]; // WRONG
out vec4 tse_color; // * Fixed
[...]
// tse_color[0] = tsc_color[0]; // WRONG
tse_color = tsc_color[0]; // * Fixed
Finally, you are only outputting color to a single vertex for every invocation of your control shader, when you should be outputting multiple. To pass your per-vertex color through the control shader, you need the following:
tsc_color [gl_InvocationID] = vs_color [gl_InvocationID];
Now, here is where things get strange... you are only referencing the first color in your patch for each evaluated vertex. I think what you actually want is an input/output variable qualified with patch storage. That will allow you to create exactly 1 instance of the variable shared across all invocations, sort of like a provoking vertex only for tessellation.

Compilation errors using shaders

My application is returning an error:
Fragment shader failed to compile with the following errors:
ERROR: 0:5: error(#132) Syntax error: 'out' parse error
ERROR: error(#273) 1 compilation errors. No code generated
whenever I execute the following code:
fragment.fs
#version 330
in vec4 color
out vec4 fragColor;
void main() {
fragColor = color;
}
vertex.vs
#version 330
layout (location = 0) in vec3 position;
out vec4 color;
uniform float uniformFloat;
void main() {
color = vec4(clamp(position, 0.0, 1.0), 1.0);
gl_Position = vec4(position, 1.0);
}
How could I fix this?
You forgot the semicolon after in vec4 color in the fragment shader.