|
PTK is one of the best 2D game libraries around. It’s simple, fast, cross platform, and inexpensive. One of the downsides to being a PTK user is the lack of articles about how to make PTK work best. I’m going to try to remedy that somewhat, in a series of articles (I hope) that should help you make the most out of using PTK.
First, where do you get it?
www.phelios.com/ptk
There’s a free to use for free stuff version that you can use to get started. It has a watermark that’s displayed while your game is running, but it’s not too annoying, and it won’t take too much time spent with PTK before you know you’ve got to have it.
So, for this first article, we’re just going to talk about setting up a project using PTK and Visual C++ .Net.
Setting Up in Visual Studio .Net
First off, I’m using Visual Studio .Net 2003 for this article, primarily because that’s what I have, but also because there isn’t currently any existing documentation that describes the process. It’s really not all that different from Visual C++ 6, but some things are in different places, and it’s always handy to have a guide for the compiler that you’re using. All of these steps can be done in VC6. Many of them are not described in the documentation, despite the fact that you would need to do them. As far as how it compares to the earlier Visual Studio .Net (2002), the differences are so slight they're not worth mentioning.
So open Visual Studio. See that shortcut in your start menu? Yeah, that one. Click it. Now, if you’re paying attention, and you’re looking at the docs while reading this article (specifically the ones regarding Visual Studio 6), you’ll see they start with creating a Win32 Application. First things first. Don’t do that yet.
First, download PTK from www.phelios.com/ptk, and then "install" it by putting it into a directory that is easily accessible. Inside the PTK tree, there are quite a few folder levels to traverse, so don’t add to the horror by putting it in c:\my source code\projects\devlibs\gamelibs\ptk. Use something shorter, like D:\LDG\3rdParty\ptk. This is where I installed it on my machine (LDG is short for Laughing Dragon Games).
OK. Now, create a new Win32 application.
From the File menu, select New->Project. In the project types dialog, find Visual C++ Projects, expand that node, and select the Win32 folder. Choose Win32 Project from the list on the right. Type a Name in the "Name" textbox. For this article, we’ll use "Example1" (exciting, I know). The best place to put it is in a folder that is adjacent to the folder in which you put PTK. In my case, that folder is D:\LDG. Click OK to move to the next stage.

The next dialog shows a couple options. Select "Application Settings to take you to this screen. Make sure Windows application is selected, and, for the purposes of this Article, click the "Empty Project" box. The reason for this is to prevent Visual C++ .Net from creating a bunch of unnecessary stuff for you, including code to display a window, that you don’t need as a PTK developer. Click Finish when your dialog looks like the one here (minus the nifty WindowBlinds skin).

Our next step is the creation of a source file. Visual Studio .Net, for some reason, doesn't realize your project is a C++ project until you add at least one file, and will be missing a necessary option page in the project properties. At the moment, your project should look similar to the following image. Right click the "Example1" node (this is the project node) and select Add->Add New Item. Select C++ file from the list of items, and give it the name "main". Click Open.

Now is where I really diverge from the PTK documentation as far as setting up your project to use PTK. The documentation tells you to set up global (as far as VC is concerned) directory pointers to the headers and libraries. This is the easy way out, and it works fine until you want to move your project to another computer, where you have forgotten that you need to set these settings. If you want to go this route, the appropriate dialog can be found by clicking Tools->Options on the menu, and then selecting Projects->VC++ Directories from the folder tree in the options menu. Then check the PTK documentation for how to add the items. It's essentially the same as VC6, and I'm not going to describe it in detail.
What I am going to describe to you is more difficult, initially, but it means that you can move your project to whatever machine you wish, and it will work immediately without any settings changing. However, it also means that you have to learn to think of your project as the code you write AND any other libraries that you may use, and whenever you move them, the libraries have to be moved relative to your Visual Studio project.
So...
Right now, you have a project that looks something like the image below with a single, empty, source file. Right click on the bolded "Example1" again and select "Properties" from the context menu.

You should be looking at something that resembles the following dialog.
Click the C/C++ folder and make sure the C/C++->General node is selected. The top line should say "Additional Include Directories". To that, we need to add a reference to the ptk headers directory. Now, as a reminder, my PTK library is in D:\LDG\3rdParty\ptk and my project is at D:\LDG\Example1. So, I am going to set a relative path from my project to the PTK directory. For me, it’s "..\3rdparty\ptk\libptk\pc\headers", without the quotes, of course. First, since the header directory will be the same for all build types, select "All Configurations" from the Configuration dropdown. Then type your relative path into the Additional Include Directories box. Your dialog should look like this.

Now, click the Linker node, and then the General node (if it’s not already selected). In the "Additional Library Directories" field, you are going to put in basically the same thing, only this time, you are going to point it to the libmicrosoftvc directory, instead of the headers directory. For me, the string looks like "..\3rdparty\ptk\libptk\pc\libmicrosoftvc" as in the following image.
The next step is to click the Linker->Input node of the tree, and you’ll see "Additional Dependencies". In that box, type the following items, each one followed by a space (or you can just copy the line) : libptkvc.lib ksoundvcstatic.lib winmm.lib opengl32.lib dsound.lib dxguid.lib
We've finished with global Configurations, and need to set some specific items for each Configuration type, depending on whether it’s Debug or Release. We’ll start with debug. Select Debug from the Configuration dropdown. If it asks you if you would like to save the changes, click yes.
On that same page, in the "Ignore Specific Library" we need to add a couple things. Specifically, "libcmt;libc". We’re in debug mode, and the linker will spout some warnings to you that such and such already exists and will be ignored because you are linking against release mode libraries. Add those items and click Apply. Your completed linker page should look like this.

Switch to the Release configuration, and add "libc" to the "Ignore Specific Library" field for release mode and click Apply.
Now, click the C++ node (we’re still doing the Release configuration). Then, click the Code Generation node. In this page, you want to find Runtime Library, and select Multi-threaded (/MT) from the dropdown that appears when you click into the box. Click Apply. Your dialog should look like this, now.
Select Debug from the Configuration dropdown, and in the Runtime Library field, select Multi-threaded Debug (/MTd). Click Apply, and you’re all done, and ready to write some code.
Testing Your Project Paths
To test your new setup, add the following code to your main.cpp file and compile. Running it should give you a red window. Alt-F4 to quit.
|