# OpenGL Programming/Basics/Structure
## Setting up a New Project

Depending on which app you plan to code in, you might need to set up a new C++ project before you begin. The instructions for this vary based on the program, so check your program's manual if you are unsure about how to do this.

## GLUT

Many OpenGL applications take advantage of a cross-platform (Windows, Mac and Linux compatible) toolkit called GLUT, which is used in conjunction with OpenGL. GLUT is used to draw windows and handle mouse and keyboard events, which OpenGL cannot do on its own. There are alternatives to GLUT, but GLUT is the simplest GUI toolkit that runs cross-platform, so we assume you have GLUT installed.
There are many disadvantages to GLUT, which are related to its inflexibility. Since GLUT has to work the same across three very different operating systems, you don't have any platform-specific features. GLUT itself cannot take advantage of operating-system provided widgets (buttons, pulldown menus). Your application will not be able to change window-level menus (although context-menus can be customized). If these limitations are dealbreakers for your project, you'll have to use an alternative to GLUT. These will be discussed later in this wikibook. For now, just sit tight with GLUT.

## My First OpenGL Program

Open up (or create) your main.cpp file. You should be familiar with the basic format of this file:

### Including the OpenGL Headers

We're going to need to add some includes here, so we can use OpenGL in our application. Depending on how and where you installed OpenGL, you might have to tweak these paths a bit.
This includes the basic OpenGL commands, GLUT and a utility toolkit called GLU which is useful later. Note that if your operating system handles filenames case sensitive (e.g. Linux) you must capitalize the GL before compiling.
If using Visual Studio, make sure to include windows.h before any of the OpenGL headers.

### Creating a Window

Now that we have our library, we can begin to design our interface by creating our window inside our int main function:
We first call glutInit, which starts up GLUT for our use. Next, we set up a display mode. For now, just use the settings we've provided here for glutInitDisplayMode. You might tweak these settings later. Then we tell GLUT how big we want our window to be; 800 by 600 is OK for now. Finally, we actually create the window with glutCreateWindow, passing the window title as an argument, and give control of our program to GLUT through glutMainLoop. Never forget to call glutMainLoop when you use GLUT!
You might have noticed something so far: every function is prefixed with glut-. When we start actually using OpenGL itself, every function will be prefixed with just a gl-. This is for organization.
Try compiling this application. Hopefully, you should get an 800x600 window with the title Hello World. If you don't, refer to the installation section of this wikibook and consider reinstalling.

### Getting Ready to Draw Stuff

Most simple OpenGL applications consist of only three elements:
* A setup function, which configures everything before you start actually drawing.
* A display function, which does the actual drawing, and
* int main, which we've mostly configured above. int main just calls the setup function, and tells GLUT to use the display function when it needs to.
Some OpenGL code might look sort of like this:
This code itself doesn't draw anything, since display is empty.
Next Chapter OpenGL_Programming/Basics/Rectangles