943,884 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2101
  • C++ RSS
Jun 14th, 2008
0

Need to "pause" „while“ loop

Expand Post »
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++ ?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Thew is offline Offline
61 posts
since Jan 2008
Jun 14th, 2008
0

Re: Need to "pause" „while“ loop

MS-Windows: Sleep(milliseconds) -- *nix: usleep(milliseconds).
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,952 posts
since Aug 2005
Jun 14th, 2008
0

Re: Need to "pause" „while“ loop

I'm quite sure he asked how to test keypress in while but I have no idea how to do it while( now)
Reputation Points: 15
Solved Threads: 3
Light Poster
Cybulski is offline Offline
47 posts
since Apr 2008
Jun 15th, 2008
0

Re: Need to "pause" „while“ loop

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:

C++ Syntax (Toggle Plain Text)
  1. while (1) {
  2. //drawing for the 3D app
  3.  
  4. //when esc is pressed
  5. break;
  6. }
  7. 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.
Last edited by TacklesMcCaw; Jun 15th, 2008 at 1:43 am.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
TacklesMcCaw is offline Offline
9 posts
since Jun 2008
Jun 15th, 2008
0

Re: Need to "pause" „while“ loop

The rendering loop is fully automatic, but I can do something like this:
C++ Syntax (Toggle Plain Text)
  1. // startup sequence
  2.  
  3. // while loop
  4. while (true)
  5. {
  6. renderOneFrame();
  7. if ( /* ESC pressed */ )
  8. break;
  9. }
  10.  
  11. if ( /* escaping main editor */ )
  12. // 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.
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
Thew is offline Offline
61 posts
since Jan 2008
Jun 15th, 2008
0

Re: Need to "pause" „while“ loop

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.
Reputation Points: 10
Solved Threads: 2
Newbie Poster
TacklesMcCaw is offline Offline
9 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: operation overload
Next Thread in C++ Forum Timeline: NEED HELP PROGRAMMING! sorted arrays





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC