View Full Version : Just a quick question about getting data from a shader?

02-13-2014, 06:52 PM
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 += "\n" + 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);
std::string line = "";
THIS LINE --> VertexShaderCode += "\n" + Line;
// Function not finished below for obvious reasons.

02-14-2014, 02:07 AM
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.

02-14-2014, 06:45 AM
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.

02-14-2014, 06:42 PM
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


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

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

This will append a carriage return "\n" 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"