High performance with canvas prerendering

Canvas API is slow by nature, don’t try to argue this, it is…
When using HTMLcanvas, we have to know how the whole thing works, first of all, the canvas 2D context itself is an Int8Array with length (side^2) * 4 and an API to modify this array, this API is an abstraction layer that allows you to easily draw shapes, paths, etc without leading with pixel modification or rasterizing.

Each time you tells this API to draw a rectangle, it calculates the new state of all the pixels involved, this could be easy, but if you draw a shape like an triangle or a irregular one, the API will triangulate it, calculate the pixels state and rasterize it, and trust me, this take’s a lot of time and hard working.

Continue reading “High performance with canvas prerendering”

Multi-Platform JavaScript Modules

A multi-platform module/library is a piece of code that works shameless in browser, server -usually nodeJS- and embedded systems.
Haven’t you noticed that JQuery works when you import the library from “script” tags in a website and when you “require” it in nodeJS? this is because JQuery controls the global scope and, depending on it, initialises the suit in different manners.

JQuery is the paradigm of multi-platform libraries, it runs in modern and old browsers, from phones to smartwatches, in Webkit, blink or Node, but, how do it do it?

Continue reading “Multi-Platform JavaScript Modules”

Animations in video games: Sprites

The obvious difference between a shitty prototype and a professional game is the way it looks, the graphics, animations, shaders, blooms, etc.
Today we are going to see what sprites are and how they work.

Continue reading “Animations in video games: Sprites”

Compile SDL2 in Unix systems: undefined reference

undefined reference to SDL when compiling

Today, trying to compile a SDL2 based proyect with G++ in a Unix based system i ran across a linking error, have you ever seen something like this?

TxtFunc.cpp:(.text+0x61): undefined reference to `TTF_OpenFont'
TxtFunc.cpp:(.text+0x8c): undefined reference to `TTF_RenderText_Solid'
TxtFunc.cpp:(.text+0xf6): undefined reference to `SDL_UpperBlit'
TxtFunc.cpp:(.text+0x108): undefined reference to `TTF_CloseFont'
TxtFunc.cpp:(.text+0x114): undefined reference to `SDL_FreeSurface'

This happen when libraries are not correctly linked to the project, usually the issue is related to the import order.

Continue reading “Compile SDL2 in Unix systems: undefined reference”

Define values in compilation time with GCC

 

Sometimes your code need some additional / environmental information to compile, like version number, platform data, date, etc.

Most compilers let you “define” values in compile time, in this article we gonna cover how to do it in GCC, G++ and Clang.

Continue reading “Define values in compilation time with GCC”

Share memory between processes in C++

Wouldn’t be awesome to have some fastest way to share data between processes and services than TCP/UDP sockets, even faster than Unix sockets or OS Events/Signals?
Stop dreaming, it exists, the FASTEST DATA SHARING EVER SEEN, shared memory.

Shared memory is just accessing the same memory block from two or more processes, that means that multiple processes can share data in real time.

Continue reading “Share memory between processes in C++”

Bit flags and bitwise manipulation

learn how manage large boolean data using bitwise manipulation and bit flags

Have you ever wondered what does this mean?

glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT DEPTH);

glut, as OpenGL or many other frameworks, libraries and utilities has tons of boolean values that has to be setted in order to achieve a correct initialization, that can seem easy but it’s not.

C++, as many other languages such Javascript, Java or Python need variables to have a minimal size, usually the “word size”, this is the minimal bit block needed to store a “word” , known as minimal addressable storage unit.
This usually means that the minimal addressable unit has 1 byte length, from booleans to strings, everything has to be greater than 1 byte length (8 bits).

Where’s the problem?
Easy, a boolean variable can have 2 values (0 or 1), so just 1 bit is needed, but it takes 8 bits to store it, so, if we have 100 boolean variables in our program we will need 100 bytes to store them (800 bits).
Wouldn’t be awesome to use all the bits in that byte to store 8 booleans in the space that just 1 would require?
Continue reading “Bit flags and bitwise manipulation”

Design a site like this with WordPress.com
Get started