Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如果我对纹理使用片段着色器,如何绘制红线?_C++_Qt_Opengl - Fatal编程技术网

C++ 如果我对纹理使用片段着色器,如何绘制红线?

C++ 如果我对纹理使用片段着色器,如何绘制红线?,c++,qt,opengl,C++,Qt,Opengl,我正在使用opengl编写一个简单的视频播放器。我使用Qt并遵循它的基本纹理示例。 顶点和片段着色器如下所示: QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this); const char *vsrc = "attribute highp vec4 vertex;\n" "attribute mediump vec4 texCoord;\n"

我正在使用opengl编写一个简单的视频播放器。我使用Qt并遵循它的基本纹理示例。 顶点和片段着色器如下所示:

    QOpenGLShader *vshader = new QOpenGLShader(QOpenGLShader::Vertex, this);
    const char *vsrc =
        "attribute highp vec4 vertex;\n"
        "attribute mediump vec4 texCoord;\n"
        "varying mediump vec4 texc;\n"
        "uniform mediump mat4 matrix;\n"
        "void main(void)\n"
        "{\n"
        "    gl_Position = matrix * vertex;\n"
        "    texc = texCoord;\n"
        "}\n";
    vshader->compileSourceCode(vsrc);

    QOpenGLShader *fshader = new QOpenGLShader(QOpenGLShader::Fragment, this);
    const char *fsrc =
        "uniform sampler2D texture;\n"
        "varying mediump vec4 texc;\n"
        "void main(void)\n"
        "{\n"
        "    gl_FragColor = texture2D(texture, texc.st);\n"
        "}\n";
    fshader->compileSourceCode(fsrc);
我这样做是为了显示一个图像:

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture_cv.cols, texture_cv.rows,  GL_RGB, GL_UNSIGNED_BYTE, texture_cv.data);
//then draw a quad
...

在这之后,我如何在屏幕上绘制几条红线,因为我使用的是片段着色器(我对着色器非常陌生),我无法关闭纹理。

到目前为止,最简单的解决方案是使用不同的着色器程序绘制红线。因为它只画一种纯色,所以很容易。片段着色器可能类似于:

void main()
{
    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
顶点着色器将与您拥有的非常相似,只是它不需要生成纹理坐标。您甚至可以使用现有的顶点着色器

使用多个着色器程序进行渲染是非常常见的。对于每种不同类型的渲染,您都有一个着色器程序,并使用
glUseProgram()
在它们之间切换