| 188 | } |
| 189 | |
| 190 | void sample_gl_debug_ui::on_draw() |
| 191 | { |
| 192 | glfwMakeContextCurrent(window); |
| 193 | |
| 194 | int width, height; |
| 195 | glfwGetWindowSize(window, &width, &height); |
| 196 | |
| 197 | glViewport(0, 0, width, height); |
| 198 | glClearColor(0.25f, 0.25f, 0.25f, 1.0f); |
| 199 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
| 200 | |
| 201 | glEnable(GL_CULL_FACE); |
| 202 | glEnable(GL_DEPTH_TEST); |
| 203 | |
| 204 | glEnable(GL_BLEND); |
| 205 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 206 | |
| 207 | const float4x4 projectionMatrix = cam.get_projection_matrix(float(width) / float(height)); |
| 208 | const float4x4 viewMatrix = cam.get_view_matrix(); |
| 209 | const float4x4 viewProjectionMatrix = (projectionMatrix * viewMatrix); |
| 210 | |
| 211 | // Render the offscreen nvg surface |
| 212 | { |
| 213 | std::string text = "Polymer Engine"; |
| 214 | |
| 215 | NVGcontext * nvg = surface->pre_draw(window, 0); |
| 216 | const float2 size = surface->surface_size(); |
| 217 | |
| 218 | nvgSave(nvg); |
| 219 | |
| 220 | nvgBeginPath(nvg); |
| 221 | nvgRect(nvg, 0, 0, size.x, size.y); |
| 222 | nvgFillColor(nvg, nvgRGBAf(0.2f, 0.2f, 0.2f, 1.f)); |
| 223 | nvgFill(nvg); |
| 224 | |
| 225 | surface->draw_text_quick(text, 120, float2(size.x / 2, size.y / 2), nvgRGBAf(1, 1, 1, 1)); |
| 226 | |
| 227 | nvgRestore(nvg); |
| 228 | |
| 229 | surface->post_draw(); |
| 230 | } |
| 231 | |
| 232 | // Reset state changed by nanovg |
| 233 | glViewport(0, 0, width, height); |
| 234 | glEnable(GL_DEPTH_TEST); |
| 235 | |
| 236 | const float4x4 boxModel = (make_translation_matrix({ 0, 6, -10 }) * make_scaling_matrix(float3(8.f, 4.f, 0.1f))); |
| 237 | |
| 238 | // Render the offscreen nvg surface in the world as a small quad to the left |
| 239 | { |
| 240 | const float4x4 nvgSurfaceModel = (make_translation_matrix({ -4, 2, 0 }) * make_rotation_matrix({ 0, 1, 0 }, (float)POLYMER_PI / 2.f)); |
| 241 | nvg_surface_shader.bind(); |
| 242 | nvg_surface_shader.uniform("u_mvp", (viewProjectionMatrix * nvgSurfaceModel)); |
| 243 | nvg_surface_shader.texture("s_texture", 0, surface->surface_texture(0), GL_TEXTURE_2D); |
| 244 | quad_mesh.draw_elements(); |
| 245 | nvg_surface_shader.unbind(); |
| 246 | } |
| 247 |
nothing calls this directly
no test coverage detected