Skip to content

Commit b895374

Browse files
committed
under Windows waiting for user input when some tutorials got opened in a new window
1 parent 7a36f29 commit b895374

7 files changed

Lines changed: 79 additions & 5 deletions

File tree

tutorials/bvh_access/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
## SPDX-License-Identifier: Apache-2.0
33

44
ADD_EXECUTABLE(bvh_access ../../kernels/embree.rc bvh_access.cpp)
5-
TARGET_LINK_LIBRARIES(bvh_access embree math sys tasking ${GLFW_LIBRARY})
5+
TARGET_LINK_LIBRARIES(bvh_access embree math sys tasking tutorial ${GLFW_LIBRARY})
66
SET_PROPERTY(TARGET bvh_access PROPERTY FOLDER tutorials/single)
77
SET_PROPERTY(TARGET bvh_access APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")
88
INSTALL(TARGETS bvh_access DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT examples)

tutorials/bvh_access/bvh_access.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,10 @@ namespace embree
233233
/* cleanup */
234234
rtcReleaseScene (scene);
235235
rtcReleaseDevice(device);
236+
237+
/* wait for user input under Windows when opened in separate window */
238+
waitForKeyPressedUnderWindows();
239+
236240
return 0;
237241
}
238242
}

tutorials/bvh_builder/bvh_builder.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ namespace embree
1616

1717
}
1818

19-
int main(int argc, char** argv) {
20-
return embree::Tutorial().main(argc,argv);
19+
int main(int argc, char** argv)
20+
{
21+
int code = embree::Tutorial().main(argc,argv);
22+
23+
/* wait for user input under Windows when opened in separate window */
24+
embree::waitForKeyPressedUnderWindows();
25+
26+
return code;
2127
}

tutorials/common/tutorial/application.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,36 @@
33

44
#include "application.h"
55

6+
#if defined(_WIN32)
7+
# include <stdio.h>
8+
# include <conio.h>
9+
# include <windows.h>
10+
#endif
11+
612
namespace embree
713
{
814
Application* Application::instance = nullptr;
15+
16+
void waitForKeyPressedUnderWindows()
17+
{
18+
#if defined(_WIN32)
19+
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
20+
21+
CONSOLE_SCREEN_BUFFER_INFO csbi;
22+
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) {
23+
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
24+
return;
25+
}
26+
27+
/* do not pause when running on a shell */
28+
if (csbi.dwCursorPosition.X != 0 || csbi.dwCursorPosition.Y != 0)
29+
return;
30+
31+
/* only pause if running in separate console window. */
32+
printf("\n\tPress any key to exit...\n");
33+
int ch = getch();
34+
#endif
35+
}
936

1037
Application::Application(int features)
1138
: rtcore("start_threads=1,set_affinity=1"), verbosity(0),

tutorials/common/tutorial/application.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace embree
99
{
10+
void waitForKeyPressedUnderWindows();
11+
1012
class Application
1113
{
1214
public:

tutorials/minimal/minimal.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
#include <stdio.h>
66
#include <math.h>
77
#include <limits>
8+
#include <stdio.h>
9+
10+
#if defined(_WIN32)
11+
# include <conio.h>
12+
# include <windows.h>
13+
#endif
814

915
/*
1016
* A minimal tutorial.
@@ -200,6 +206,27 @@ void castRay(RTCScene scene,
200206
printf("Did not find any intersection.\n");
201207
}
202208

209+
void waitForKeyPressedUnderWindows()
210+
{
211+
#if defined(_WIN32)
212+
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);
213+
214+
CONSOLE_SCREEN_BUFFER_INFO csbi;
215+
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) {
216+
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
217+
return;
218+
}
219+
220+
/* do not pause when running on a shell */
221+
if (csbi.dwCursorPosition.X != 0 || csbi.dwCursorPosition.Y != 0)
222+
return;
223+
224+
/* only pause if running in separate console window. */
225+
printf("\n\tPress any key to exit...\n");
226+
int ch = getch();
227+
#endif
228+
}
229+
203230

204231
/* -------------------------------------------------------------------------- */
205232

@@ -220,7 +247,10 @@ int main()
220247
* always make sure to release resources allocated through Embree. */
221248
rtcReleaseScene(scene);
222249
rtcReleaseDevice(device);
223-
250+
251+
/* wait for user input under Windows when opened in separate window */
252+
waitForKeyPressedUnderWindows();
253+
224254
return 0;
225255
}
226256

tutorials/verify/verify.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6029,6 +6029,11 @@ namespace embree
60296029
int main(int argc, char** argv)
60306030
{
60316031
embree::VerifyApplication app;
6032-
return app.main(argc,argv);
6032+
int code = app.main(argc,argv);
6033+
6034+
/* wait for user input under Windows when opened in separate window */
6035+
embree::waitForKeyPressedUnderWindows();
6036+
6037+
return code;
60336038
}
60346039

0 commit comments

Comments
 (0)