 #include <math.h>
 #include "cudpp.h"
 #include "cutil.h"
+#include <GL/glut.h>
 
 #ifdef _WIN32
 #  define WINDOWS_LEAN_AND_MEAN

        printf("Error creating CUDPPPlan.\n");
    }

    CUT_SAFE_CALL(cutCreateTimer(&(satTimer[0])));
    CUT_SAFE_CALL(cutCreateTimer(&(satTimer[1])));
    CUT_SAFE_CALL(cutCreateTimer(&(satTimer[2])));
}

extern "C"

    CUT_CHECK_ERROR("scan 2");
    cudppMultiScan(scanPlan, SATs[1][2], SATs[0][2], width, height);
    CUT_CHECK_ERROR("scan 3");

    

    // transpose so columns become rows
    transpose<float, 16, 16><<<grid, block, 0>>>
        (SATs[0][0], SATs[0][1], SATs[0][2], 
         SATs[1][0], SATs[1][1], SATs[1][2], d_satPitchInElements, width, height);
    CUT_CHECK_ERROR("transpose");

    // scan columns
    cudppMultiScan(scanPlan, SATs[1][0], SATs[0][0], width, height);

    CUT_CHECK_ERROR("scan 4");
    cudppMultiScan(scanPlan, SATs[1][1], SATs[0][1], width, height);
    CUT_CHECK_ERROR("scan 5");
    cudppMultiScan(scanPlan, SATs[1][2], SATs[0][2], width, height);
    CUT_CHECK_ERROR("scan 6"); 
    
    interleaveFloat32toRGBAfp32<<<grid, block, 0>>>((float4*)out_data, 
                                                    SATs[1][0], 
                                                    SATs[1][1], 
                                                    SATs[1][2], 
                                                    d_satPitchInElements,
                                                    width, height);

    CUDA_SAFE_CALL(cudaEventRecord(timerStop));

    CUT_CHECK_ERROR("interleave");

    CUDA_SAFE_CALL(cudaGLUnmapBufferObject( pbo_in));
    CUDA_SAFE_CALL(cudaGLUnmapBufferObject( pbo_out));

    float ms;
    CUDA_SAFE_CALL( cudaEventSynchronize(timerStop) );
    CUDA_SAFE_CALL( cudaEventElapsedTime(&ms, timerStart, timerStop) );
    char msg[100];
    sprintf(msg, "CUDPP Summed-Area Table: %0.3f ms to create SAT", ms);
    glutSetWindowTitle(msg);
}

extern "C"
