Jump to content

  • Log In with Google      Sign In   
  • Create Account

Lesson 10 Question: What is the Main Loop?

  • You cannot reply to this topic
2 replies to this topic

#1 Cydriic   Members   -  Reputation: 132


Posted 20 June 2014 - 07:53 PM

Hi Everyone,


I'm done with Lesson 10, but there is something I don't understand.


Where is the Main Loop in the Code? Where does it start and end?


I know the program ends if anything returns FALSE, but I just don't see where the Loop is Located.


We initialize the Texture system and we setup the world by reading the World File, we also Initialize OpenGL and Create the Window.


I guess those previous functions are only ran once...


Then we have three functions, we Draw our Scene and then we read and deal with the Windows Events. Are these the Loops? If so what determines that?




Thanks guys. Love the Tutorials.

Edited by Cydriic, 20 June 2014 - 07:54 PM.


#2 Servant of the Lord   Crossbones+   -  Reputation: 17334


Posted 20 June 2014 - 08:36 PM

Normally, a C or C++ program enters a function called 'int main(int argc, char *argv[])' or WinMain(...), or equivalent. That special function is known as the "entrypoint" and is where control is first passed to your program. When that main function returns, then your program ends.


The "main loop" is a concept - the idea that things like games loop around continually until they are ready to exit. When they are ready, they end the loop and let the main() function return. This loop doesn't have to be an actual for() or while() loop, though it often is.


Sometimes, when using certain game engines or certain graphical or GUI libraries, the libraries or engines handle the loop for you behind the scenes.


The NEHE tutorials (which are very outdated - I've heard this is a better tutorial, but can't personally comment on it), use Win32 (Microsoft Window's API), so the entry point function is called WinMain(), and is semi-explained in NEHE tutorial 1.

It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.

[Fly with me on Twitter] [Google+] [My broken website]

All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.                                                                                                                                                       [Need free cloud storage? I personally like DropBox]

Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

#3 Cydriic   Members   -  Reputation: 132


Posted 20 June 2014 - 08:55 PM

Thank You so Much, Understood! :)