Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
OutputWowDisplay2.cpp
1 /*
2  * OutputWowDisplay2.cpp
3  *
4  * Created on: Mar 18, 2009
5  * Author: africk
6  */
7 
8 #include "OutputWowDisplay2.hh"
9 
10 using namespace std;
11 using namespace BIAS;
12 
13 OutputWowDisplay2::OutputWowDisplay2(BIAS::glfRenderTarget *out) :
15 {
16  InitShader_();
17 }
18 
20 {
21  // TODO Auto-generated destructor stub
22 }
23 
24 int
26 {
27 
28  string vertexCode =
29  "void main()\r\n"
30  "{\r\n"
31  " gl_TexCoord[0] = gl_MultiTexCoord0;\r\n"
32  " gl_Position = ftransform();\r\n"
33  "}\r\n";
34 // string vertexCode = ""
35 // "varying float disparity;"
36 // "void main () {\n"
37 // " gl_TexCoord[0] = gl_MultiTexCoord0;"
38 // "vec4 v = gl_Vertex;"
39 // ""
40 // ""
41 // "vec4 pos = gl_ModelViewProjectionMatrix * v;"
42 // "v.x= v.x+1;"
43 // "gl_FrontColor = gl_Color;\n"
44 // ""
45 // ""
46 // "vec4 pos_t = gl_ModelViewProjectionMatrix * v;"
47 // ""
48 // //"disparity = abs(pos[0]/pos[3] - pos_t[0]/pos_t[3]);"
49 // "disparity = 0.5;"
50 // ""
51 // "gl_Position = pos;"
52 // "}\n";
53  string fragmentCode = "uniform sampler2D tex;"
54  "uniform sampler2D dep;"
55  "varying float disparity;"
56  "uniform float w;"
57  "uniform float h;"
58  "void main() {"
59  "vec2 pos = gl_TexCoord[0].st;"
60  ""
61  "vec3 color = vec3(0.0,0.0,0.0);"
62  ""
63  // "if (mod(pos[1]*h,2.0) >= 0.5) {"
64  "if (pos[0] < 0.5) {"
65  "color = texture2D(tex,pos);"
66  "} else {"
67  "color = vec3(disparity,disparity,disparity);"
68  "}"
69  // "}"
70  "gl_FragColor.rgb = color;"
71  "}";
72 
73  int res = 0;
74  try
75  {
76 
77  res = GLProjectionOutputAttachment::InitShader(vertexCode, fragmentCode);
78  }
79  catch (glfException& e)
80  {
81  std::cout << "Error: " << e.GetMessageString() << std::endl;
82  BIASABORT;
83  }
84  return res;
85 }
86 
87 int
89 {
90 
91  unsigned char wow_content = 0x02;
92  unsigned char wow_use_factor = 0x80; // 0x00 for default
93  unsigned char wow_use_offset = 0x40; // 0x00 for default
94  unsigned char wow_use_factor_plut_offset = wow_use_factor+wow_use_offset;
95  unsigned char header[] =
96  { 0xF1, wow_content, 50, 0, wow_use_factor_plut_offset, 0x00, 0x00,
97  0x00, 0x00, 0x00 };
98  // Calc the CRC32
99  {
100  unsigned long _register = 0;
101  for (int i = 0; i < 10; ++i)
102  {
103  unsigned char mask = 0x80;
104  unsigned char byte = header[i];
105  for (int j = 0; j < 8; ++j)
106  {
107  bool topBit = (_register & 0x80000000) != 0;
108  _register <<= 1;
109  _register ^= ((byte & mask) != 0 ? 0x1 : 0x0);
110  if (topBit)
111  {
112  _register ^= 0x04c11db7;
113  }
114  mask >>= 1;
115  }
116  }
117  unsigned char *p = (unsigned char*) &_register;
118  for (size_t i = 0; i < 4; ++i)
119  {
120  header[i + 6] = p[3 - i];
121  }
122  }
123 
124  int fullheader[256];
125  {
126  for (int x = 0; x < 256; ++x)
127  {
128  fullheader[x] = 0;
129  }
130  for (int x = 0; x <= 9; ++x)
131  {
132  for (int y = 7; y >= 0; --y)
133  {
134  int i = 2 * (7 - y) + 16 * x;
135  fullheader[i] = (((1 << (y)) & (header[x])) << (7 - (y)));
136  }
137  }
138  }
139 
140  shaderProg_.SetUniform("header", 256, fullheader);
141 
143 }
void SetUniform(const std::string &varName, float value)
int InitShader(std::string vertexCode, std::string fragmentCode)
can be called to create output attachment without having to derive new subclass will also create FBO ...
Exception class used for run-time errors in the OpenGLFramework.
Definition: glfException.hh:79
const std::string & GetMessageString() const
Returns the description of the error including the file name and line number where the error occured...
int StandardDraw_()
this function suffices for simple shaders that only need the standard uniforms to be set...
Class for extra rendering pass in GLProjection (for now only used in glutGLviewer) ...
Interface for render targets.