Lecture 4
Lecture 4
(i,j)
Pixel[i,j]
Frame buffer structure 5
Color Buffer
• Two color buffers – front and back buffers.
• Keep {r, g, b, a} values of pixels.
– In some definition, a color buffer consists of only the
RGB channels
• All drawing commands change color buffer contents.
• The R,G,B, and A channels are separate buffers.
– They are sub-buffers of the color buffer.
• Resolutions of all the buffers are the same
– Equal to the resolution of the window
1
drawing 0
window
Y-size
Rectangle to be read
/*---Read the front buffer and store its contents in image[][][], (pos_x,pos_y) is the lower-
left corner. The size is SIZE by SIZE*/
glReadPixels(pos_x, 500-pos_y, //lower left corner.視窗高度=500
XSIZE, YSIZE, //shape of the rectangle, width & height
GL_RGBA, //read RGBA channels.
GL_UNSIGNED_BYTE, //convert the data into unsigned bytes.
image); //keep data in the array image[][][4].
Frame buffer structure 16
Buffer Writing
• Write data into a rectangle in a buffer.
X_size
Y-size
Rectangle to be written
window
pos_y
Transparent
polygon