| 165 | } |
| 166 | |
| 167 | void sample_gl_render_offscreen::on_draw() |
| 168 | { |
| 169 | glfwMakeContextCurrent(window); |
| 170 | |
| 171 | int width, height; |
| 172 | glfwGetWindowSize(window, &width, &height); |
| 173 | |
| 174 | glEnable(GL_CULL_FACE); |
| 175 | glEnable(GL_DEPTH_TEST); |
| 176 | glEnable(GL_BLEND); |
| 177 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 178 | |
| 179 | // Render to framebuffer |
| 180 | { |
| 181 | glBindFramebuffer(GL_FRAMEBUFFER, renderFramebuffer); |
| 182 | glViewport(0, 0, width, height); |
| 183 | glClearColor(0.25f, 0.25f, 0.25f, 1.0f); |
| 184 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 185 | |
| 186 | const float4x4 projectionMatrix = cam.get_projection_matrix(float(width) / float(height)); |
| 187 | const float4x4 viewMatrix = cam.get_view_matrix(); |
| 188 | const float4x4 viewProjectionMatrix = projectionMatrix * viewMatrix; |
| 189 | |
| 190 | auto default_wireframe_variant = wireframe_handle.get()->get_variant(); |
| 191 | auto & wireframe_prog = default_wireframe_variant->shader; |
| 192 | |
| 193 | wireframe_prog.bind(); |
| 194 | for (auto & object : objects) |
| 195 | { |
| 196 | const float4x4 modelMatrix = object.t.matrix() * make_scaling_matrix(object.scale); |
| 197 | wireframe_prog.uniform("u_color", selected_object == &object ? float4(1, 0, 0, 0.5f) : float4(1, 1, 1, 0.5)); |
| 198 | wireframe_prog.uniform("u_eyePos", cam.get_eye_point()); |
| 199 | wireframe_prog.uniform("u_viewProjMatrix", viewProjectionMatrix); |
| 200 | wireframe_prog.uniform("u_modelMatrix", modelMatrix); |
| 201 | object.mesh.draw_elements(); |
| 202 | } |
| 203 | wireframe_prog.unbind(); |
| 204 | |
| 205 | grid.draw(viewMatrix, projectionMatrix, cam.get_eye_point()); |
| 206 | } |
| 207 | |
| 208 | // Render to default framebuffer (the screen) |
| 209 | glBindFramebuffer(GL_FRAMEBUFFER, 0); |
| 210 | glViewport(0, 0, width, height); |
| 211 | glClearColor(1.0f, 0.0f, 0.0f, 1.0f); |
| 212 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 213 | |
| 214 | view->draw(renderTextureRGBA); |
| 215 | |
| 216 | gl_check_error(__FILE__, __LINE__); |
| 217 | |
| 218 | glfwSwapBuffers(window); |
| 219 | } |
| 220 | |
| 221 | int main(int argc, char * argv[]) |
| 222 | { |
nothing calls this directly
no test coverage detected