0
\$\begingroup\$

I'm trying to compile a GLSL shader, to which I use the following code.

Initialization

SDL_Window* boringInitStuff(){
    SDL_Init(SDL_INIT_VIDEO);
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 1 );
    SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );

    Uint32 windowFlags = SDL_WINDOW_OPENGL;
    SDL_Window* sdlWindow = SDL_CreateWindow("Boooring", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 400, 400, windowFlags);

    SDL_GL_CreateContext(sdlWindow);

    glewExperimental = GL_TRUE;
    glewInit();

    return sdlWindow;
}

File parser

void readFile(std::string path, std::string& data){
    std::ifstream f(path.c_str(), std::ios::binary);
    data.assign((std::istreambuf_iterator<char>(f)),
                (std::istreambuf_iterator<char>()));
}

Main

int main(int argv, char** args) {
    SDL_Window* sdlWindow = boringInitStuff();

    std::string buffer;
    readFile("./compile_test.vert", buffer);
    const char* cBuffer = buffer.c_str();

    GLuint shaderID = glCreateShader(GL_VERTEX_SHADER);
    glShaderSource(shaderID, 1, &cBuffer, nullptr);
    glCompileShader(shaderID);

    while(!SDL_QuitRequested()){
        SDL_GL_SwapWindow(sdlWindow);
    }

    return 0;
}

But when I try to inspect the source code in gDEBugger, the source code is gone. Linking of course doesn't work aswell. The weird thing is, that the compilation error checking works. EDIT: When I copy & paste the main part into another opengl project, it works.

\$\endgroup\$
1
  • \$\begingroup\$ "When I copy & paste the main part into another opengl project, it works." This suggests that you haven't yet isolated the problem. Try copying more into the new project until you can reproduce the issue, or create a duplicate of your project that has the issue and remove stuff until the issue disappears. Either way will help you identify a minimal, complete, verifiable example that others can reproduce. \$\endgroup\$
    – DMGregory
    Commented Oct 2, 2018 at 0:55

1 Answer 1

1
\$\begingroup\$

Creating a new Project in CLion and just copy-pasting the source code fixed the problem. Sadly I still don't exactly know why the error was there in the first place.

EDIT:

Apparently the name I give the project makes the difference. When I give the Project the Name OpenGLTestbed, it does not work, the shaders won't compile correctly. But if I rename the project to anything else, in my case Testbed, it compiles the shaders correctly.

I'm working in CLion with MinGW.

\$\endgroup\$
3
  • \$\begingroup\$ You could save new project under a different location and then compare files for differences .. \$\endgroup\$
    – Kromster
    Commented Oct 2, 2018 at 11:38
  • \$\begingroup\$ Take a look at my edit. @Kromster \$\endgroup\$
    – Kiryu144
    Commented Oct 2, 2018 at 11:46
  • \$\begingroup\$ That's very strange, but good that you have it isolated better. +1 for edit \$\endgroup\$
    – Kromster
    Commented Oct 2, 2018 at 11:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .