5
\$\begingroup\$

I am trying to draw over a GL_TRIANGLE_FAN one texture to render video frames, using shaderProgram1, and render above it some points (GL_POINTS) using shaderProgram2.

By this way: (OpenGL Core 4.3)

void GLViewer::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(handleShaderProg1);

    glUniform...(); //Set Uniforms for shaderProg1... <-- FIXED

    glBindTexture(GL_TEXTURE_2D, textureHandle); //Bind texture
    glBindVertexArray(vaoHandle1); //Bind VAO
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glBindVertexArray(0); //Unbind VAO      
    glBindTexture(GL_TEXTURE_2D, 0); //Unbind texture (used in shaderProg1)

    glUseProgram(handleShaderProg2);    

    glUniform...(); //Set Uniforms for shaderProg2... <-- FIXED

    glBindVertexArray(vaoHandle2);  //Bind VAO
    glDrawArrays(GL_POINTS, 0, 25);     
    glBindVertexArray(0);  //Unbind VAO
}

But only the points defined in vbo2 are rendered over the black glClearColor. Without using the shaderProgram2, all are rendered, texture and the points above it.

Is mandatory to use a FBO and two pass deferred rendering? If not, what could be the problem?


SOLVED : After an OpenGL debugging, I discovered a newbie bug...

In my case, I needed to pass the uniforms to the shader every time the current shader program will be changed to another shader program. I was thinking that the uniform variables will keep alive after another call to glUseProgram. I was wrong...

\$\endgroup\$
4
  • \$\begingroup\$ Show us texture->bind(), texture->unbind() and vbo*->render() definitions. We need to know raw GL calls. To debug rendering issues, you could use graphics debugger tools, to see exact GL calls order. For example, NSight if you have NVidia GPU. \$\endgroup\$ Jun 10, 2015 at 14:59
  • \$\begingroup\$ Thanks for your help. I have included the OpenGL calls and edited some errata. I have a nVidia GTX 960, I know the existence of the Nsight debugger but I never have used it. Maybe this is the moment to start using it. :-) \$\endgroup\$
    – JHH
    Jun 10, 2015 at 15:24
  • \$\begingroup\$ Hello! I have removed the "solved" tag from the title of this question; you might want to post an answer with the solution you have come up with, and mark it as the accepted answer :) \$\endgroup\$
    – Vaillancourt
    Nov 27, 2020 at 17:25
  • \$\begingroup\$ Nope, in principle shader uniforms are persistent between calls even if you switch between shaders with different interfaces. They are set only when they change in the application. Some live eternally (e.g. constants for calculations like pi), some change every frame (e.g. view matrix), or every time they need updating. There must be more to your problem. \$\endgroup\$
    – user144188
    Nov 27, 2020 at 19:35

1 Answer 1

-1
\$\begingroup\$

After you are done with the first VAO call glUseProgram(0);. Same applies for the second VAO.

void GLViewer::paintGL()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glUseProgram(handleShaderProg1);
    glBindTexture(GL_TEXTURE_2D, textureHandle); //Bind texture
    glBindVertexArray(vaoHandle1); //Bind VAO
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
    glBindVertexArray(0); //Unbind VAO      
    glBindTexture(GL_TEXTURE_2D, 0); //Unbind texture (used in shaderProg1)

    glUseProgram(0);

    glUseProgram(handleShaderProg2);        
    glBindVertexArray(vaoHandle2);  //Bind VAO
    glDrawArrays(GL_POINTS, 0, 25);     
    glBindVertexArray(0);  //Unbind VAO


    glUseProgram(0);
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ I can't call glUseProgram(0) because in OpenGL 3.1+ Core profile, it will get a GL_INVALID_OPERATION error. Core OpenGL must allways have a program. \$\endgroup\$
    – JHH
    Jun 11, 2015 at 12:03

You must log in to answer this question.

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