-
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.
-
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:
- x, y: bottom left window coordinates of region to read (note, the y-value supplied to the mouose function
is in screen coordinates with (0,0) at top right as opposed to frame buffer coordinates where (0,0) is the lower left corner).
- width, height: of regions to read
- format: you can read any of the available channels and many combinations. For this lab you'll probably want to use
GL_RED to read the red value and GL_BLUE to read the blue value.
- type: the data type of the pixel buffer you are providing to store the result. Since we are only interested in a single
pixel value GL_UNSIGNED_BYTE is what you'll want to use.
- pixel buffer: these can be unsigned chars (one for red and one for blue)
-
Reporting results:
Compare the values read from the buffer and print one of the following messages:
- "You picked the blue triangle."
- "You picked the red triangle."
- "You didn't pick either triangle."