Results 1 to 4 of 4

Thread: Just a quick question about getting data from a shader?

  1. #1
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    2

    Smile 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
    Code :
    VertexShaderCode += "\n" + Line;
    My first assumption was it's for adding a new line whilst adding white space to the string perhaps?:

    Code :
    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 += "\n" + Line;
    			VertexShaderStream.close();
    		}
    	// Function not finished below for obvious reasons.
    }

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,135
    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.

  3. #3
    Newbie Newbie
    Join Date
    Feb 2014
    Posts
    2
    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.

  4. #4
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    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

    Code :
    (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"

    Code :
    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"


Similar Threads

  1. Quick FBO question....
    By scratt in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 11-01-2008, 03:27 AM
  2. Quick question on data transfer
    By Freelancer in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-10-2004, 08:42 AM
  3. Quick Question:
    By Krak in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-05-2003, 09:24 PM
  4. quick question
    By ArchMiffo in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-16-2002, 01:48 PM
  5. Quick Question.....
    By in forum OpenGL: User Software
    Replies: 0
    Last Post: 10-26-2001, 01:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean