#define USE_FORGE_CPU_COPY_HELPERS
#include <complex>
#include <cmath>
const unsigned DIMX = 512;
const unsigned DIMY = 512;
struct Bitmap {
    unsigned char *ptr;
    unsigned width;
    unsigned height;
};
Bitmap createBitmap(unsigned w, unsigned h);
void destroyBitmap(Bitmap& bmp);
void kernel(Bitmap& bmp);
int julia(int x, int y, int width, int height);
int main(void)
{
    Bitmap bmp = createBitmap(DIMX, DIMY);
    
    
#ifdef OS_WIN
#else
#endif
    
    
    kernel(bmp);
    
    
    do {
    
    releaseGLBuffer(handle);
    destroyBitmap(bmp);
    return 0;
}
Bitmap createBitmap(unsigned w, unsigned h)
{
    Bitmap retVal;
    retVal.width = w;
    retVal.height= h;
    retVal.ptr   = new unsigned char[4*w*h];
    return retVal;
}
void destroyBitmap(Bitmap& bmp)
{
    delete[] bmp.ptr;
}
void kernel(Bitmap& bmp)
{
    for (unsigned y=0; y<bmp.height; ++y) {
        for (unsigned x=0; x<bmp.width; ++x) {
            int offset  = x + y * bmp.width;
            int juliaVal= julia(x, y, bmp.width, bmp.height);
            bmp.ptr[offset*4 + 0]   = 255 * juliaVal;
            bmp.ptr[offset*4 + 1]   = 0;
            bmp.ptr[offset*4 + 2]   = 0;
            bmp.ptr[offset*4 + 3]   = 255;
        }
    }
}
int julia(int x, int y, int width, int height)
{
    const float scale = 1.5;
    float jx = scale * (float)(width/2.0f - x)/(width/2.0f);
    float jy = scale * (float)(height/2.0f - y)/(height/2.0f);
    std::complex<float> c(-0.8f, 0.156f);
    std::complex<float> a(jx, jy);
    for (int i=0; i<200; i++) {
        a = a * a + c;
        if (abs(a) > 1000)
            return 0;
    }
    return 1;
}