char *GLSLShaders::ReturnFileAsString( char *filename ) { /* open the file */ FILE *file = fopen( filename, "r" ); if (!file && verbose) printf("**** Error opening file '%s'\n", filename ); /* get the length of the file */ fseek( file, 0, SEEK_END ); long size = ftell( file ); rewind( file ); /* allocate memory for the shader string */ char *shaderMemory = (char *)calloc( (size+1), sizeof(char) ); if (!shaderMemory) { fclose(file); return 0; } /* read shader data from the file */ long bytesRead = fread (shaderMemory,1,size,file); /* On Windows platforms fread() strips out '\r' characters, so the */ /* number of bytes read is less than the file size. This can */ /* add garbage at the end of the shader if the null-termination */ /* occurs at the end of the buffer, since only part of it may */ /* be filled by fread(). This should fix that. */ size = ( bytesRead < size ? bytesRead : size ); shaderMemory[size] = 0; /* clean up and return the data */ fclose(file); return shaderMemory; }