150 likes | 383 Views
Lecture 13 Pixels, Bitmaps, Fonts, Images. Bitmaps and Fonts. Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window. Applications: The most application of bitmaps in OpenGL is to display Fonts on the screen.
E N D
Bitmaps and Fonts • Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window. • Applications: The most application of bitmaps in OpenGL is to display Fonts on the screen. • Raster Position: Points to a location on the screen where the bitmap is drawn(Lower Left Corner). Note: Raster Position is affected by MODEL_VIEW matrix • Use glRasterPos to set Raster Position
Bitmaps and Fonts • Drawing Bitmaps: • First setup the position that you want to draw using glRasterPos2i(x, y). • Then use glBitmapas follow to draw the bitmap: glBitmap(width, height, xbo, ybo, xbi, ybi, const GLubyte *bitmap)
Fonts and Display Lists • Display lists are very useful when used with fonts. • A new list can be generated for each character and be called correspondingly when needed. • By using display lists, you can define a function that takes a text as input and prints out the input on screen.
Images • Reading, Writing, and Copying Pixel: • Usethree basic commands that manipulate image data • glReadPixels() - Reads a rectangular array of pixels from the framebuffer and stores the data in processor memory. • glDrawPixels() - Writes a rectangular array of pixels from data kept in processor memory into the framebuffer at the current raster position specified by glRasterPos*(). • glCopyPixels() - Copies a rectangular array of pixels from one part of the framebuffer to another. This command behaves similarly to a call to glReadPixels() followed by a call to glDrawPixels(), but the data is never written into processor memory.
Reading Pixel Data from Frame Buffer to Processor Memory • glReadPixels(GLintx, GLint y, GLsizei width, GLsizei height, GLenumformat, GLenum type, GLvoid*pixels) Reads pixel data from the framebuffer rectangle whose lower-left corner is at (x, y) and whose dimensions are width and height and stores it in the array pointed to by pixels. Note: If you are using double-buffer, you have to specify which buffer are you using front buffer or back buffer.
Writing Pixel Data from Processor Memory to Frame Buffer • void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *pixels) Draws a rectangle of pixel data with dimensions width and height. The pixel rectangle is drawn with its lower-left corner at the current raster position. format and type have the same meaning as with glReadPixels(). Note: If the current raster position is invalid, nothing is drawn, and the raster position remains invalid.
Pixel Packing and Unpacking • Packing and unpacking refer to the way that pixel data is written to and read from processor memory. • During Packingand Unpacking, we are enable to manipulate the data read. • Such modifications consist of: • Controlling Pixel-Storage Modes • Pixel-Transfer Operations • Pixel Mapping
Controlling Pixel Storage Modes • Packing and unpacking refer to the way that pixel data is written to and read from processor memory. • Sometimes you may be dealing with packing/unpacking a sub-image instead of the whole image. • In such conditions, controlling byte alignment may be very useful: • Different machines have different byte orders • Some machines have special hardware that works only if data is aligned in 2, 4 or 8 byte boundaries in processor memory. • In such cases, we use glPixelStoreto align the data
Pixel Transfer Operations • Before the data is written to frame-buffer or processor memory, OpenGL can perform several operations on it. • The range of a component can be changed, e.g. you may want to change the range of red component to be other than [0,1] • Or, could be that the data you are using comes from a different graphic system which stores the RGB components in a different range rather than [0,1] • In these situations use glPixelTransfer function in order to transform the data as you need.