Just a quick question about getting data from a shader?

Hi was just trying not to follow a tutorial and figure out for myself what to do and mostly can read the functions and what they do apart from some parts but something confuses me and I was just wondering what exactly is this for and how you figured that out

VertexShaderCode += "
" + Line;
My first assumption was it's for adding a new line whilst adding white space to the string perhaps?:
GLuint LoadShader(const char *vertex_source, const char * fragment_source)
{
	GLuint VertexShader = glCreateShader(GL_VERTEX_SHADER);
	GLuint FragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
	
	std::ifstream VertexShaderStream(Vertex_source, std::ifstream::in);
	if(VertexShaderStream.is_open())
	{
			std::string line = "";
			while(std::getline(VertexShaderStream,line))
		THIS LINE -->	VertexShaderCode += "
" + Line;
			VertexShaderStream.close();
		}
	// Function not finished below for obvious reasons.
}

Which tutorial is that? GLSL, like C, is almost format free and if well-formed otherwise, there is no need for line-breaks except in very few cases.

What the code does is to simply parse a text-file using a std::ifstream line by line and assemble all lines into a std::string vertexShaderCode. The author could just as well have read the file completely at once.

No offense but that wasn’t very descriptive but thanks for the help : ) , if anyone else could provide more details and descriptions that would be fantastic thanks.

thokra discription seemed pretty clear but I will try to add a little. I think there must be a typo - I assume “Line” and “line” are the same variable


(std::getline(VertexShaderStream,line)

This will read a set of characters from VertexShaderStream until a end of line is found and put it into “line”


VertexShaderCode += "
" + Line; // ? should be variable line

This will append a carriage return "
" and that string “line” to the string VertexShaderCode

As thorka said this is not necessary unless you plan to manipulate the data - for example remove lines or expand a line say that has a key word like “include”