我在纹理上使用了opengl着色器。一旦完成纹理着色,我想停止glUseProgram()函数。

目前,着色器将覆盖所有东西,包括我不需要着色的rectf()函数。

我尝试了glUseProgram(0),但是没有用。

相关问题:Java Opengl: Discarding Texture Background with Shaders

这是相关的代码。

        glPushMatrix();
        dirPosd = i.torso.getPosition().mul(30);
        glTranslatef(dirPosd.x, dirPosd.y, 0);
        glRotated(Math.toDegrees(i.torso.getAngle()), 0, 0, 1);
        glColor3f(1,1,1);
        skel_torso.bind();
        sizer = 40;
        glUseProgram(shaderProgram);
        glBegin(GL_QUADS);
        glTexCoord2f(0f, 0f);
        glVertex2f( i.torso.getPosition().x - sizer-5, i.torso.getPosition().y - sizer-5);     //NW
        glTexCoord2f(1, 0);
        glVertex2f( i.torso.getPosition().x + sizer-5, i.torso.getPosition().y - sizer-5);   //NE
        glTexCoord2f(1, 1);
        glVertex2f( i.torso.getPosition().x + sizer-5, i.torso.getPosition().y + sizer-5); //SE
        glTexCoord2f(0, 1);
        glVertex2f( i.torso.getPosition().x - sizer-5, i.torso.getPosition().y + sizer-5);   //SW
        glEnd();
        glPopMatrix();

        glUseProgram(0); //Note here

        glPushMatrix();

        Vec2 shoulderPosL = i.shouldL.getPosition().mul(30);
        glTranslatef(shoulderPosL.x, shoulderPosL.y, 0);
        glRotated(Math.toDegrees(i.shouldL.getAngle()), 0, 0, 1);

        glColor3f(1,1,0);
        glRectf(-i.shoulderSize[0] * 30, -i.shoulderSize[1] * 30, i.shoulderSize[0] * 30, i.shoulderSize[1] * 30);

        glPopMatrix();`


我添加了glUseProgram(0)语句,但是当我添加该着色器时根本不起作用。

最佳答案

您必须切换到其他着色器,完成其他材质渲染的操作。着色器并不是“包裹”在渲染对象上的东西。着色器使渲染工作正常。如果禁用着色器,并且您的OpenGL上下文不是兼容性配置文件,则不会提供默认回退(以固定功能管道行为表示),并且不呈现任何内容。 OTOH您正在使用固定功能管线,但是要使其正常工作,您必须对其进行适当的参数化(启用纹理目标,调制模式,颜色等)。通常,简单地切换着色器而不是使用FF流水线状态比较容易。

10-04 12:12