CS155 Computer Graphics

OpenGL Picking

The purpose of this tutorial is to introduce you to the basics of OpenGL picking.
  1. Create a project:
    In VC7, create a new Visual C++ Project. Select "Win32 Console Project"as the template. Create the project on your desktop with the name "MyPickingLab1." You'll be presented with an "Applications Settings" window where you should choose "Empty Project."

    Download picking1.cpp to the project folder. Open the file from the VC7 interface and right-click to add it to the project. Build the project and run it. The application opens two windows; one is a console window and the other is an OpenGL window. The latter shows red and blue triangles.

  2. Reading from the frame buffer:
    Modify the mouse functtion to read from the frame buffer at the cursor location when the user presses the right mouse button. Check the glut manual, which is available online, for testing the button and state entered.

    Before reading any buffer we need to tell OpenGL which buffer we want to read. The framebuffer currently displayed is call the front buffer. We enable reading with the command:

    	glReadBuffer(GL_FRONT);
    
    We can read any rectangular region of the frame buffer using the glReadPixels command. It takes the following arguments:

  3. Reporting results:

    Compare the values read from the buffer and print one of the following messages:



Last updated 10/09