# Not all shaders have valid object code.

## Recommended Posts

kibokun    122
I'm trying to attach and run the simplest possible shader, and this is the error I get at runtime. ERROR: Not all shaders have valid object code. My shaders SEEM syntctically correct. It may be a problem with how I'm loading them? File loading function I did not write myself:
   FILE *fptr;
long length;
char *buf;

fptr = fopen(filename, "r"); /* Open file for reading */
if (!fptr) /* Return NULL on failure */
return NULL;
fseek(fptr, 0, SEEK_END); /* Seek to the end of the file */
length = ftell(fptr); /* Find out how many bytes into the file we are */
buf = (char*)malloc(length+1); /* Allocate a buffer for the entire length of the file and a null terminator */
fseek(fptr, 0, SEEK_SET); /* Go back to the beginning of the file */
fread(buf, length, 1, fptr); /* Read the contents of the file in to the buffer */
fclose(fptr); /* Close the file */
buf[length] = 0; /* Null terminator */

return buf; /* Return the buffer */


Calls to set up the shader:
    vertexSource = ReadShaderFile("minimal_shader.vert");


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ VERTEX SHADER
void main()
{
gl_Position = ftransform();
}

void main()
{
gl_FragColor = vec4(1.0, 0.1, 0.1, 1.0);
)



##### Share on other sites
Wavarian    850
void main(){	...) <------

Also you should specify the version of GLSL your shaders are using with "#version XXX". And I hope that you're free'ing the buffer that your file loading function returns.

##### Share on other sites
HuntsMan    368
Also, check if shader compilation (and program link) is sucessful, and print compilation infologs to aid debugging.

##### Share on other sites
kibokun    122
Quote:
 Original post by Wavarianvoid main(){ ...) <------Could this be your problem?Also you should specify the version of GLSL your shaders are using with "#version XXX". And I hope that you're free'ing the buffer that your file loading function returns.

If only that had fixed it. I would have been furious and elated at the same time. :) Thanks for the catch on freeing the buffer. I had that happening somewhere else dangerously far from it's creation. hah.

I'll try writing the infologs to a file. (Can't really see print output since I'm doing this in VS. How annoying.)