Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Loading Shaders from File

Threaded View

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2012

    Loading Shaders from File

    This is more of a basic C/C++ question. I'm using ifstream to read from a text file the shader program. glShaderSource needs that shader code in the form of GLchar **. Is there anyway to get a const char * array that is just large enough to hold all the lines in the code? Or is there some other way I'm not seeing?

    fstream shaderFile( filePath, ios::in );

    if ( shaderFile.is_open() )
    std::stringstream buffer;
    buffer << shaderFile.rdbuf();
    shader = buffer.str();
    That's basically what I'm doing and I'm passing shader.c_str(). However, the shader is failing to compile. One thing I don't understand though, if my shaders are failing to link and compile (and they obviously are since my triangles are not being colored blue), but I'm still getting two white triangles. I thought shaders were needed to do everything in the core profile?

    // load and compile vertex shader
    string shaderProgramText;
    const char* text = getShaderProgram( shaderInfo.vShaderFile, shaderProgramText );
    GLint length = shaderProgramText.size();
    glShaderSource( GL_VERTEX_SHADER, 1, (const GLchar**)&text, (GLint*)&length );
    glCompileShader( shaderObject );
    I've also checked my c_str, and it has all the shader code with newlines. Should I be inserting '\0' and setting the last parameter of glShaderSource to NULL instead?

    I used glGetShaderiv and got:

    Shader compilation failed...
    (0) : error C0000: syntax error, unexpected $end at token "<EOF>"

    What does this mean?
    Last edited by Qoheleth; 12-17-2012 at 12:46 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