@@ -238,19 +238,17 @@ void GPUDisplayFrontendGlfw::cursorPos_callback(GLFWwindow* window, double x, do
238238
239239void GPUDisplayFrontendGlfw::resize_callback (GLFWwindow* window, int width, int height) { me->ResizeScene (width, height); }
240240
241+ #ifdef GPUCA_O2_LIB
241242void GPUDisplayFrontendGlfw::DisplayLoop ()
242243{
243- #ifdef GPUCA_O2_LIB
244244 ImGui::SetNextWindowPos (ImVec2 (0 , 0 ));
245245 ImGui::SetNextWindowSize (ImVec2 (me->mDisplayWidth , me->mDisplayHeight ));
246246 ImGui::SetNextWindowBgAlpha (0 .f );
247247 ImGui::Begin (" Console" , nullptr , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
248- #endif
249248 me->DrawGLScene ();
250- #ifdef GPUCA_O2_LIB
251249 ImGui::End ();
252- #endif
253250}
251+ #endif
254252
255253int GPUDisplayFrontendGlfw::FrontendMain ()
256254{
@@ -271,6 +269,9 @@ int GPUDisplayFrontendGlfw::FrontendMain()
271269 glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR , GL_MIN_VERSION_MINOR );
272270 glfwWindowHint (GLFW_OPENGL_FORWARD_COMPAT , 0 );
273271 glfwWindowHint (GLFW_OPENGL_PROFILE , mBackend ->CoreProfile () ? GLFW_OPENGL_CORE_PROFILE : GLFW_OPENGL_COMPAT_PROFILE );
272+ #ifdef GPUCA_O2_LIB
273+ mUseIMGui = true ;
274+ #endif
274275 }
275276 mWindow = glfwCreateWindow (INIT_WIDTH , INIT_HEIGHT , DISPLAY_WINDOW_NAME , nullptr , nullptr );
276277 if (!mWindow ) {
@@ -288,7 +289,9 @@ int GPUDisplayFrontendGlfw::FrontendMain()
288289 glfwSetScrollCallback (mWindow , scroll_callback);
289290 glfwSetCursorPosCallback (mWindow , cursorPos_callback);
290291 glfwSetWindowSizeCallback (mWindow , resize_callback);
291- glfwSwapInterval (1 );
292+ if (backend ()->backendType () == GPUDisplayBackend::TYPE_OPENGL ) {
293+ glfwSwapInterval (1 );
294+ }
292295
293296 pthread_mutex_lock (&mSemLockExit );
294297 mGlfwRunning = true ;
@@ -300,16 +303,18 @@ int GPUDisplayFrontendGlfw::FrontendMain()
300303 }
301304
302305#if defined(GPUCA_O2_LIB) && !defined(GPUCA_DISPLAY_GL3W)
303- if (gl3wInit ()) {
306+ if (mUseIMGui && gl3wInit ()) {
304307 fprintf (stderr, " Error initializing gl3w (2)\n " );
305308 return (-1 ); // Hack: We have to initialize gl3w as well, as the DebugGUI uses it.
306309 }
307310#endif
308311
309312#ifdef GPUCA_O2_LIB
310- mCanDrawText = 2 ;
311- if (drawTextFontSize () == 0 ) {
312- drawTextFontSize () = 12 ;
313+ if (mUseIMGui ) {
314+ mCanDrawText = 2 ;
315+ if (drawTextFontSize () == 0 ) {
316+ drawTextFontSize () = 12 ;
317+ }
313318 }
314319#endif
315320
@@ -319,28 +324,33 @@ int GPUDisplayFrontendGlfw::FrontendMain()
319324 }
320325
321326#ifdef GPUCA_O2_LIB
322- ImGui_ImplGlfwGL3_Init (mWindow , false );
323- while (o2::framework::pollGUI (mWindow , DisplayLoop)) {
324- }
325- #else
326- while (!glfwWindowShouldClose (mWindow )) {
327- HandleSendKey ();
328- if (DrawGLScene ()) {
329- fprintf (stderr, " Error drawing GL scene\n " );
330- return (1 );
327+ if (mUseIMGui ) {
328+ ImGui_ImplGlfwGL3_Init (mWindow , false );
329+ while (o2::framework::pollGUI (mWindow , DisplayLoop)) {
331330 }
332- if (backend ()->backendType () == GPUDisplayBackend::TYPE_OPENGL ) {
333- glfwSwapBuffers (mWindow );
331+ } else
332+ #endif
333+ {
334+ while (!glfwWindowShouldClose (mWindow )) {
335+ HandleSendKey ();
336+ if (DrawGLScene ()) {
337+ fprintf (stderr, " Error drawing GL scene\n " );
338+ return (1 );
339+ }
340+ if (backend ()->backendType () == GPUDisplayBackend::TYPE_OPENGL ) {
341+ glfwSwapBuffers (mWindow );
342+ }
343+ glfwPollEvents ();
334344 }
335- glfwPollEvents ();
336345 }
337- #endif
338346
339347 ExitDisplay ();
340348 mDisplayControl = 2 ;
341349 pthread_mutex_lock (&mSemLockExit );
342350#ifdef GPUCA_O2_LIB
343- ImGui_ImplGlfwGL3_Shutdown ();
351+ if (mUseIMGui ) {
352+ ImGui_ImplGlfwGL3_Shutdown ();
353+ }
344354#endif
345355 glfwDestroyWindow (mWindow );
346356 glfwTerminate ();
@@ -365,12 +375,14 @@ void GPUDisplayFrontendGlfw::DisplayExit()
365375void GPUDisplayFrontendGlfw::OpenGLPrint (const char * s, float x, float y, float r, float g, float b, float a, bool fromBotton)
366376{
367377#ifdef GPUCA_O2_LIB
368- if (fromBotton) {
369- y = ImGui::GetWindowHeight () - y;
378+ if (mUseIMGui ) {
379+ if (fromBotton) {
380+ y = ImGui::GetWindowHeight () - y;
381+ }
382+ y -= 20 ;
383+ ImGui::SetCursorPos (ImVec2 (x, y));
384+ ImGui::TextColored (ImVec4 (r, g, b, a), " %s" , s);
370385 }
371- y -= 20 ;
372- ImGui::SetCursorPos (ImVec2 (x, y));
373- ImGui::TextColored (ImVec4 (r, g, b, a), " %s" , s);
374386#endif
375387}
376388
0 commit comments