0

I have some OpenGL 2.x code on which I want to run these shaders:

static const char* YUYV_VS = ""
  "#version 150\n"
  "uniform mat4 u_pm;"
  "uniform mat4 u_mm;"
  "in vec4 a_pos;"
  "in vec2 a_tex;"
  "out vec2 v_tex;"

  "void main() {"
  " gl_Position = u_pm * u_mm * a_pos; "
    " v_tex = a_tex;"
  "}"
  "";

static const char* YUYV_FS = ""
  "#version 150\n"
  "uniform sampler2D u_tex;"
  "out vec4 outcol;"
  "in vec2 v_tex;"

  "const vec3 R_cf = vec3(1.164383,  0.000000,  1.596027);"
  "const vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);"
  "const vec3 B_cf = vec3(1.164383,  2.017232,  0.000000);"
  "const vec3 offset = vec3(-0.0625, -0.5, -0.5);"

  "void main() {"
  "  vec3 tc =  texture( u_tex, v_tex ).rgb;"
  "  vec3 yuv = vec3(tc.g, tc.b, tc.r);"
  "  yuv += offset;"
  "  outcol.r = dot(yuv, R_cf);"
  "  outcol.g = dot(yuv, G_cf);"
  "  outcol.b = dot(yuv, B_cf);"
  "  outcol.a = 1.0;"
  "}"
  "";

Trouble is, OpenGL 2.x doesn't support shaders of version 150. Does anyone have an idea how I would back-convert the shaders to 2.x?

uliwitness
  • 8,532
  • 36
  • 58

2 Answers2

3

Use this procedure except start at GLSL 1.50 spec instead of the 1.30 one.

Community
  • 1
  • 1
genpfault
  • 51,148
  • 11
  • 85
  • 139
1

File shader.vsh

uniform mat4 u_pm;
uniform mat4 u_mm;
attribute vec4 a_pos;
attribute vec2 v_tex;

varying vec2 fragmentTextureCoordinates;

void main() {
  gl_Position = u_pm * u_mm * a_pos;
  fragmentTextureCoordinates = v_tex;
}

File shader.fsh

uniform sampler2D u_tex;
varying vec2 fragmentTextureCoordinates;

const vec3 R_cf = vec3(1.164383,  0.000000,  1.596027);
const vec3 G_cf = vec3(1.164383, -0.391762, -0.812968);
const vec3 B_cf = vec3(1.164383,  2.017232,  0.000000);
const vec3 offset = vec3(-0.0625, -0.5, -0.5);

void main() {
  vec3 tc =  texture2D(u_tex, fragmentTextureCoordinates).rgb;
  vec3 yuv = vec3(tc.g, tc.b, tc.r);
  yuv += offset;
  gl_FragColor.r = dot(yuv, R_cf);
  gl_FragColor.g = dot(yuv, G_cf);
  gl_FragColor.b = dot(yuv, B_cf);
  gl_FragColor.a = 1.0;
}

Would that work? You may have to adapt the variables you pass to your program/technique/shaders.

Patrick Lafleur
  • 326
  • 2
  • 6