1 #include <msp/gl/meshbuilder.h>
2 #include <msp/gl/texture2d.h>
3 #include "sidebysidecombiner.h"
7 const char vs_source[] =
8 "uniform float offset;\n"
9 "varying vec2 texcoord;\n"
12 " gl_Position = vec4(gl_Vertex.x*0.5+offset, gl_Vertex.yzw);\n"
13 " texcoord = gl_Vertex.xy*0.5+0.5;\n"
16 const char fs_source[] =
17 "uniform sampler2D texture;\n"
18 "varying vec2 texcoord;\n"
21 " gl_FragColor = texture2D(texture, texcoord);\n"
29 SideBySideCombiner::SideBySideCombiner(GL::View &view, bool c):
31 shprog(vs_source, fs_source)
33 target_width = view.get_width()/2;
34 target_height = view.get_height()/2;
35 render_aspect = static_cast<float>(target_width)/target_height;
37 left_shdata.uniform("texture", 0);
38 right_shdata.uniform("texture", 0);
42 GL::MeshBuilder bld(mesh);
43 bld.begin(GL::TRIANGLE_STRIP);
51 void SideBySideCombiner::set_cross_eyed(bool c)
54 float m = (cross_eyed ? -0.5f : 0.5f);
55 left_shdata.uniform("offset", -m);
56 right_shdata.uniform("offset", m);
59 void SideBySideCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const
61 GL::Bind bind_shprog(shprog);
63 GL::Bind bind_tex(left);