Member Avatar

I need help in my application development.
I'm actualy working on editor for simple 3D App, and I need to add window for rendering 3D content into the editor. But as many of you know, 3D apps have the while loop keep rendering. So if I create main editor window and the the 3D content window, how can I set up the 3D App so everytime ESC is pressed, the mouse and control will be given to main editor window. I thought about some thread, but then I need to "pause" it everytime ESC is pressed. Is any way how to pause the thread in C++ ?

Recommended Answers

All 5 Replies

MS-Windows: Sleep(milliseconds) -- *nix: usleep(milliseconds).

I'm quite sure he asked how to test keypress in while but I have no idea how to do it while( now)

It depends what kind of graphics library you are using. I personally have only ever used openGL on because that is portable, but it seems like you aren't using that, or are not using a standard graphics library at all, not that I know all that much about them.

One way of doing it, and this might not fit well into how your code is structured:

while (1) {
   //drawing for the 3D app

   //when esc is pressed

Where return conceivably brings you back to the section of the code that handles the editor. The assumption I'm making is that you can call at will the function that does the 3D rendering loop, but that may be a bad assumption without knowing the code. I would put the 3D rendering commands into a separate function that you can call from the main app, so that you can return to it at your leisure.

Member Avatar

The rendering loop is fully automatic, but I can do something like this:

// startup sequence

// while loop
while (true)
    if ( /* ESC pressed */ )

if ( /* escaping main editor */ )
    // clear sequence

so eveytime the ESC is pressed in 3D Window, rendering process will be broken, but one thing that I still don't know is, how can I after the rendering loop broke bring mouse to the main editor Window, I think to focus the Window, so the 3D Window will be inactive until I click it.

Well that depends on what you're using to do all this windowing and graphics work. I happen to only use OpenGL/glut which is windowing system agnostic, which means its not always possible to fully control where the mouse is displayed, but whatever your using (I'm assuming something MS related, which I don't have any experience with) might be able to physically move the cursor. As far as making the editor the main window that should be easy as long as whatever API you're using has something akin to glutSetWindow(int) where int is a window ID. Like I said, I don't know other API's very well, but I do know that it is possible to do this, you just need to know what you're using well enough.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.