glShaderSource();
This is my file to char conversion function…
char **convToChar(const char *file_path){
FILE *file;
file = fopen(file_path, "rb");
unsigned int length;
char *buffer;
if(file){
fseek(file, 0, SEEK_END);
length = ftell(file);
buffer = malloc(length + 1);
fseek(file, 0, SEEK_SET);
//buffer = calloc(length, sizeof(char));
fread(buffer, length, 1, file);
fclose(file);
buffer[length] = '\0';
printf("%s", buffer);
}
char **dp_buffer = &buffer;
return dp_buffer;
}
I can just use this function to send my shader code to ‘glShaderSource’ function.
const GLchar *vertexShaderCode = *convToChar("shader/vertexshader.myextension");
glShaderSource(vertexShaderID, 1, &vertexShaderCode, 0);
Same code for the fragment shader code…
Funny thing is sometimes the debugger says ‘Attached vertex shader is not compiled’ but sometimes it says ‘Attached fragment shader is not compiled’.
This is my shader code but I don’t think there is any problem with it.
#version 430
in layout(location = 0) vec2 position;
void main(){
gl_Position = vec4(position, 0.0, 1.0);
}
So my question is what’s wrong with my code? or is there recommended text to char function? could you share it please? thank you.