@@ -375,13 +375,13 @@ SampleViewer::SampleViewer()
375
375
{
376
376
auto quad_verts =
377
377
vector<float3>{{-0 .5f , -0 .5f , 0 .f }, {-0 .5f , 0 .5f , 0 .0f }, {0 .5f , 0 .5f , 0 .0f }, {0 .5f , -0 .5f , 0 .0f }};
378
- m_2d_point_shader = new Shader (" 2D point shader" , " shaders/point_instance .vert" ,
379
- " shaders/point_instance.frag " , Shader::BlendMode::AlphaBlend);
378
+ m_2d_point_shader = new Shader (" 2D point shader" , " shaders/point .vert" , " shaders/point.frag " ,
379
+ Shader::BlendMode::AlphaBlend);
380
380
m_2d_point_shader->set_buffer (" vertices" , quad_verts);
381
381
m_2d_point_shader->set_buffer_divisor (" vertices" , 0 );
382
382
383
- m_3d_point_shader = new Shader (" 3D point shader" , " shaders/point_instance .vert" ,
384
- " shaders/point_instance.frag " , Shader::BlendMode::AlphaBlend);
383
+ m_3d_point_shader = new Shader (" 3D point shader" , " shaders/point .vert" , " shaders/point.frag " ,
384
+ Shader::BlendMode::AlphaBlend);
385
385
m_3d_point_shader->set_buffer (" vertices" , quad_verts);
386
386
m_3d_point_shader->set_buffer_divisor (" vertices" , 0 );
387
387
@@ -413,8 +413,8 @@ SampleViewer::SampleViewer()
413
413
HelloImGui::SaveUserPref (" AboutDismissedVersion" , to_string (version_combined ()));
414
414
};
415
415
416
- m_params.callbacks .ShowGui = [this ]() { draw_gui (); };
417
- m_params.callbacks .CustomBackground = [this ]() { draw_scene (); };
416
+ m_params.callbacks .ShowGui = [this ]() { draw_about_dialog (); };
417
+ m_params.callbacks .CustomBackground = [this ]() { draw_background (); };
418
418
m_params.callbacks .AnyBackendEventCallback = [this ](void *event) { return process_event (event); };
419
419
}
420
420
@@ -442,75 +442,6 @@ int2 SampleViewer::get_draw_range() const
442
442
return {start, count};
443
443
}
444
444
445
- void SampleViewer::draw_gui ()
446
- {
447
- auto &io = ImGui::GetIO ();
448
-
449
- m_viewport_pos_GL = m_viewport_pos = {0 , 0 };
450
- m_viewport_size = io.DisplaySize ;
451
- if (auto id = m_params.dockingParams .dockSpaceIdFromName (" MainDockSpace" ))
452
- {
453
- auto central_node = ImGui::DockBuilderGetCentralNode (*id);
454
- m_viewport_size = int2{int (central_node->Size .x ), int (central_node->Size .y )};
455
- m_viewport_pos = int2{int (central_node->Pos .x ), int (central_node->Pos .y )};
456
- // flip y coordinates between ImGui and OpenGL screen coordinates
457
- m_viewport_pos_GL =
458
- int2{int (central_node->Pos .x ), int (io.DisplaySize .y - (central_node->Pos .y + central_node->Size .y ))};
459
- }
460
-
461
- float radius = m_radius / (m_scale_radius_with_points ? std::sqrt (m_point_count) : 1 .0f );
462
-
463
- float4x4 mvp = m_camera[CAMERA_CURRENT].matrix (float (m_viewport_size.x ) / m_viewport_size.y );
464
-
465
- // draw text labels
466
- if (m_view == CAMERA_2D)
467
- {
468
- // draw the text labels for the grid of 2D projections
469
- for (int i = 0 ; i < m_num_dimensions - 1 ; ++i)
470
- {
471
- float4x4 pos = layout_2d_matrix (m_num_dimensions, int2{i, m_num_dimensions - 1 });
472
- float4 text_pos = mul (mvp, mul (pos, float4{0 .f , -0 .5f , -1 .0f , 1 .0f }));
473
- float2 text_2d_pos ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
474
- draw_text (m_viewport_pos + int2 (int ((text_2d_pos.x ) * m_viewport_size.x ),
475
- int ((1 .f - text_2d_pos.y ) * m_viewport_size.y ) + 16 ),
476
- to_string (i), float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[16 ],
477
- TextAlign_CENTER | TextAlign_BOTTOM);
478
-
479
- pos = layout_2d_matrix (m_num_dimensions, int2{0 , i + 1 });
480
- text_pos = mul (mvp, mul (pos, float4{-0 .5f , 0 .f , -1 .0f , 1 .0f }));
481
- text_2d_pos = float2 ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
482
- draw_text (m_viewport_pos + int2 (int ((text_2d_pos.x ) * m_viewport_size.x ) - 4 ,
483
- int ((1 .f - text_2d_pos.y ) * m_viewport_size.y )),
484
- to_string (i + 1 ), float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[16 ],
485
- TextAlign_RIGHT | TextAlign_MIDDLE);
486
- }
487
- }
488
- else
489
- {
490
- int2 range = get_draw_range ();
491
-
492
- // draw the index or coordinate labels around each point
493
- if (m_show_point_nums || m_show_point_coords)
494
- for (int p = range.x ; p < range.x + range.y ; ++p)
495
- {
496
- float4 text_pos = mul (mvp, float4{m_3d_points[p] - 0 .5f , 1 .f });
497
- float2 text_2d_pos ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
498
- int2 draw_pos = m_viewport_pos + int2{int ((text_2d_pos.x ) * m_viewport_size.x ),
499
- int ((1 .f - text_2d_pos.y ) * m_viewport_size.y )};
500
- if (m_show_point_nums)
501
- draw_text (draw_pos - int2{0 , int (radius / 4 )}, fmt::format (" {:d}" , p),
502
- float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[12 ], TextAlign_CENTER | TextAlign_BOTTOM);
503
- if (m_show_point_coords)
504
- draw_text (draw_pos + int2{0 , int (radius / 4 )},
505
- fmt::format (" ({:0.2f}, {:0.2f}, {:0.2f})" , m_3d_points[p].x , m_3d_points[p].y ,
506
- m_3d_points[p].z ),
507
- float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[11 ], TextAlign_CENTER | TextAlign_TOP);
508
- }
509
- }
510
-
511
- draw_about_dialog ();
512
- }
513
-
514
445
void SampleViewer::draw_about_dialog ()
515
446
{
516
447
if (g_open_help)
@@ -1305,7 +1236,7 @@ void SampleViewer::draw_2D_points_and_grid(const float4x4 &mvp, int2 dims, int p
1305
1236
draw_grid (mat, int2{m_custom_line_counts[dims.x ], m_custom_line_counts[dims.y ]}, 1 .f );
1306
1237
}
1307
1238
1308
- void SampleViewer::draw_scene ()
1239
+ void SampleViewer::draw_background ()
1309
1240
{
1310
1241
auto &io = ImGui::GetIO ();
1311
1242
@@ -1321,10 +1252,23 @@ void SampleViewer::draw_scene()
1321
1252
// clear the scene and set up viewports
1322
1253
//
1323
1254
1255
+ // calculate the viewport sizes
1256
+ m_viewport_pos_GL = m_viewport_pos = {0 , 0 };
1257
+ m_viewport_size = io.DisplaySize ;
1258
+ if (auto id = m_params.dockingParams .dockSpaceIdFromName (" MainDockSpace" ))
1259
+ {
1260
+ auto central_node = ImGui::DockBuilderGetCentralNode (*id);
1261
+ m_viewport_size = int2{int (central_node->Size .x ), int (central_node->Size .y )};
1262
+ m_viewport_pos = int2{int (central_node->Pos .x ), int (central_node->Pos .y )};
1263
+ // flip y coordinates between ImGui and OpenGL screen coordinates
1264
+ m_viewport_pos_GL =
1265
+ int2{int (central_node->Pos .x ), int (io.DisplaySize .y - (central_node->Pos .y + central_node->Size .y ))};
1266
+ }
1267
+
1324
1268
// first clear the entire window with the background color
1325
1269
// display_size is the size of the window in pixels while accounting for dpi factor on retina screens.
1326
- // for retina displays, io.DisplaySize is the size of the window in points (logical pixels)
1327
- // but we need the size in pixels. So we scale io.DisplaySize by io.DisplayFramebufferScale
1270
+ // for retina displays, io.DisplaySize is the size of the window in points (logical pixels)
1271
+ // but we need the size in pixels. So we scale io.DisplaySize by io.DisplayFramebufferScale
1328
1272
auto display_size = int2{io.DisplaySize } * int2{io.DisplayFramebufferScale };
1329
1273
CHK (glViewport (0 , 0 , display_size.x , display_size.y ));
1330
1274
CHK (glClearColor (m_bg_color[0 ], m_bg_color[1 ], m_bg_color[2 ], 1 .f ));
@@ -1420,6 +1364,26 @@ void SampleViewer::draw_scene()
1420
1364
for (int y = 0 ; y < m_num_dimensions; ++y)
1421
1365
for (int x = 0 ; x < y; ++x, ++plot_index)
1422
1366
draw_2D_points_and_grid (mvp, int2{x, y}, plot_index);
1367
+
1368
+ // draw the text labels for the grid of 2D projections
1369
+ for (int i = 0 ; i < m_num_dimensions - 1 ; ++i)
1370
+ {
1371
+ float4x4 pos = layout_2d_matrix (m_num_dimensions, int2{i, m_num_dimensions - 1 });
1372
+ float4 text_pos = mul (mvp, mul (pos, float4{0 .f , -0 .5f , -1 .0f , 1 .0f }));
1373
+ float2 text_2d_pos ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
1374
+ draw_text (m_viewport_pos + int2 (int ((text_2d_pos.x ) * m_viewport_size.x ),
1375
+ int ((1 .f - text_2d_pos.y ) * m_viewport_size.y ) + 16 ),
1376
+ to_string (i), float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[16 ],
1377
+ TextAlign_CENTER | TextAlign_BOTTOM);
1378
+
1379
+ pos = layout_2d_matrix (m_num_dimensions, int2{0 , i + 1 });
1380
+ text_pos = mul (mvp, mul (pos, float4{-0 .5f , 0 .f , -1 .0f , 1 .0f }));
1381
+ text_2d_pos = float2 ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
1382
+ draw_text (m_viewport_pos + int2 (int ((text_2d_pos.x ) * m_viewport_size.x ) - 4 ,
1383
+ int ((1 .f - text_2d_pos.y ) * m_viewport_size.y )),
1384
+ to_string (i + 1 ), float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[16 ],
1385
+ TextAlign_RIGHT | TextAlign_MIDDLE);
1386
+ }
1423
1387
}
1424
1388
else
1425
1389
{
@@ -1459,6 +1423,29 @@ void SampleViewer::draw_scene()
1459
1423
1460
1424
if (m_show_fine_grid)
1461
1425
draw_trigrid (m_grid_shader, mvp, 0 .2f , int2x3{m_point_count});
1426
+
1427
+ //
1428
+ // draw the index or coordinate labels around each point
1429
+ //
1430
+ int2 range = get_draw_range ();
1431
+ float radius = m_radius / (m_scale_radius_with_points ? std::sqrt (m_point_count) : 1 .0f );
1432
+
1433
+ if (m_show_point_nums || m_show_point_coords)
1434
+ for (int p = range.x ; p < range.x + range.y ; ++p)
1435
+ {
1436
+ float4 text_pos = mul (mvp, float4{m_3d_points[p] - 0 .5f , 1 .f });
1437
+ float2 text_2d_pos ((text_pos.x / text_pos.w + 1 ) / 2 , (text_pos.y / text_pos.w + 1 ) / 2 );
1438
+ int2 draw_pos = m_viewport_pos + int2{int ((text_2d_pos.x ) * m_viewport_size.x ),
1439
+ int ((1 .f - text_2d_pos.y ) * m_viewport_size.y )};
1440
+ if (m_show_point_nums)
1441
+ draw_text (draw_pos - int2{0 , int (radius / 4 )}, fmt::format (" {:d}" , p),
1442
+ float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[12 ], TextAlign_CENTER | TextAlign_BOTTOM);
1443
+ if (m_show_point_coords)
1444
+ draw_text (draw_pos + int2{0 , int (radius / 4 )},
1445
+ fmt::format (" ({:0.2f}, {:0.2f}, {:0.2f})" , m_3d_points[p].x , m_3d_points[p].y ,
1446
+ m_3d_points[p].z ),
1447
+ float4 (1 .0f , 1 .0f , 1 .0f , 0 .75f ), m_regular[11 ], TextAlign_CENTER | TextAlign_TOP);
1448
+ }
1462
1449
}
1463
1450
}
1464
1451
catch (const std::exception &e)
0 commit comments