在opengl shader的编写过程中,常用的两种方式是:
- 将shader 定义为字符串,然后使用glShaderSource加载
static const char *vs =
"attribute vec4 vertexIn;\n"
"attribute vec2 textureIn;\n"
"varying vec2 textureOut;\n"
"void main(void)\n"
"{\n"
"gl_Position = vertexIn;\n"
"textureOut = textureIn;\n"
"}\n";
static const char *fs =
"varying vec2 textureOut;\n"
"uniform sampler2D tex_y;\n"
"uniform sampler2D tex_u;\n"
"uniform sampler2D tex_v;\n"
"void main(void)\n"
"{\n"
"vec3 yuv;\n"
"vec3 rgb;\n"
"yuv.x = texture2D(tex_y, textureOut).r;\n"
"yuv.y = texture2D(tex_u, textureOut).r - 0.5;\n"
"yuv.z = texture2D(tex_v, textureOut).r - 0.5;\n"
"rgb = mat3(1, 1, 1, 0, -0.39465, 2.03211, 1.13983, -0.58060, 0) * yuv;\n"
"rgb.x = rgb.x * 2;"
"rgb.y = rgb.x;"
"rgb.z = rgb.x;"
"gl_FragColor = vec4(rgb, 1.0f);\n"
"}\n";
glShaderSource(v, 1, &vs, NULL);
glShaderSource(f, 1, &fs, NULL);
这种方法写起来


4293

被折叠的 条评论
为什么被折叠?



