Skip to content

Commit

Permalink
under Windows waiting for user input when some tutorials got opened i…
Browse files Browse the repository at this point in the history
…n a new window
  • Loading branch information
svenwoop committed Sep 22, 2020
1 parent 7a36f29 commit b895374
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 5 deletions.
2 changes: 1 addition & 1 deletion tutorials/bvh_access/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## SPDX-License-Identifier: Apache-2.0

ADD_EXECUTABLE(bvh_access ../../kernels/embree.rc bvh_access.cpp)
TARGET_LINK_LIBRARIES(bvh_access embree math sys tasking ${GLFW_LIBRARY})
TARGET_LINK_LIBRARIES(bvh_access embree math sys tasking tutorial ${GLFW_LIBRARY})
SET_PROPERTY(TARGET bvh_access PROPERTY FOLDER tutorials/single)
SET_PROPERTY(TARGET bvh_access APPEND PROPERTY COMPILE_FLAGS " ${FLAGS_LOWEST}")
INSTALL(TARGETS bvh_access DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT examples)
Expand Down
4 changes: 4 additions & 0 deletions tutorials/bvh_access/bvh_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ namespace embree
/* cleanup */
rtcReleaseScene (scene);
rtcReleaseDevice(device);

/* wait for user input under Windows when opened in separate window */
waitForKeyPressedUnderWindows();

return 0;
}
}
Expand Down
10 changes: 8 additions & 2 deletions tutorials/bvh_builder/bvh_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ namespace embree

}

int main(int argc, char** argv) {
return embree::Tutorial().main(argc,argv);
int main(int argc, char** argv)
{
int code = embree::Tutorial().main(argc,argv);

/* wait for user input under Windows when opened in separate window */
embree::waitForKeyPressedUnderWindows();

return code;
}
27 changes: 27 additions & 0 deletions tutorials/common/tutorial/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,36 @@

#include "application.h"

#if defined(_WIN32)
# include <stdio.h>
# include <conio.h>
# include <windows.h>
#endif

namespace embree
{
Application* Application::instance = nullptr;

void waitForKeyPressedUnderWindows()
{
#if defined(_WIN32)
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) {
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
return;
}

/* do not pause when running on a shell */
if (csbi.dwCursorPosition.X != 0 || csbi.dwCursorPosition.Y != 0)
return;

/* only pause if running in separate console window. */
printf("\n\tPress any key to exit...\n");
int ch = getch();
#endif
}

Application::Application(int features)
: rtcore("start_threads=1,set_affinity=1"), verbosity(0),
Expand Down
2 changes: 2 additions & 0 deletions tutorials/common/tutorial/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace embree
{
void waitForKeyPressedUnderWindows();

class Application
{
public:
Expand Down
32 changes: 31 additions & 1 deletion tutorials/minimal/minimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
#include <stdio.h>
#include <math.h>
#include <limits>
#include <stdio.h>

#if defined(_WIN32)
# include <conio.h>
# include <windows.h>
#endif

/*
* A minimal tutorial.
Expand Down Expand Up @@ -200,6 +206,27 @@ void castRay(RTCScene scene,
printf("Did not find any intersection.\n");
}

void waitForKeyPressedUnderWindows()
{
#if defined(_WIN32)
HANDLE hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE);

CONSOLE_SCREEN_BUFFER_INFO csbi;
if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) {
printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError());
return;
}

/* do not pause when running on a shell */
if (csbi.dwCursorPosition.X != 0 || csbi.dwCursorPosition.Y != 0)
return;

/* only pause if running in separate console window. */
printf("\n\tPress any key to exit...\n");
int ch = getch();
#endif
}


/* -------------------------------------------------------------------------- */

Expand All @@ -220,7 +247,10 @@ int main()
* always make sure to release resources allocated through Embree. */
rtcReleaseScene(scene);
rtcReleaseDevice(device);


/* wait for user input under Windows when opened in separate window */
waitForKeyPressedUnderWindows();

return 0;
}

7 changes: 6 additions & 1 deletion tutorials/verify/verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6029,6 +6029,11 @@ namespace embree
int main(int argc, char** argv)
{
embree::VerifyApplication app;
return app.main(argc,argv);
int code = app.main(argc,argv);

/* wait for user input under Windows when opened in separate window */
embree::waitForKeyPressedUnderWindows();

return code;
}

0 comments on commit b895374

Please sign in to comment.