2

I'm trying to debug some shaders but I can't change the one currently loaded. I tried to run without loading any shader, or linking any program and it still working.

I already tried deleting completely the shaders from my HDD. I tried to just call glUseProgram (with any random number including 0) just before calling glDrawElements and it still work. And even if I load any shader it just doesn't make any effect. It still show linking and compile error if I make mistakes in the files but when run the executable it just ignores what is in the shaders.

I draw the vertex with this

void Renderer::renderFrame() {
    vao.bind();
    glUseProgram(0);
    glDrawElements(GL_LINE_LOOP, 3, GL_UNSIGNED_INT, nullptr);
}

and this are my window hints

void App::start() {
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

    window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 500,500, SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL);
    this->context = SDL_GL_CreateContext(window);
    glewInit();
    glClearColor(0.5,1.0,1.0,1.0);

     renderer.init();
}
JC2H
  • 23
  • 3
  • 2
    In case no valid shader is binded the default fixed function is used (you know GL 1.0 backward compatibility) so in case your attribute locations matches the used fixed function ones your CPU side code still renders image see [What are the Attribute locations for fixed function pipeline in OpenGL 4.0++ core profile?](https://stackoverflow.com/a/20574219/2521214) however the locations are not defined by any standard so it is different for any vendor (and can change with time). Only **nVidia** defined it and still using it after years. – Spektre Apr 09 '19 at 07:38
  • @Spektre: The code explicitly requests a core profile. So it's not able to use fixed-function stuff. – Nicol Bolas Apr 09 '19 at 13:24
  • 2
    @NicolBolas: It requests a core profile for the *next* `SDL_CreateWindow()` call. – genpfault Apr 09 '19 at 14:41
  • I think @Spektre is right. My vertex shader had an error with the layouts locations after fixing it the code work properly. I thought if the shader wasn't right it would throw an error but it looks like it will change to compatibility stuff. – JC2H Apr 14 '19 at 06:49
  • @Spektre Could you publish your first comment as an answer so I can accept it? – JC2H Apr 14 '19 at 07:36
  • @JC2H I moved the comments into answer – Spektre Apr 14 '19 at 10:07

2 Answers2

2

SDL_GL_SetAttribute() only affects the next SDL_CreateWindow() call.

From the doc wiki:

Use this function to set an OpenGL window attribute before window creation.

So right now you're most likely getting a Compatibility context where shader-less draws are perfectly valid. You can check the value of GL_VERSION to see what you're getting.

If you want a Core context make those SDL_GL_SetAttribute() calls before your SDL_CreateWindow():

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
window = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 500,500, SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL);
this->context = SDL_GL_CreateContext(window);
genpfault
  • 51,148
  • 11
  • 85
  • 139
  • Sorry for my code. It was a mistake in the question. In my code the attributes are set before but when I wrote the question I put all in one method for clarity purposes and don't realized I put it after creating the window. – JC2H Apr 14 '19 at 06:44
0

In case no valid shader is binded the default fixed function is usually used (you know GL 1.0 backward compatibility even on core profile sometimes depending on vendor/driver).

So in case your attribute locations matches the used fixed function ones your CPU side code still renders image see:

however the locations are not defined by any standard so it is different for any vendor (and can change with time/driver version). Only nVidia defined it and still using it after years...

So its a good idea to check the GLSL compiler/linker log for any shader in development to avoid confusion ... For more info on how to obtain them see:

btw some gfx drivers support logging and if enabled it will save the GLSL logs into a file on its own... tha can be done for example with nVidia drivers and NVEmulate utility

Spektre
  • 49,595
  • 11
  • 110
  • 380