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 &v, bool c):
32 shprog(vs_source, fs_source)
34 target_width = view.get_width()/2;
35 target_height = view.get_height()/2;
36 render_aspect = static_cast<float>(target_width)/target_height;
38 left_shdata.uniform("texture", 0);
39 right_shdata.uniform("texture", 0);
43 GL::MeshBuilder bld(mesh);
44 bld.begin(GL::TRIANGLE_STRIP);
52 void SideBySideCombiner::set_cross_eyed(bool c)
55 float m = (cross_eyed ? -0.5f : 0.5f);
56 left_shdata.uniform("offset", -m);
57 right_shdata.uniform("offset", m);
60 void SideBySideCombiner::render(const GL::Texture2D &left, const GL::Texture2D &right) const
62 GL::Bind bind_shprog(shprog);
64 GL::Bind bind_tex(left);
72 view.get_context().swap_buffers();