 void onGLUTExit() {
    fprintf(stdout, "De-Allocating memory.\n");
    //Deallocate(h_flock);
+}
+
+void createVBO(GLuint *vbo, struct cudaGraphicsResource **vbo_res, unsigned int vbo_res_flags) {
+  
+  // Create buffer object and register it with CUDA
+  glGenBuffers(1, vbo);
+  glBindBuffer(GL_ARRAY_BUFFER, *vbo);
+  unsigned int size = mesh_width * mesh_height * 4 * sizeof(float);
+  glBufferData(GL_ARRAY_BUFFER, size, 0, GL_DYNAMIC_DRAW);
+  
+  // Unbind Buffer
+  glBindBuffer(GL_ARRAY_BUFFER, 0);
+  
+  // Register VBO
+  checkCudaErrors( cudaGraphicsGLRegisterBuffer(vbo_res, *vbo, vbo_res_flags) );
+}
+
+void deleteVBO(GLuint *vbo, struct cudaGraphicsResource *vbo_res) {
+  // Unregister with CUDA
+  checkCudaErrors( cudaGraphicsUnregisterResource(vbo_res) );
+
+  glBindBuffer(1, *vbo);
+  glDeleteBuffers(1, vbo);
+}
+
+void runCUDA(struct cudaGraphicsResource ** vbo_resource) {
+  // Map VBO to GL with CUDA
+  float4* positions;
+  checkCudaErrors( cudaGraphicsMapResources(1, vbo_resource, 0) );
+  size_t num_bytes;
+  checkCudaErrors( cudaGraphicsResourceGetMappedPointer((void ** )&positions,
+		  &num_bytes,
+		  vbo_resource) );
+
+  launchKernel(positions, mesh_width, mesh_height, time); 
+  // Unmap Buffer
+  checkCudaErrors( cudaGraphicsUnmapResources(1, vbo_resource, 0) );
 }
 
 __host__ int main (int argc, char* argv[]) {


#include <cuda_runtime.h>
#include <cuda_gl_interop.h>

#include <aligned_allocator.h>


}

__host__ void Render() {
  
  // Clear screen
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  // Perspective modifications
  glRotatef(rX, 1.0, 0.0, 0.0);
  glRotatef(rY, 0.0, 1.0, 0.0);
  
  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT);
  glColor3f(1.0, 0.0, 0.0);
  glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

  glBindBuffer(GL_ARRAY_BUFFER, positionsVBO);
  glVertexPointer(4, GL_FLOAT, 0, 0);
  glEnableClientState(GL_VERTEX_ARRAY);
  glDrawArrays(GL_POINTS, 0, width * height); // Where the magic happens
  glDisableClientState(GL_VERTEX_ARRAY);
  
  // Switch Buffers
  glutSwapBuffers();
  glutPostRedisplay();
}

__host__ void Keyboard(int key, int x, int y) {
