Use a semaphore for image_ready

A condition variable blocks if it has been signaled before wait was called.
Fix mapping between continuous and discrete coordinates
Use the dimension of the render target instead of the GL viewport