bitmap: a bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a...

14
Lecture 13 Pixels, Bitmaps, Fonts, Images

Upload: clifford-lane

Post on 28-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 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:

Lecture 13

Pixels, Bitmaps, Fonts, Images

Page 2: 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:

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

Page 3: 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:

Drawing Bitmaps: ◦ First setup the position that you want to draw

using glRasterPos2i(x, y).◦ Then use glBitmap as follow to draw the bitmap: glBitmap(width, height, xbo, ybo, xbi, ybi, const GLubyte *bitmap)

Bitmaps and Fonts

Page 4: 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:

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.

Fonts and Display Lists

Page 5: 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:

Reading, Writing, and Copying Pixel: ◦ Use three 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.

Images

Page 6: 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:

Diagram of Pixel Data Flow

Page 7: 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:

glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, 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.

Reading Pixel Data from Frame Buffer to Processor Memory

Page 8: 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:

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.

Writing Pixel Data from Processor Memory to Frame Buffer

Page 9: 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:

Packing and unpacking refer to the way that pixel data is written to and read from processor memory.

During Packing and Unpacking, we are enable to manipulate the data read.

Such modifications consist of:◦ Controlling Pixel-Storage Modes◦ Pixel-Transfer Operations◦ Pixel Mapping

Pixel Packing and Unpacking

Page 10: 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:

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 glPixelStore to align the data

Controlling Pixel Storage Modes

Page 11: 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:

Controlling Pixel Storage Modes

Page 12: 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:

Controlling Pixel Storage Modes

Page 13: 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:

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.

Pixel Transfer Operations

Page 14: 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:

QUESTIONS?