Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ OpenGL
Hi,
 
I have two infinite loops.
They both have to be running at the same time.
 
When i call one infinite loop. That's it. I'm stuck; I can not call the other infinite loop.
 
Is there another way to solve this problem then having 2 "threads", each running one loop?
 
Thank you for your help.
Posted 27-Feb-12 5:08am
Edited 27-Feb-12 20:19pm
v3
Comments
DontLaughtIMLearning at 27-Feb-12 10:10am
   
The question on top should be: "How to use values generated by one infinite loop in another infinite loop?" I wonder how i can edit my question after having posted it!
Richard MacCutchan at 27-Feb-12 10:29am
   
Click on the "Improve question" link!
SAKryukov at 27-Feb-12 17:37pm
   
Why on Earth?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need separate threads or processes to do this. Why the need for infinite loops? Why don't you want to use separate threads?
  Permalink  
Comments
DontLaughtIMLearning at 27-Feb-12 10:54am
   
One of the loops is glutMainLoop() from "openGL". I have a sphere, growing. The other loop is the value of the radius of the sphere being calculated. The sphere needs to know it's radius value from the second loop, the one calculating the values. I'll just use two threads. Thank you. Was just wondering if there was another method :)
wizardzz at 27-Feb-12 11:00am
   
You could do it with event handlers, but that's still threading. Why is the radius value an infinite loop? Can't you just call a calculate radius function from the sphere growing loop?
enhzflep at 27-Feb-12 11:06am
   
Precisely!
Why someone would want to change the radius of a sphere during the course of it's drawing is beyond me. By definition, the shape would no longer be a sphere.
 
Surely, you'd just get the radius before each and every frame was drawn, as wizardzz said.
Maximilien at 27-Feb-12 14:27pm
   
@enhzflep
When you change the radius of a sphere, it will stay a sphere.
wizardzz at 27-Feb-12 14:29pm
   
Just a headsup, you can reply directly to enhzflep's comment by hitting the reply button on the right side of his post.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

glutMainLoop is the main event loop of a glut OpenGL application; you just have to call it once.
 
You need to define a callback function (usually for the display) that will be called internally from the glutMainLoop function (with the glutDisplayFunc).
 
You will also need to define another callback function when the process is iddle, (use glutIdleFunc).
 
It is in that function that you should update the radius of the sphere, and that radius will (should?) be used in the display function to redraw the sphere with the appropriate radius.
 
(mostly inspired from http://www.lighthouse3d.com/tutorials/glut-tutorial/[^])
  Permalink  
Comments
DontLaughtIMLearning at 28-Feb-12 1:33am
   
Thanks. I have leaning OpenGL for about 2 to 3 weeks. A few things still don't make sense. I'll read you tutorial and post my next question as an OpenGL question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 28 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100