Coding in 3D

It's time for us to put our theory into practice and create our first 3D scene. To keep things simple, we will go through the steps of placing a cube in 3D space. This is also going to be the start of our 3D game, so let's start by creating a brand new project in Visual Studio.

Creating the project

When we created a project for our 2D game, we started with a standard Windows project and then removed (or ignored) the items that we didn't need to use. In fact, the standard Windows project has a lot of overhead that we don't need. This is because the Windows project template assumes that Windows is going to be in charge of rendering and processing. This came in useful for our 2D project, but just adds a lot of extra code that we don't need.

For this project, we will start with a blank Windows project and then add the necessary code to initialize and create an OpenGL window. Then, we will work our way up from there:

  1. Begin by opening Visual Studio.
  2. Once Visual Studio is open, create a new project by clicking on File, New, Project. From the Visual C++ branch choose Empty Project.
    Creating the project
  3. Name the project SpaceRacer3D, place it in the location of your choice, and click OK. The result is a project that has no code. Let's solve that problem by creating our main game file.
  4. Right-click on the Source Files folder in the Solution Explorer panel.
  5. Choose Add, New Item….
  6. Click on C++ File (.cpp).
  7. Type SpaceRacer3D.cpp for Name and click Add.
    Creating the project

Retrieving OpenGL files

The standard OpenGL library is already installed when you install Visual Studio. However, the OpenGL utilities library may not be. To make things simple, we will simply copy the files that we need from our RoboRacer2D project.

Open the RoboRacer2D project folder and select the following files:

  • glut.h
  • glut32.dll
  • glut32.lib

Now copy these files into the SpaceRacer3D source folder. This will be the same folder that your SpaceRacer3D.cpp file is located.

Linking projects to OpenGL libraries

Now that we have a project and the relevant OpenGL files, we need to link to the OpenGL libraries. This is done by accessing the project properties.

In the Solution Explorer panel perform the following actions:

  1. Right-click on the project name (not the solution), and choose Properties.
  2. Open the Linker branch under Configuration Properties, and select Input.
  3. Click on Additional Dependencies and then click the drop-down arrow that appears.
  4. Click on <Edit…>.
  5. Add OpenGL32.lib and GLu32.lib in the Additional Dependencies dialog window.
    Linking projects to OpenGL libraries
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.31.180