| 147 | } |
| 148 | |
| 149 | bool Viewer::render() |
| 150 | { |
| 151 | // wipe the drawing surface clear |
| 152 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 153 | |
| 154 | GLint x = 0, y = 0; |
| 155 | int fb_width, fb_width_half, fb_height, fb_height_half; |
| 156 | |
| 157 | std::map<std::string, libfreenect2::Frame*>::iterator iter; |
| 158 | |
| 159 | for (iter = frames.begin(); iter != frames.end(); ++iter) |
| 160 | { |
| 161 | libfreenect2::Frame* frame = iter->second; |
| 162 | |
| 163 | // Using the frame buffer size to account for screens where window.size != framebuffer.size, e.g. retina displays |
| 164 | glfwGetFramebufferSize(window, &fb_width, &fb_height); |
| 165 | fb_width_half = (fb_width + 1) / 2; |
| 166 | fb_height_half = (fb_height + 1) / 2; |
| 167 | |
| 168 | glViewport(x, y, fb_width_half, fb_height_half); |
| 169 | x += fb_width_half; |
| 170 | if (x >= (fb_width - 1)) |
| 171 | { |
| 172 | x = 0; |
| 173 | y += fb_height_half; |
| 174 | } |
| 175 | |
| 176 | float w = static_cast<float>(frame->width); |
| 177 | float h = static_cast<float>(frame->height); |
| 178 | |
| 179 | Vertex bl = { -1.0f, -1.0f, 0.0f, 0.0f }; |
| 180 | Vertex br = { 1.0f, -1.0f, w, 0.0f }; |
| 181 | Vertex tl = { -1.0f, 1.0f, 0.0f, h }; |
| 182 | Vertex tr = { 1.0f, 1.0f, w, h }; |
| 183 | Vertex vertices[] = { |
| 184 | bl, tl, tr, |
| 185 | tr, br, bl |
| 186 | }; |
| 187 | |
| 188 | gl()->glGenBuffers(1, &triangle_vbo); |
| 189 | gl()->glGenVertexArrays(1, &triangle_vao); |
| 190 | |
| 191 | gl()->glBindVertexArray(triangle_vao); |
| 192 | gl()->glBindBuffer(GL_ARRAY_BUFFER, triangle_vbo); |
| 193 | gl()->glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); |
| 194 | |
| 195 | GLint position_attr = renderShader.getAttributeLocation("Position"); |
| 196 | gl()->glVertexAttribPointer(position_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0); |
| 197 | gl()->glEnableVertexAttribArray(position_attr); |
| 198 | |
| 199 | GLint texcoord_attr = renderShader.getAttributeLocation("TexCoord"); |
| 200 | gl()->glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(2 * sizeof(float))); |
| 201 | gl()->glEnableVertexAttribArray(texcoord_attr); |
| 202 | |
| 203 | |
| 204 | if (iter->first == "RGB" || iter->first == "registered") |
| 205 | { |
| 206 | renderShader.use(); |