Fragment shader does not show any colour when compiled with vs2013

95 views Asked by At

When compiled with vs2010, the fragment shader works, but when I compiled and run in vs 2013, it's grey.

My fragment shader converts the yuv texture into rgb

Below is my fragment code

    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);

This is my texture code, I receive linesize and yuv frame data from ffmpeg and make into texture. Everything works fine in VS 2010 computer, but when compiled and run in vs2013 computer, it is grey (black n white), no colour

    /* 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

There are 0 answers