Not all shaders have valid object code.

Started by
2 comments, last by kibokun 14 years, 1 month ago
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");
    fragmentSource = ReadShaderFile("minimal_shader.frag");

    vertexShaderHandle = glCreateShader(GL_VERTEX_SHADER);
    fragmentShaderHandle = glCreateShader(GL_FRAGMENT_SHADER);

    glShaderSource(vertexShaderHandle, 1, (const GLchar**)&vertexSource, 0);
    glShaderSource(fragmentShaderHandle, 1, (const GLchar**)&fragmentSource, 0);

    glCompileShader(vertexShaderHandle);
    glCompileShader(fragmentShaderHandle);

    shaderProgramHandle = glCreateProgram();

    glValidateProgram(shaderProgramHandle);

    glAttachShader(shaderProgramHandle, vertexShaderHandle);
    glAttachShader(shaderProgramHandle, fragmentShaderHandle);

    glLinkProgram(shaderProgramHandle);
    glUseProgram(shaderProgramHandle);

Vertex Shader / Fragment Shader

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


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

Advertisement
void 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.
Also, check if shader compilation (and program link) is sucessful, and print compilation infologs to aid debugging.
Quote:Original post by Wavarian
void 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.)

This topic is closed to new replies.

Advertisement