954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need to "pause" „while“ loop

Hello,
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++ ?

Thew
Junior Poster in Training
61 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

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

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

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

Cybulski
Light Poster
47 posts since Apr 2008
Reputation Points: 15
Solved Threads: 3
 

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
   break;
}
return;


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.

TacklesMcCaw
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

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

// startup sequence

// while loop
while (true)
{
    renderOneFrame();
    if ( /* ESC pressed */ )
        break;
}

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.

Thew
Junior Poster in Training
61 posts since Jan 2008
Reputation Points: 10
Solved Threads: 0
 

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.

TacklesMcCaw
Newbie Poster
9 posts since Jun 2008
Reputation Points: 10
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You