-
Notifications
You must be signed in to change notification settings - Fork 5
PEN_2_4
std::string readShaderSource(const char *filePath); This function reads the content of the file specified by filePath and returns the shader source code as a string.
-
filePath:A character string representing the path to the file containing the shader source code.
Returns a std::string containing the shader source code.
-
First, an empty string content is initialized to store the file content.
-
The file is opened using std::ifstream in input mode (std::ios::in).
-
If the file cannot be opened, an error message is printed and an empty string is returned.
-
The file is read line by line using getline and the content is accumulated in the content string, adding a newline at the end of each line.
-
Finally, the file is closed and the read content is returned.
GLuint createShaderProgram(); This function creates a shader program, compiling and linking a vertex shader and a fragment shader, and returns the program identifier.
Returns a GLuint which is the identifier of the created shader program.
-
The source codes of the vertex and fragment shaders are read from the files ./vertex_shader4.glsl and ./fragment_shader4.glsl using the readShaderSource function.
-
The character strings (const char*) are obtained from the read contents.
-
Vertex and fragment shaders are created using glCreateShader.
-
The shader source code is set using glShaderSource.
-
Shaders are compiled using glCompileShader.
-
If there were compilation errors, the error logs are printed using checkOpenGLError and printShaderLog.
-
A shader program is created using glCreateProgram.
-
The shaders are attached to the program using glAttachShader.
-
The program is linked using glLinkProgram.
-
If there were linking errors, the error logs are printed using checkOpenGLError and printShaderLog.
-
Finally, the shader program identifier is returned.