Note that there are some explanatory texts on larger screens.

plurals
  1. POUnable to link compiled shaders (GLSL)
    primarykey
    data
    text
    <p>I have a small class that allows me to load shaders and use them in my program. I am able to compile the shaders, but when it's time to link them, they just don't want to. Using glGetProgramInfoLog I got the following error log. I don't understand why it tells me that there are no program defined since the compilation worked fine...</p> <pre><code>Vertex info ----------- (0) : error C3001: no program defined Fragment info ------------- (0) : error C3001: no program defined </code></pre> <p>The code below does the GLSL linking:</p> <pre><code>program_ = glCreateProgramObjectARB(); if (vertex_) { glAttachObjectARB(program_, vertex_); } if (fragment_) { glAttachObjectARB(program_, fragment_); } glLinkProgramARB(program_); </code></pre> <p>vertex_ and fragment_ are the vertex and fragment shader, and program_ is the ProgramObjectARB.</p> <p>I'd like to know what are the necessary modifications I need to do in order to make this run.</p> <p>Vertex shader:</p> <pre><code>varying vec4 OCPosition; // surface positon in world's coordinates varying vec4 ECposition; // surface position in eye coordinates varying vec4 ECballCenter; // ball center in eye coordinates uniform vec4 BallCenter; // ball center in modelling coordinates void main() { OCPosition = gl_Vertex; ECposition = gl_ModelViewMatrix * OCPosition; ECballCenter = gl_ModelViewMatrix * BallCenter; gl_Position = gl_ProjectionMatrix * ECposition; } </code></pre> <p>Fragment shader:</p> <pre><code>varying vec4 OCPosition; // surface position in world coordinates varying vec4 ECposition; // surface position in eye coordinates varying vec4 ECballCenter; // ball center in eye coordinates uniform vec4 LightDir; // light direction, should be normalized uniform vec4 HVector; // reflection vector for infinite light source uniform vec4 SpecularColor; uniform vec4 BaseColor, StripeColor; uniform float StripeWidth; // = 0.3 uniform float FWidth; // = 0.005 void main() { vec3 normal; // Analytically computed normal vec4 p; // Point in shader space vec4 surfColor; // Computed color of the surface float intensity; // Computed light intensity vec4 distance; // Computed distance values float inorout; // Counter for computing star pattern p.xyz = normalize(OCPosition.xyz); // Calculate p p.w = 1.0; distance.y = StripeWidth - abs(p.z); distance.xy = smoothstep(-FWidth, FWidth, distance.xy); surfColor = mix(BaseColor, StripeColor, distance.y); // normal = point on surface for sphere at (0,0,0) normal = normalize(ECposition.xyz - ECballCenter.xyz); // Per fragment diffuse lighting intensity = 0.2; // ambient intensity += 0.8 * clamp(dot(LightDir.xyz, normal), 0.0, 1.0); surfColor *= intensity; // Per fragment specular lighting intensity = clamp(dot(HVector.xyz, normal), 0.0, 1.0); intensity = pow(intensity, SpecularColor.a); surfColor += SpecularColor * intensity; gl_FragColor = surfColor; } </code></pre> <p><strong>EDIT - SOLUTION</strong> It seems the method I used to read the source file was incorrect. The shader would compile, but at linking, it was not working correctly. Now I use this method to read my file and the linking is correct:</p> <pre><code>char *textFileRead(char *fn) { FILE *fp; char *content = NULL; int count=0; if (fn != NULL) { fp = fopen(fn,"rt"); if (fp != NULL) { fseek(fp, 0, SEEK_END); count = ftell(fp); rewind(fp); if (count &gt; 0) { content = (char *)malloc(sizeof(char) * (count+1)); count = fread(content,sizeof(char),count,fp); content[count] = '\0'; } fclose(fp); } } return content; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload