Sep 20

GAME-ENGINE: getting started

GAME-ENGINE: getting started

Hi there,
as learning project I decided to create a simple game engine. Let me explain, I am not crazy or mad, what I am trying to do is, hopefully, a subset of a game engine, starting as small as possible and then build on top of that.

The first goal I have is to have a 2D sprite jumping around the screen in a Mario style. Which is not that hard if you hardcode your way out of it putting everything in a rigid loop etc, doing it by trying to have a basic pipeline running is a hole another story. Here I will try to explain what I designed and trying to build. Most likely a game developer will see this and have an hart attack, but I will try to have not a uber terrible bunch of code.

Here is how I see a basic game loop happening:



Let me try to explain it.
We have the event loop which has a standard series of call. First we process the inputs, to know what has been pressed. Next step is to update the game state, right now I am only updating the position of the game objects.
The game object is assembled with components, one components is in charge to update it’s position, by swapping the component I can change the wanted behaviour.  For example a component can read the user input and update accordingly, another type of component might be controlled from AI or just replay older user inputs etc. The input class is also quite useful to abstract away the windowing system, in this way hopefully if  the windowing library needs to be changed wont be super painful. Last step would be resolving collisions but that part is being designed right now, probably I will write a post about it in the future.

Next is the rendering step, before this step (or even before world update) we can build a subset of entity to render, again there are different rendering components in charge of different type of rendering, more about it later.

Here a scheme more focused on rendering:

Rendering pipeline

This is an old picture of the design (pre components) but should still give an idea.
The renderer is nothing more then a container grouping together a glsl_program with the shaders, a camera pointer and a series of resources to render. You register to a renderer a resource you wish to render, this can be for example built on the fly after a camera frustum culling pass.

A resource is called GameEntity,  which again is noting more then a container of different other resources, in the latest iteration it is filled with components,  a move , collision and render component. Now the buffers and render data is encapsulated in the render components. Some resources are at entity level like the position or velocity, I will need to find the right balance between encapsulation and shared resources. All the resources should be allocated with custom allocators to avoid memory fragmentation and ensure memory locality.

This was a super quick run trough of the engine structure, surely will change a lot while working on it. It has been super exciting so far!

Here is what I got:



By no means this is a tutorial on how a game engine should be structured, this is just a report of a programmer trying to get into game development. For this reason comment or critique are more then welcome, anything that can make the “engine wanna be” better.


Feb 22

PC BUILD: let’s go cool!

Hi everyone so I am back with part two of my pc build! It s time to go water-cooling!


So as you might know from my previous post I built my first custom pc from scratch, but as my dad always told me:”If you do something, do it right!”.

This means I could not stop there, I had to push further and watercooling and overclocking was the next natural step.

Finally last weekend I received the second batch of stuff:


Right there we got the second gtx 960, green fans (you will see the result later) , water cooling kit, green colour for the fluid and LED strips.

The first think I did was put in the second card and start seeing as it performed. (PS if you get a flashing green screen in SLI mode, just swap the direction of the SLI bridge).

IMG_20150214_133135 IMG_20150214_133125


As soon as I got started  with the watercooling kit problems showed up,  the instruction manual  said there was the need for an oring between the pump and the reservoir, of course that o-ring was missing.

As you might understand being the first time I was building a watercooling kit I did not want to take any chances to flood all that precious hardware. I had to contact the retailer, the kit manufacturer and they all gave me everytime different answers, in the end I found out they upgraded they watercooling kit and that oring is now integrated in the pump and colored



With that out of the way let the fun begins!

IMG_20150219_213830 IMG_20150219_213819 IMG_20150219_081333



The process was fairly straight forward even though I was freaking scared of leaks! ( that’s also the reason why there is toilet paper everywhere).

I let the system run for quite a while (4~ hours running and a whole day standing). In the kit there was an handy plug to jump start the PSU so I could just run the pump without need of anything else running.

After all that was done time for final touches and that means light!

IMG_20150219_213437 IMG_20150219_194344 IMG_20150219_194337 IMG_20150219_194328


That was it for the build, it took me quite a bit of trial and error but it was an amazing experience and I learned so much!

Here you can see a video of the lighting effect:

PC BUILD: NV FURY final result from Marco Giordano on Vimeo.

Finally here just a slide shows of picture with music of the whole building process!

NV FURY: making of from Marco Giordano on Vimeo.

That’s it guys! I did not talk about temperatures yet because I want to keep that for next post where overclocking will come ! Trust me when I say that little pentium holds some serious horse power!

Feb 15

My first pc build!

My first pc build!


Hi everyone! Yes I finally decided to build my first pc!

The reason for that is simple, since I started programming I got interested more and more about how actually a pc works, that led me to follow many channel on youtube that talk about hardware etc, I love following tech news about new cpus  and gpus. When I started doing parallel computing on both CPU and GPU I could hold it no more, I had to do my own build.

This build was born with the goal of being an experiment, cheap material just to get some experience. I also wanted to be able to play with overclocking, that led me to more expensive components like the motherboard.

In the end I decided what the heck lets make a nice build that will stand nicely for a year or two meanwhile I wait for new pascal architecture to come out.

This is what I ended up with:

CPU : Intel Pentium G 3258 K Anniversary edition (modest processor dual core but its multiplier is unlocked, and this bad boy overclocks like a beast!)

MOBO: Gigabyte Z97X-SLI

RAM : 2×8 GB Corsair vengeance


PSU : Corsair AX 750W

It is funny you know, years ago a friend of mine, Alberto Vazzola (AKA Wolf), asked me: “Aren’t you interested at all in hardware?”, I answered him that I was a programmer, and I did not give a s**t about hardware, kindle he answered me : “wait for it…”. He was damm right.

Here is a nice pic of the initial hardware:

IMG_20150207_112022 IMG_20150207_114355

I have to say that 960 is a sexy piece of hardware come on, you cannot deny it!

So let s move forward, before putting it into the case I did the most basic build possible just to see if the system post (and as you will see it was a good choice).

Getting the system to post was a pain in the neck, not for hardware fault but for my newbie mistakes.

For example took me ages to see why the PSU and motherboard wouldn’t get started and the why I got no screen output at all. After a lot of head banging on the wall and the help of friends and dad, we figured out that

I did not connect a second plug of the main 24 pin connector:



The reason why I did not plug the second one (on PSU side) was because a little force was needed to plug both and I had to bend the cable at the base, that combined with the fear of breaking stuff (you always have that fear with new stuff) led me to think only one of the two was needed. After my mistake was fixed I could finally scream: “IT ALIVE!”.

IMG_20150208_174250After that I could finally put everything in the case:



I did not pay too much attention for cable management since this is just the beginning :D Stay tuned if you wanna know more!

Anyway so It took me almost a weekend to put everything together but I am quite satisfied because I learned a huge bunch of stuff!

So that is it for now guys!


PS huge thanks to Alberto Vazzole and Alessandro Boschian Pest and best of all my Dad for all the advice.

Jan 18

LINUX: Fixing screen position running NVidia drivers

LINUX: Fixing screen position running NVidia drivers

Hello folks!

So lately I have been playing a lot with CentOS, and looks like I finally am on a stable setup, where I can compile all my stuff, opengl, cuda and TBB etc.

The problem that bothered me for a while was the setup of the screens, I had swapped monitor, meaning I had to go to the right  side in order to go in the left monitor, and swapping the monitors was not a solution due to a comples setup running with a shared monitor with two computers etc.

I was able to fix that with the nvidia-settings panel, unluckily the fix was not permanent, I tried a shitload of guides in order to fix the  problem, everyone suggested to use this command at runtime:

nvidia-settings --load-confing-only

But that was completely ignored for some weird reason I don;t know, so I had to do that with a script, I tried to mess around with the nvidia-settings command but no luck there, luckily I remebered a command I used ages ago on Ubuntu 10 to fix this very same problem, the command is xrandr, after a little googling on how to use the command I come out with few lines of code to fix my problem:

xrandr --auto --output DVI-D-0 --right-of HDMI-0
xrandr --auto --output HDMI-0 --left-of DVI-D-0
xrandr --auto --output HDMI-0 --primary
echo ">>>> screens setupped properly ... I hope!"

The code first sets my second monitor on the right of my main and then the opposite, at the end I also set the HDMI monitor as primary.
Now you might wonder where I came out whit those names HDMI-0, DVI-D-0 etc. To get the names of your monitors is quite simple you just need to
run xrandr without arguments in the terminal and it will spit out the current plugged monitors.

<pre>$ xrandr
Screen 0: minimum 8 x 8, current 3840 x 1080, maximum 16384 x 16384
VGA-0 disconnected (normal left inverted right x axis y axis)
DVI-D-0 connected 1920x1080+1920+0 (normal left inverted right x axis y axis) 531mm x 298mm
 1920x1080 60.0*+
 1680x1050 60.0 
 1600x900 60.0 
 1280x1024 75.0 60.0 
 1280x800 59.8 
 1280x720 60.0 
 1024x768 75.0 60.0 
 800x600 75.0 60.3 
 640x480 75.0 59.9 
HDMI-0 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 477mm x 268mm
 1920x1080 60.0*+ 59.9 50.0 
 1680x1050 60.0 
 1600x900 60.0 
 1440x900 59.9 
 1280x1024 75.0 60.0 
 1280x800 59.8 
 1280x720 60.0 59.9 50.0 
 1152x864 75.0 
 1024x768 75.0 70.1 60.0 
 800x600 75.0 72.2 60.3 56.2 
 720x576 50.0 
 720x480 59.9 
 640x480 75.0 72.8 59.9</pre>

Once you know that you are golden and can make your script run.
Last two step where to run the script at start-up, and create and alias for the script since I have a complex setup with HDMI swithces etc which sometimes still
freaks out the monitors, so I run the script manually from terminal and all goes in the right place.

That’s it guys , happy Linux!

Jan 06

Having fun with cuda…. again

Having fun with cuda…. again















Hello there, today we are talking about cuda again, some time ago you saw me talking about pycuda in THIS post, here today I did something similar but with a more serious approach,

I decided to get better at c++,  parallel computation and Linux, this led me to start this learning project about image processing.

The first step was able of course to read an image and convert the data in something that can be easily processed both from cpu and gpu, also it gave me an excuse to learn how to read a binary file.

I decided to go with a BMP image format, because is one of the simplest there is around, with no compression and just simple header.

Now don’t get me wrong I am not trying to re-invent the wheel at all, I just made a simple bmp class to learn the process, the class itself is quite limited as well features wise, it just let me load and save the image or if needed generate an empty buffer then save it, as a reference I used THIS awesome article, be sure to have a look at it.

Once the BMP was out of the way I could finally start working on the image processing itself, first step is the most basic and simple black and withe filter, I first implemented the serial version then the TBB version and finally the cuda version, I am not sharing the code yet just because I don’t believe it is decent enough to be shown, but I will do that soon and you will see it popping up on timings


Let s start with the black and white, the first thing to notice is that we don’t have such big difference between cuda and TBB, such small computation was not so worth based on all the managing of the data that cuda needs ( allocating/copying memory etc ), we start get some more speed up when we start going up on heavier images. Another interesting thing was that if I was trying to run 8 thread with TBB (aka hyper-threading), I was actually getting lower performances that just running 4 threads, unluckily I don’t know much about hyperthreading to know why but I plan on looking a little into it.

Here is a carth of the running times:





Everything looks fairly standard, the increase in time is also quite linear, even though the gap between 4k and 5k is not that much, but we will see later that, that particular spot will hold some surprises for the blur aswelas well

Speaking of blur, we can see that since we have abit more computation in the blur we start getting some way better performances out of cuda, lets see the charts for the timings.





As you can see here we start to get some nice performance out of the GTX 780M, we get an ~76x speedup compared to the serial code and a ~21x speed up compared TBB on a 9k Image.

It is all good and nice, except the serial execution between 4k – 5k, you can see that the 5k is actually running faster then the 4k, don’t ask me because I have no clue about it, at the beginning I thought it

was an error, but I run the program other two times for both the 4k and 5k image the result were the same, the only guess might be some combination in memory that made the 4k particularly  slower for some reason.

Other then that I was quite pleased to see the GPU starting to crunch as it is supposed to, but I am not stopping here, the plan for the future are the following, first I want to implement a gaussian blur, with a radius parameter which will force me to implement a dynamic size stancil and implement a generic convolution kernel with that stancil, also I came across THIS page where they show the different effects of different stencils, like sharpening or edge detection etc. Once the generic kernel will be implemented it will be fairly easy to play with those.

In the road map there is also the implementation of some more complex filters, or better I hope to find some filters more computationally expensive but not necessarily   super complex math wise, I don’t want to dive too much yet into image processing , last step will be add a nice UI where the user will be able to load an image and display that using opengl and then stack on each other different filters and see the result (hopefully) realtime.

Once that is done I will be ready to jump back on my opengl sandbox and make it way more robust and start implementing some more cool stuff.

That is it guys , here below a small video demo of me running the program.

Parallel Image: simple image processing program from Marco Giordano on Vimeo.




Dec 07

My current OSs setup and why is painful

My current OSs setup and why is painful

Hello folks how is it going?

Today I would like to share with you the painful mess I put myself in order to be able to work under Linux.

First of all I am not here to make a flame about Linux vs Windows, just stating some observation based on my experience, so if you are here to flame please kindly get the fuck of this post, thanks :D.

Now I am going to list my 3 partition setup and what each partition allow me to do, my final goal would be to have a Linux distro able to let me use Maya, do python and C++ , C++ opengl and possibly cuda.

My current setup:

Ubuntu 14:  First Linux distro I ever used

  • Maya : not able to make the license to work, I got a genuine student license but since I have to convert from rpm to deb I cannot use maya installer and had to go into the mess of manually make the license to work, after several painful hours no luck
    I tried to contact Autodesk for help and they laughed at me saying: “We dont support Linux have a good day”.
  • Python: works no problem , but most of my python is done for Maya so I cannot do maya-python on here
  • C++ : I can compile nicely with g++ no problem here
  • Opengl: Thanks to Nvidia finally supporting nvidia optimus technology I was able to make opengl stuff working on my GTX (and not integrated intel) card quite easily, problem second monitor refresh is uber laggy
  • Misc: my gaming mouse works ( basic functionality but that’s all I need)

CentoOS 7:   Best would be to use this distro, which is the same I use at work

  • Maya: CentOS uses rpm packages so I could use their installer and was just a matter of click click click done, installed (plus of course linking manually all the missing shared libs), license works ! wooot
  • Python : all good here, python works no problem and I can do maya stuff
  • C++ : I can compile with g++ no problem here
  • OpenGL: Bloody mess, there is no official support from Nvidia, so need to use Bumblebee project  which is quite of a pain to make it work, after I made it work my opengl viewport kinda works so for now I am stuck there.
  • Misc : gaming mouse does not work, need to have another mouse plugged

Windows 7: Works out of the box

  • Maya: always worked never had a problem
  • Python : all nice and smooth
  • C++ : well best is to use Microsoft compiler , but I need to use gcc/g++ and on windows doesn’t work so well, need to use some portings like MingGW, etc which gave me quite a bit of trouble before
  • OpengGL: I made stuff working on windows, but always on windows compiler I will try with MingGW
  • Misc : every device worked,

The final thoughts you guys might have is “Fuck Linux then, use Windows that works”. You got a point here ,  and I am not an a strict adopter of open-source, I am pro open source stuff but that s not my reason for jumping on Linux.

There are two main reasons I want to use Linux:

  • Loving the work flow: damn how much I like my work flow on Linux, where I pretty much interact only with the console, I can  get similar work flow on Win but is a pale imitation.
  • Work: for the kind of work I do and I wish to do in the future I need to be comfortable in programming and compiling on Unix systems.

Right now I am in the situation where I kinda do all I need to do but I have to switch between 2 different distros and each one has it s own pro-cons as you can see from the list above. I am by no means a Linux expert so might be just me the retarded one not being able to make it work XD,  but I hope one day I can stay on Linux all the time and just jump on Win for gaming purpose.

I might one day just buy a desktop PC and remove the Nvidia Optimus problem all at once, but we will see about that.

So that s all for now folks



Older posts «