使用vs2013编译时,片段着色器不显示任何颜色

时间:2015-06-11 11:25:53

标签: ffmpeg fragment textures rgb yuv

使用vs2010编译时,片段着色器可以正常工作,但是当我在vs 2013中编译并运行时,它是灰色的。

我的片段着色器将yuv纹理转换为rgb

下面是我的片段代码

    const char *FProgram =
    "uniform sampler2D Ytex;\n"
    "uniform sampler2D Utex;\n"
    "uniform sampler2D Vtex;\n"
    "void main(void) {\n"
    "  vec4 c = vec4((texture2D(Ytex, gl_TexCoord[0]).r - 16./255.) * 1.164);\n"
    "  vec4 U = vec4(texture2D(Utex, gl_TexCoord[0]).r - 128./255.);\n"
    "  vec4 V = vec4(texture2D(Vtex, gl_TexCoord[0]).r - 128./255.);\n"
    "  c += V * vec4(1.596, -0.813, 0, 0);\n"
    "  c += U * vec4(0, -0.392, 2.017, 0);\n"
    "  c.a = 1.0;\n"
    "  gl_FragColor = c;\n"
    "}\n";





glClearColor(0, 0, 0, 0);

PHandle = glCreateProgram();
FSHandle = glCreateShader(GL_FRAGMENT_SHADER);



glShaderSource(FSHandle, 1, &FProgram, NULL);
glCompileShader(FSHandle);

glAttachShader(PHandle, FSHandle);
glLinkProgram(PHandle);


glUseProgram(PHandle);
glDeleteProgram(PHandle);
glDeleteProgram(FSHandle);

这是我的纹理代码,我从ffmpeg接收lineize和yuv帧数据并制作纹理。在VS 2010计算机上一切正常,但在vs2013计算机上编译和运行时,它是灰色的(黑色和白色),没有颜色

    /* Select texture unit 1 as the active unit and bind the U texture. */
glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize1);
glActiveTexture(GL_TEXTURE1);
i = glGetUniformLocation(PHandle, "Utex");
glUniform1i(i, 1);  /* Bind Utex to texture unit 1 */
glBindTexture(GL_TEXTURE_2D, 1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width / 2, height / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, frame1);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);


/* Select texture unit 2 as the active unit and bind the V texture. */
glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize2);
glActiveTexture(GL_TEXTURE2);
i = glGetUniformLocation(PHandle, "Vtex");
glUniform1i(i, 2);  /* Bind Vtext to texture unit 2 */
glBindTexture(GL_TEXTURE_2D, 2);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width / 2, height / 2, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, frame2);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);


/* Select texture unit 0 as the active unit and bind the Y texture. */



glPixelStorei(GL_UNPACK_ROW_LENGTH, linesize0);
glActiveTexture(GL_TEXTURE0);
i = glGetUniformLocation(PHandle, "Ytex");
glUniform1i(i, 0);
glBindTexture(GL_TEXTURE_2D, 0);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, width, height, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, frame0);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);



glClear(GL_COLOR_BUFFER_BIT);

/* Draw image (again and again). */

glBegin(GL_QUADS);
glTexCoord2i(0, 0);
glVertex2i(-w / 2, h / 2);
glTexCoord2i(1, 0);
glVertex2i(w / 2, h / 2);
glTexCoord2i(1, 1);
glVertex2i(w / 2, -h / 2);
glTexCoord2i(0, 1);
glVertex2i(-w / 2, -h / 2);
glEnd();

需要指导,提前谢谢!

0 个答案:

没有答案