0

I'm trying to rewrite the shader loader I was using, and I keep getting the title error when I try to compile my program. My search of related questions turned up these two topics which suggested that the issue might be with my use of strings, so I tried copying the loaded shaders from string objects to arrays, and it's still happening. Here's the relevant section of my Initialize function:

// Begin shader loading
vertShader = glCreateShader(GL_VERTEX_SHADER);
fragShader = glCreateShader(GL_FRAGMENT_SHADER);

// Vertex shader first
vertShaderCode = loader.read("vs.txt");

char codeHolder[vertShaderCode.size() + 1];
std::size_t length = vertShaderCode.copy(codeHolder, vertShaderCode.size(), 0);
codeHolder[length] = '\0';

const char* tmp1 = codeHolder;

// Compile the vertex shader
glShaderSource(vertShader, 1, &tmp1, NULL);
glCompileShader(vertShader);

This is a little more verbose than is probably necessary, but I was trying to be very explicit so I didn't miss anything.

I know my shader loader class is working fine, because in the section where I'm checking the compilation status and printing out error messages, I added in some code to check to make sure everything was being passed correctly:

//check the compile status
glGetShaderiv(vertShader, GL_COMPILE_STATUS, &shader_status);
if (!shader_status) 
    {
    ofstream fout;
    fout.open("verification.txt");
    fout << vertShaderCode << endl;

    int index = 0;
    while(tmp1[index] != '\0' && index < 1000)
        {
        fout << tmp1[index];
        index++;
        }
    fout << endl;
    index = 0;
    while(codeHolder[index] != '\0' && index < 1000)
        {
        fout << codeHolder[index];
        index++;
        }
    fout.close();

    GLchar InfoLog[1024];
    glGetShaderInfoLog(vertShader, sizeof(InfoLog), NULL, InfoLog);
    fprintf(stderr, "Vertex Shader %d: '%s'\n", vertShader, InfoLog);
    return false;
    }

the "verification.txt" file ends up with three copies of the shader code as I would expect:

attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}
attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}
attributevec3v_position;attributevec3v_color;varyingvec3color;uniformmat4mvpMatrix;voidmain(){gl_Position=mvpMatrix*vec4(v_position,1.0);color=v_color;}

I know the rest of my program works fine, too, as it works perfectly if I just hard code the shaders into my application program.

Thanks in advance, this is super annoying.

Edit: Here's my makefile

# Linux
CC=g++
LIBS= -lglut -lGLEW -lGL

# Compiler flags
CXXFLAGS= -g -Wall -std=c++0x

all: ../bin/Matrix

../bin/Matrix: ../src/main.cpp
    $(CC) $(CXXFLAGS) ../src/main.cpp -o ../bin/Matrix $(LIBS)
Community
  • 1
  • 1
  • `char codeHolder[vertShaderCode.size() + 1];` This is not legal C++. So how does your code compile? – Nicol Bolas Dec 11 '15 at 21:23
  • If that's the case I'm not really sure. I'm using the VMware player to run a Ubuntu distro, and I'm just compiling it with g++. And the program is writing out to "verification.txt" correctly, so it's definitely running. – Gregory Stayner Dec 11 '15 at 21:29
  • @NicolBolas I tried changing it from `char codeHolder[vertShaderCode.size() + 1];` to `char codeHolder[2048];` and it didn't change compilation, or the error that I'm getting at the terminal. – Gregory Stayner Dec 11 '15 at 21:37

0 Answers0