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