title: How to give texture to a point cloud?
body: <p>I have a disparity image obtained using OpenCV. I am able to display a 640 x 360 grid of points using OpenGL and CUDA, and give to each point a Z value which corresponds to the disparity value. The result: </p>
  
  <p><img src="https://i.stack.imgur.com/ZJ72u.png" alt="screenshot"></p>
  
  <p>Now I wish to give to each point in the point cloud a colour value corresponding to the pixel in the left image of the stereo camera which have same size (640 x 380).</p>
  
  <p>This is my CUDA kernel and the calling function where I have both images, the disparity and the left image (gray scale) containing the color information:</p>
  
  <pre><code>__global__ void simple_vbo_kernel(float4 *pos, unsigned int width, unsigned int height, float time,
          uchar* disp, int stepDisp)
  {
      const int x = threadIdx.x + blockIdx.x * blockDim.x;
      const int y = threadIdx.y + blockIdx.y * blockDim.y;
       if ((x &lt; width) &amp;&amp; (y &lt; height))
       {
  
              float u = x / (float) width;
              float v = y / (float) height;
              u = u*2.0f - 1.0f;
              v = v*2.0f - 1.0f;
  
              const int depth  = y * stepDisp + x;
              float w =  static_cast&lt;float&gt;(disp[depth]);
              w/=10;
  
              pos[y*width+x] = make_float4(u, w, v, 1.0f);
       }
  
  }
  
  extern "C"
  void launch_kernel(dim3 grid, dim3 block, float4 *pos, unsigned int mesh_width,unsigned int mesh_height,
          float time, cv::Mat disp, cv::Mat left)
  {
      if(!disp.empty() &amp;&amp; !left.empty()){
  
          uchar* d_image;
          int dsize = disp.rows * disp.step;
          cudaMalloc((void**)&amp;d_image, dsize);
          cudaMemcpy(d_image, disp.ptr(), dsize, cudaMemcpyHostToDevice);
  
          simple_vbo_kernel&lt;&lt;&lt; grid, block&gt;&gt;&gt;(pos, mesh_width, mesh_height, time, d_image, disp.step);
          cudaDeviceSynchronize();
          cudaFree(d_image);
      }
  }
  </code></pre>
  
  <p>My question is, what is the easiest way to give a texture or colour to the points in the point cloud, in this case using the <code>cv::Mat left</code>? I have seen some other examples from the CUDA samples but I did not find how to do it.</p>