Creating a new C++ project
The Microsoft C++ compiler, like most integrated development
environments, combines source files into a project. And it combines projects into a
"workspace". The projects are a collection of source code and other
resources, such as icons, menus, and other widgets.
When writing programs, you will in many cases find it convenient to use an existing workspace/project to create a new application. Sometimes, of course, you don't want to do this (for instance, if you don't want to overwrite your existing project) and then you will want to create a new project.
This page describes briefly the steps needed to make a new C/C++ project that uses the aux or glut OpenGL library routines. The same steps are used, in fact, for any program which has a main() program as its entry point. We will describe the simplest possible way to do this. For more information consult the online documentation provided with the Microsoft C++ compiler.
Step 1: If you have a workspace currently open, close it from the the File
Then under the File menu, choose New.... A dialog box opens: choose the Projects tab. Select Win32 Console Application as the project type. Choose a project name (something informative, but not too long), and a directory for a location (the C++ compiler will automatically create a folder whose name is the same as the project). Keep Create new workspace and Win32 selected. Press OK.
In the next box, select either Empty Application, Simple Application or Hello-World Application. (Empty Application is probably best.)
Step 2: You may start creating new .c, .cpp,
and .h files in the usual way (use New from the File
menu). Once a source file is created, you must add it to the project.
You do this by selecting the Project menu, then Add to
Project, then Files....
Alternately, instead of creating a new file via the File menu and later adding it to the project, you may create a new file that is already in the project by using the Project menu, then Add to Project, then New....
(By the way, there are various shortcut methods of adding a file to a project: you may try to compile it and it will prompt you to put it in the project. Or you may try right-clicking on the source file window.)
Step 2': Instead of creating a completely new source file, you may
wish modify an existing source file for your new project. (For instance, another
OpenGL program, that you want to modify). To do this, first create a copy of
the source file and put it in your new project directory. Then select
the the Project menu, then Add to Project, then Files...
to add it to the project. Don't forget to use the same procedure for header files.
If you skip the step of making a new copy of the file before adding it to your project, then you will have the same source file in two different projects. If you modify the file for one project, it will also change the other project and in most cases, this is not what you want!
Step 3: If you set your project up the wrong way, you may get compile-time errors about the use of precompiled headers. If this happen, use the Project menu, go to Settings..., then choose the C/C++ tab, select Category Precompiled Headers and turn off precompiled headers.
Step 4: For OpenGL, you need to tell the compiler (or to be precise, the linker) to include the OpenGL libraries. If you do not do this, then you will get lots of error messages about unresolved external references. This is done by selecting the Project menu, then Settings..., and then in the dialog box, Link. This shows a dialog box with a editable field Object/Library modules. Add to the end of the contents of this field, the following three OpenGL library names:
opengl32.lib glu32.lib glaux.lib
If you would rather not do this, you can also use the #pragma command to tell the compiler which libraries to use.
Test I/O (stdin/stdout): If you run your program it will open a text window (in addition to any OpenGL window). Standard C I/O routines may be used to read and write from the window, via stdin and stdout. If you want to do this, don't forget to include the necessary C header files.