Sign in to follow this  

Lesson 10 Question: What is the Main Loop?

Recommended Posts

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

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this