Results 1 to 2 of 2

Thread: Loading Shaders from File

  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?

  2. #2
    Junior Member Newbie
    Join Date
    Dec 2012
    omg...I'm so stupid. Passed in GL_VERTEX_SHADER to glShaderSource instead of my actual shader object. SOLVED.

Similar Threads

  1. Loading 2 textures in 2 shaders - 1 doesn't work?
    By Jossos in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-27-2014, 05:17 AM
  2. Having trouble loading my shaders from file.
    By inlinevoid in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 04-27-2013, 07:51 PM
  3. Loading BMP file using C++
    By Chayan Vinayak in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-29-2011, 11:07 AM
  4. ASE file loading?????
    By Jon723 in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 08-21-2001, 06:49 AM
  5. TGA File Loading
    By VeRtEX in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-21-2000, 10:01 PM

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