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\$
  • \$\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\$ – Ivan Aksamentov - Drop Jun 10 '15 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\$ – PijusMagnificus Jun 10 '15 at 15:24
-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
    \$\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\$ – PijusMagnificus Jun 11 '15 at 12:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.