GPiC++Stf Chapter 3 Part 3


Hello Everybody, Earth Otherwise here to continue our journey into Game Programming in C++: Start to Finish by Eric Yuzwa.

Get into your IDE of choice. We have a basic empty project, add a static library project. I'll show you how to make one in visual studio. There are tutorials on how to do this in other IDE's. This is going to be our game engine that we'll be adding to as we make our games. Really it's just a separate repository of easily reusable code that's useful in multiple games. It will take longer to build up a useful engine, but it will speed development on later projects.

You could download a pre-made game engine and learn how to use it, but if you haven't already done that; you're in it for the long haul, so let's go. Create a new win32 console application. Give it a name. Mines called Otherwise. Choose a different name for yours so that our code doesn't match perfectly. It's a good way to make sure that you're actually paying attention and not just copy-pasting, which you really shouldn't be doing. Take it from someone who did nothing but copy-paste code for the longest time, it doesn't help you learn.

Set the project to be a static library with no pre-compiled header. I don't know why we do this, but we do. I'm sure you can google the reason. In fact, someone please do google what would happen if we had pre-compiled headers and leave a comment telling the rest of us why.

While they do that we'll go ahead and set up our projects to have access to our deps folder so that we can include SDL and GLEW. Open the properties of the library. There are two configurations, Debug and Release. Debug mode runs slower and gives you real time analysis of some of the stuff running in your game. Release runs faster but with no analysis.

In this project include directories are the same for release and debug, it's easier to set the Configuration to all when adding the include paths. In the Directories, under Input Directories, add a path to our include folder. You can click the arrow at the right and hit edit if you want to do it line by line but you can just write over what's there since what's already there is locked in unless you specifically turn it off. The path is simple, it's $(SolutionDir)Dependencies/Include/;$(IncludePath)

For those of you that don't know, we just told the IDE that it can look for included files inside the include directory which is inside our deps directory which is in the same directory as our solution, the file that contains all the info on our projects. The library and executable projects in this instance.

Now set the configuration to Debug and in the Library Directories section we're going to add $(LibraryPath). I don't remember what the original reasoning for this is, but I'm sure Ben explained it somewhere. If it trips us up we can change it whenever we like.

Go to the librarian section's general tab. Here we'll be adding which libraries we'll be specifically using. Right now we need SDL2.lib, SDL2main.lib, and glew32.lib in the additional dependencies section. In the additional library directories section we'll add $(SolutionDir)Dependencies/Lib/Debug/;%(AdditionalLibraryDirectories) in the debug configuration and we'll copy and replace the debug with release for the release configuration.

Move onto the executable project's properties. Go to all configurations and put $(SolutionDir)Dependencies/Include;$(SolutionDir);$(IncludePath) in the include directories section for both release and debug. Then we add the debug part of the lib folder to the debug configuration and the release folder for the release configuration. I know that right now this doesn't matter since our debug and release libraries are the same, but you'll be thanking me that you don't have to learn this stuff when you eventually encounter different debug libraries in the future.

Now go to the linker part of the property pages and go to input. In the release configuration we will only have it looking at the Otherwise lib file, or whatever you personal library is called. For the debug configuration, however, we will need to have all the other libraries as well as our personal library SDL2.lib;SDL2main.lib;glew32.lib;Otherwise.lib;%(AdditionalDependencies) . I don't remember why we do this either, but we do. As I've said before, I'm sure Ben explains it somewhere in his tutorial videos.

With our properties sorted out we can test to see if they worked. Create a new class in your personal library with the same name as the library itself. This is the first point of contact between your library and any games you're going to be making with it. It probably won't hold much, but it should hold the very basics of your SDL interface and some comments about the library in general.

In the class try to #include<SDL/SDL.h> and #include<GL/glew.h> You should be able to include both of these things if you set up the deps folder correctly. Once you have that we can finally start coding.


▶️ DTube
▶️ IPFS

Coin Marketplace

STEEM 0.16
TRX 0.13
JST 0.027
BTC 58270.16
ETH 2600.36
USDT 1.00
SBD 2.39