We call the app flashlight because it produces a directable circle of light whose intensity diminishes away from the center of the “spot.” Figure 4.1 shows the screenshot of the app in its finished state.įigure 4.1 Interactive spot of light in the finished application
Here we present the code for a sample app that opens a graphics window and interactively displays an image based on distance to a reference point that can be changed interactively using keyboard or mouse input. CUDA/OpenGL interop provides interactive controls and displays the changing scene as a texture on the displayed rectangle in real time (or, more accurately, at a rate comparable to the ~60Hz refresh rate typical of modern visual display systems). The idea is that the rectangle provides a window into the world of your app, and you can use CUDA to compute the pixel shading values corresponding to whatever scene you want the user to see. We introduce just enough OpenGL to display a single textured rectangle and provide a few examples of code to support interactions via keyboard and mouse with the help of the OpenGL Utility Toolkit (GLUT). We will be using OpenGL, which could be (and is) the subject of numerous books all by itself 2, 4, 5, so we will take our usual need-to-know approach. Real-time graphic interactivity will involve CUDA’s provision for interoperability with a standard graphics package. Now that we can construct apps that produce image data, it makes sense to start displaying those images and exploring what CUDA’s massive parallelism enables us to do in real time. Learn More Buy Live Display via Graphics Interop CUDA for Engineers: An Introduction to High-Performance Parallel Computing