Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon

4. May 2012

 

 

I have to say, Nathan does quick work, much faster than I do! Smile

 

As I said in this earlier post Nathan volunteered to port my SFML C++ tutorial to SFML 2.0.  Well, he is done.  So in addition to the 1.6 projects, you can now download source for SFML 2.0.

 

Keep in mind, the instruction are still for 1.6, that hasn’t changed, but you can now see code for either version.  Shortly I will edit the tutorial posts themselves to include the new download option, but for now you can download the 2.0 version sources here.  Part 8 does not include the FMOD sources, which were for demonstration purposes only and made the project quite a bit larger.

 

GameFromScratch C++ Edition SFML 2.0 downloads:

Part 6

Part 7

Part 8

Part 9

 

 

While he was porting, he ran into and reminded me of a bug that I encountered and Ninja-edited for future versions.  You may find that on occasion the ball disappears completely, at least in versions before part 9.  That was because GameBall used a counter from when the game started, instead of when play started.  So if you took a while to start the game, the ball could actually move on its own ( and off screen ).  The fix was a fairly simple flag I added in part 9.  For the fix details, take a look at the first few lines of GameBall::Update().

 

Thanks again Nathan.

Programming , ,

2. May 2012

 

I decided to take a quick look at the RIM Gameplay SDK I mentioned a few days ago.  I haven’t really gotten much into coding with it, but I have to say WOW did it ever get up and runningimage quickly.  Cross-platform gaming libraries normally require a number of hoops be jumped through before you get anywhere ( see PlayN for example ).  With GamePlay I was up and going in about 15 minutes, 10 of those was waiting for my computer to compile the source.

 

 

Here’s the process.

 

Head over to Github and download gameplay.  I used the zip link shown below:

image

https://github.com/blackberry/GamePlay/zipball/master

 

Extract that archive somewhere.

 

In the archive, find and double click gameplay-newproject.bat.

Now you will be asked a series of questions, all pretty straight forward.

 

I personally answered: GamePlayTest, GamePlayTest, GamePlayTest, com.gamefromscratch.GamePlayTest, Bob Dole,MyTestGame.

 

Finally when asked for a path, I entered c:\temp.  The following directory structure is created:

 

image

 

 

Open up TestGamePlay.vcxproj, or whatever your version is called.

 

Now is the only tricky part, add a reference to the gameplay library.  In Solution Explorer, right click the Solution->Add->Existing Project…

 

image

 

Navigate to directory you unzipped gameplay, open the subdirectory gameplay and choose gameplay.vxcproj and click Add.

 

image

 

Now right click your game project in Solution Explorer and select Project Dependencies…

 

image

 

In the dialog, make sure gameplay is checked then click OK.

 

image

 

You are now done.  Now hit CTRL + SHIFT + B to build, and go grab a cup of tea.

 

Gameplay will have created the following game cpp to get started with consisting of the following code:

 

//#include "MyTestGame.h" // Declare our game instance MyTestGame game; MyTestGame::MyTestGame() : _scene(NULL) { } void MyTestGame::initialize() { // Load game scene from file Bundle* bundle = Bundle::create("res/box.gpb"); _scene = bundle->loadScene(); SAFE_RELEASE(bundle); // Set the aspect ratio for the scene's camera to match the current resolution _scene->getActiveCamera()->setAspectRatio((float)getWidth() / (float)getHeight()); // Get light node Node* lightNode = _scene->findNode("directionalLight"); Light* light = lightNode->getLight(); // Initialize box model Node* boxNode = _scene->findNode("box"); Model* boxModel = boxNode->getModel(); Material* boxMaterial = boxModel->setMaterial("res/box.material"); boxMaterial->getParameter("u_lightColor")->setValue(light->getColor()); boxMaterial->getParameter("u_lightDirection")->setValue(lightNode->getForwardVectorView()); } void MyTestGame::finalize() { SAFE_RELEASE(_scene); } void MyTestGame::update(long elapsedTime) { // Rotate model _scene->findNode("box")->rotateY(MATH_DEG_TO_RAD((float)elapsedTime / 1000.0f * 180.0f)); } void MyTestGame::render(long elapsedTime) { // Clear the color and depth buffers clear(CLEAR_COLOR_DEPTH, Vector4::zero(), 1.0f, 0); // Visit all the nodes in the scene for drawing _scene->visit(this, &MyTestGame::drawScene); } bool MyTestGame::drawScene(Node* node) { // If the node visited contains a model, draw it Model* model = node->getModel(); if (model) { model->draw(); } return true; } void MyTestGame::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex) { switch (evt) { case Touch::TOUCH_PRESS: break; case Touch::TOUCH_RELEASE: break; case Touch::TOUCH_MOVE: break; }; }

 

 

And:

 

#ifndef MyTestGame_H_ #define MyTestGame_H_ #include "gameplay.h" using namespace gameplay; /** * Main game class. */ class MyTestGame: public Game { public: /** * Constructror. */ MyTestGame(); /** * @see Game::touchEvent */ void touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex); protected: /** * @see Game::initialize */ void initialize(); /** * @see Game::finalize */ void finalize(); /** * @see Game::update */ void update(long elapsedTime); /** * @see Game::render */ void render(long elapsedTime); private: /** * Draws the scene each frame. */ bool drawScene(Node* node); Scene* _scene; }; #endif

 

 

The results of this code (although animated):

 

capture_002_02052012_210105_138

 

 

That code is Windows only at this point, but the BAT file created XCode and Android projects for easily compiling for iOS and Android respectively.

 

That was a remarkably simple process.  Zero to spinning cube in 10-15 minutes (3/4 of it waiting for my compiler), I’m impressed.  They have done a very good job of making it the kind of product you can just jump into.  Now to jump into the code a bit more and see if I stay impressed.

 

 

A Quick look around the SDK

 

 

external-deps is where all the libraries gameplay depends on are located.  By the way, those libraries are bullet, collada-dom, freetype2, glew, libpng, oggvorbis, openal, pcre and zlib.

 

gameplay directory is where the gameplay library itself resides.  We linked to it earlier as a project dependency.

 

In the gameplay-api folder, there is gameplay.html which contains the system generated HTML class library references.

 

In gameplay-docs are the development guide, and three sample tutorials ( longboard, spaceship and character ) in rtf and pdf formats.  Longboard is a skateboarding game controlled using the motion controls, spaceship is a 2D sidescroller that is actually 3D and character is a 3D scene, that is mostly about demonstrating the 3D pipeline (using Maya ).

 

Longboard:

image

Spaceship Tutorial:

image

Character Tutorial:

image

 

gameplay-encoder contains the project for the gameplay-encoder, which is the utility used to encode assets in the gpb format.  See the Character tutorial for more details on how this utility works.

 

gameplay-samples contains all three tutorial projects I mentioned earlier, as well as a mesh and particle sample.

 

 

Again, nice work overall.

Programming

2. May 2012

 

 

Nathan, a reader of this site, has graciously agreed to provide his port(s) of the Game From Scratch C++ tutorial from 1.6 to 2.0.  He started with chapter 6, as prior chapters mostly involved simple changes in property/method names, as SFML has moved to CamelCase.  Chapter 6 is the first chapter where more intensive changes needed to be made.

 

 

So if you are following along my C++ tutorial, but would prefer to work with SFML 2.0, download these projects instead.  Nathan has promised to make each following chapters code available as well, and once I am up to current, I will edit in the original tutorial posts so you have an option of downloading either 1.6 or 2.0 project versions.

 

Sometime in the future, I will put together a post on what is required to port from 1.6 to 2.0, I promise… sometime. Smile

 

This project is exactly like the 1.6 ones.  It is preconfigured ( with SFML 2 release candidate ), so  all you have to do is download, unzip and open the solution in Visual Studio.

 


Download Pang6 here.   Will update as further chapters become available.

 

Thanks Nathan.

 

EDIT: Link fixed.

Programming ,

1. May 2012

 

Previously available for 40$, Bsurfaces is now available freely under the GPL license.  Thisimage wonderful modeling/retopology tool should be added to your tool chest as soon as possible.  For more details on what BSurfaces offers, check here.

 

 

The following guide shows how to install BSurfaces, or for that matter, any Blender plugin.

 

 

To install it, head over to this site and download it.

 

Open the zip file, the file you are interested in is bsurfaces.py, extract it somewhere, I will use my desktop.

 

Now fire up Blender.  In select the menu File-> User Preferences… like such:

 

image

 

In the resulting dialog, select Addons, then click Install Addons…

 

image

 

Navigate to the location you extracted pysurfaces.py, then click Install Addon…

 

image

 

Now click the checkboxes to enable the plugin

 

image

 

And BSurfaces is now installed.

Art

30. April 2012

 

BlenderOnVita

We are now going to look at creating a fully textured model in Blender and exporting to a PlayStation Studio SDK project, a simple model viewer.  We create a very simple model, UV map, texture then export it.  At this point, we process it using the PS Studio ModelConverter tool, import it into PS Studio then finally run our code in the simulator.

 

The example model is as I said, brutally simple ( it’s simply a dice, er… die, also known as a textured cube ). However the process for exporting more complex models is exactly the same.  The process isn’t really all that difficult, especially if you know your way around Blender, but if you don’t know Blender all that well don’t worry, I’ve actually captured the entire process in video form.  This video covers exactly the same thing that the rest of this tutorial does, so if you have problems following one, refer to the other and vice versa.

 

 

Modeling, texturing and exporting from Blender to Sony PlayStation Suite SDK in under 5 minutes

 

 

The above video is actually encoded at 1080p and is probably almost illegible at anything less than 720p.  You can watch it on YouTube or Vimeo in full definition.  Again, the video demonstrates exactly what I am going to show below, except the source code.  So if you are the type that prefers to learn by watching, or the type that learns by reading, you get the best of both worlds here!  Alright, let’s get started.

 

 

If you already know how to model, texture and export in COLLADA format using Blender, I suggest you skip ahead to part 2, as the remainder of this section will be quite boring for you… it goes into detail, a lot of detail. Smile

 

 

If you haven’t already, fire up Blender.  We are going to work with the default cube, if you don’t have a default cube select the Add menu –> Mesh –>Cube.  The first thing we want to do is create a new image to texture our model.

 

In the properties panel to your right ( assuming you are using the default layout, which I will for the remainder of this tutorial ), locate the Textures tab and click it.  Like such:

 

image

 

 

Now change “Type” to Image:

image

 

Scroll down slightly to the Image section ( expand it if required ) and click New:

image

 

In the resulting dialog, we specify the texture details.  I am going to name it the ultra imaginative name “Texture” but fell free to call it whatever you want.  1024x1024 is massive overkill for what we are doing, but hey… I like overkill.  When done, click OK.

 

image

 

Now we want to apply some simple texture mapping to our 3D cube.  In the 3D view, make sure you are in “Edit Mode”, either by hitting Tab until selected, or via this menu:

image

 

Now that you are in edit mode, select all the faces of your mesh by hitting “a”.  Now in the Mesh menu, you want to select Mesh->UV Unwrap…->Follow Active Quads.

image

 

Simply click OK at the resulting dialog menu.  Now we want to switch to UV editing mode.  Locate the icon to the bottom left of your view, click it and select UV/Image Editor.

image

 

We now want to make our texture the active image.  Locate the “Browse image to be linked” button, click it and select texture from the list.

 

image

 

Now press A to select all of our faces, then using hit S to scale ( then mouse move, left click when done), followed by G to translate, until our UV coordinates are all over the black image, like so:

image

 

Now we want to quickly paint our dice faces on the texture within the UV coordinates.  From the menubar select Image->Image Painting.

image

 

Now left click to mouse paint the texture like the face of a die.  You can use the left hand panel ( press “N” if not visible ) to change the paint settings.  When done you should have something like this:

image

 

Now, back in the Image menu, unclick Image Painting.  Now we want to save our completed image.  In the same menu as before, select “Save as Image” or hit F3.  In the resulting dialog, locate the directory you want to save the texture to ( make it the same place you are going to save the model ), name it, then click Save as Image:

image

 

Now with that complete, we assign our image to our texture.  Back in the Texture panel ( to the right ), locate the Image section, click the Browse Image to be Linked button and select your texture.

image

 

Now scroll down lower in the Texture panel, locate Mapping, then select the Coordinates: dropdown and select UV.

image

 

Right below that, select the Map: dropdown and select UVMap.

image

 

 

 

All right, now we have a fully texture mapped model ready for exporting.  From the File Menu ( top right ), select File->Export->COLLADA(.dae).

image

 

 

In the resulting dialog, navigate to the same location where you saved your texture, name it ( I used box.dae ), optionally select “Export only selected” then click Export COLLADA.

 

image

 

 

And we are now done with Blender.

 

 

This section has already gotten quite long so I am going to break this post into two parts.

 

 

Continue on to Part 2.

Programming, Art , , , ,

Month List

Popular Comments