Category Archives: C++

Perfomance of complex GL ES 2.0 shaders on mobile devices

There is very nice site http://glsl.heroku.com/, where you can find the gallery of complex GLSL shaders (from very simple gradients to very complex rendering systems). You can modify their code at real-time using provided editor:

heroku

Current implementation of WebGL is using GL ES 2.0 – the same as all mordern android / iOS phones/tablets. So i decided to test if i can use these shaders at mobile applications – and tested their performance on Sumsung Galaxy Note II. Of course i tested only relatively simple shaders expecting them to run slow…

Continue reading

Live Wallpaper under Android can be powered by my cross-platform engine now

After my recent modifications of android part of my cross-platform engine, it is possible to make application also run as android live background. I plan to implement the same feature as well for iOS 7, but a bit later. Here is working example (https://play.google.com/store/apps/details?id=com.calibvr.synctimer):

Synctimer as live background

Android live wallpaper is not a general Activity application – it is special WallpaperService. And you cant implement it in pure C++ using NativeActivity. All my core is cross-platform C++ so i implemented two-way communication between C++ and JAVA. From C++ NativeActivity you can call JAVA classes through JNI and from java service you can call native (c++) methods of engine core.

The tricky part that all this communication involves a lot of different threads. Wallpaper service has its own thread, but rendering should be performed in another one. My native C++ core is launched as third thread and spawns other async threads which could call some java methods. But i got through all this nightmare using mutexed queues of events. As result i got full functionality of my engine at the background of android launcher.

When i only started working with android i wrote small live wallpaper in pure java (with no OpenGL). Wasted only couple of evenings and even lost the source code. But recently i was surprised when discovered that it has more than 100.000 downloads (https://play.google.com/store/apps/details?id=back.livenumbers). It does not even work properly on my Note 2 now.

But the point is that now i have smooth OpenGl ES 2.0 animations/effects in couple with engine functionality. Probably, i will create couple of stylish backs fused with some in-code widgets (like battery indicator, weather forecast, clock, calendar date or something else) as implementation will be relatively easy now using my engine. Any suggestions on this matter are welcome.

Manual decoding of ICO file format – small c++ cross-platform decoder lib

This post is related to one simple task – decode ICO file format from C++ manually (I needed this for one of my projects where i wanted to display fav icons related to web sites and decoder has to be part of my cross-platform framework). As a result you can download small c++ code below (ico.cpp). The description of ICO format you can find here – http://www.daubnet.com/en/file-format-ico. Image data is stored uncompressed so we don’t need to implement some smart decompression algorithms – just read some headers, get data and apply bit mask to fill alpha channel.

icons

As solution i wanted a function like this:  

bool IcoDecoder::decode(unsigned charbuffer,///< input buffer data

    int size,///< size of buffer

    unsigned intwidth,///< output – width

    unsigned intheight,///< output – height

    std::vector<unsigned char>&image///< output – image data

) 

and this function should extract the largest possible image from multiresolution icon.

Continue reading

Beal prize – first approach

May be you already heard that so called Beal Prize was increased to 1.000.000$ (http://ns3.ams.org/bealprize.html). So if you can find positive integers A^x+B^y=C^z where x,y,z > 2 and A,B,C dont have common factor, you can get a lot of cash. As you can see its not a complication to write a piece of code to check some range of numbers, or generator to generate some lucky numbers. Its officially checked only in range where all numbers are less than 1000.

So i decided to try my luck.

As first approach i decided to generate a lot of prime numbers (15.000.000 for start). This is C++ code for relatively fast generation of prime numbers:

// Primes

int MAXPRIME = 15000000;

unsigned long * primeNumbers = new unsigned long[MAXPRIME];

LOG << “Computing “ << MAXPRIME << ” prime numbers…” << NL;

LOG.startProfile();

{

primeNumbers[0] = 2;

primeNumbers[1] = 3;

long x = 3;

long sqrtIndex = 0;

for (int i = 2; i < MAXPRIME; i++)

{

bool ok = false;

while (!ok)

{

x += 2;

if ((x % 6 == 1) || (x % 6 == 5))

{

ok = true;

while (primeNumbers[sqrtIndex] * primeNumbers[sqrtIndex] < x)

sqrtIndex++;

 

for (int j = 0; j <= sqrtIndex; j++)

if (x % primeNumbers[j] == 0)

{ ok = false; break; }

}

}

primeNumbers[i] = x;

if (i % 100000 == 0)

LOG << i << ” [ “ << primeNumbers[i] << ” ] “ << NL;

}

}

LOG.profile(“Computing “ + SS::toString(MAXPRIME) + ” prime numbers was completed”);

To check Beal conjecture we need support of very long integers for C++. I have my own implementation, but you can use any decent library.As first straight-forward approach i decided to do in endless cycle the following (until i get lucky numbers):

  • Get two random prime numbers from pregenerated array.
  • Generate random x,y,z within reasonable range.
  • Compute S=A^x+B^Y
  • Compute the most close C – which gives (2*C)^z ~ S (i have used simple method of bisection).
  • If (2*C)^z == S break and report success.

I got yet no success, and some mathematicians tell that conjecture is probably true. But still why not to try to search if it is so easy.

SyncTimer – stylish multiplatform timer with synchronization between devices

My newly developped cross-platform engine finally goes to markets. Current platfroms are iOS, Android and Windows desktop.

SyncTimer icon

Download stylish multiplatform timer with synchronization between devices. 
You can control your timer from your PC, your iPhone or iPad, your android tablet and more. 
And even get more fun sharing timer with your friends.

http://synctimer.calibvr.com/