Download presentation
Presentation is loading. Please wait.
Published bySilvia Potter Modified over 9 years ago
1
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next bitmap (or image) is to be drawn. void glRasterPos2{sifd}(TYPE x, TYPE y) void glRasterPos3{sifd}(TYPE x, TYPE y, TYPE z) void glRasterPos {234}{sifd}v(TYPE * coords) void glRasterPos4{sifd}(TYPE x, TYPE y, TYPE z, TYPE h) Sets the current raster position. (x, y, z, h) is treated as object coordinates and is transformed by current modelview matrix, projection matrix and viewport. The transformed position is stored as current raster position.
2
Bitmap: An array of bit values (0 or 1). Bitmaps void glBitmap(GLsizei width, GLsizei height, GLfloat xo, GLfloat yo, GLfloat xi, GLfloat yi, const GLubyte * bitmap) Draw a bitmap at current raster position. width, height:Width and height of the bitmap in pixels. xo, yo:Origin of the bitmap relative to its lower-left corner. xi, yi:x and y offsets to be added to the current raster position after the bitmap is drawn. bitmap:Array that stores the bitmap Pixel corresponding to “1” in bitmap is written using current raster color. Pixel corresponding to “0” in bitmap is unchanged. Current raster color is set to current color when glRasterPos*() is called.
3
The bits in a bitmap must be stored in chunks of 8 and start from lower left corner. But the width of the actually bitmap doesn't have to be multiple of 8. 0xff, 0xc0 GLubyte bitmap_F[] = {0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0}; glBitmap(10, 12, 0.0, 0.0, 11.0, 0.0, bitmap_F); 0xff, 0xc0 0xc0, 0x00 0xff, 0x00 0xc0, 0x00
4
GLUT Bitmap Font void glutBitmapCharacter(void *font, int character) Render character with given font at current raster position. The width of the character is added to the x coordinate of current raster position. Internally GLUT implements this function using glBitmap(). fontbitmap font GLUT_BITMAP_8_BY_13 8 by 13 fixed width font GLUT_BITMAP_9_BY_15 9 by 15 fixed width font GLUT_BITMAP_TIMES_ROMAN_1 0 10-point Times Roman GLUT_BITMAP_TIMES_ROMAN_2 4 24-point Times Roman GLUT_BITMAP_HELVETICA_10 10-point Helvetica GLUT_BITMAP_HELVETICA_12 12-point Helvetica GLUT_BITMAP_HELVETICA_18 18-point Helvetica
5
To render a null-terminated string: void DrawString(void *font, char *str) { while((*str)!='\0') { glutBitmapCharacter(font,(int)*str); str++; } int glutBitmapWidth(void * font, int character) Return the width, in pixels, of character with given font
6
Using Fonts in Windows BOOL wglUseFontBitmaps( HDC hdc, DWORD first, DWORD count, DWORD listBase) hdc:Specifies the device context with the desired bitmap font. first:Specifies the first glyph. count:Specifies the number of glyphs. listBase:Specifies a starting display list. This function creates count display lists in the current OpenGL rendering context. Each display list consists of a single call to glBitmap. Display list listBase+i corresponds to glyph first+i of the font currently selected in the device context specified by hdc, i = 0, 1, 2,..., count 1. HFONT hfont = CreateFont(......); SelectObject(hdc, hfont);
7
BOOL wglUseFontOutlines(HDC hdc, DWORD first, DWORD count, DWORD listBase, FLOAT deviation, FLOAT extrusion, int format, LPGLYPHMETRICSFLOAT lpgmf) hdc:Specifies the device context with the desired outline font. first:Specifies the first glyph. count:Specifies the number of glyphs. listBase:Specifies a starting display list. deviation:Specifies the maximum chordal deviation from the original outlines. extrusion:Specifies how much a font is extruded in the negative z direction. format:WGL_FONT_LINES or WGL_FONT_POLYGONS. lpgmf :Points to an array of GLYPHMETRICSFLOAT structures that is to receive the metrics of the glyphs. When lpgmf is NULL, no glyph metrics are returned. This function creates count display lists in the current OpenGL rendering context. Display list listBase+i corresponds to glyph first+i of the font currently selected in the device context specified by hdc, i = 0, 1, 2,..., count 1. The size of the font is 1.0 in x and y direction and extrusion in z direction.
8
Image Pipeline Image: An array of pixel values. Pixel values are not limited to color values, they can also be depth values or stencil values. OpenGL does not support reading images from or saving images to files. System Memory Frame Buffer Pixel Storage Modes Pixel Transfer Operations (Pixel Map) UnpackPack Rasterization (Pixel Zoom) Fragment Operations Texture Memory
9
Reading, Writing and Copying Pixel Data Reading Pixel Data from Frame Buffer to System Memory System Memory Frame Buffer Pixel Storage Modes Pixel Transfer Operations (Pixel Map) UnpackPack Rasterization (Pixel Zoom) Fragment Operations Texture Memory
10
void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) Read pixel data from a frame buffer rectangle to system memory. x, y:Lower left corner of the frame buffer rectangle width, height:Width and height of the frame buffer rectangle format:Pixel data elements to be read type:Data type of each pixel data element pixels:System memory to receive pixel data formatPixel data element GL_RGBRed, Green, Blue components GL_RGBARed, Green, Blue, Alpha components GL_BGRBlue, Green, Red components GL_BGRABlue, Green, Red, Alpha components Pixel data element formats
11
formatPixel data element GL_REDRed component GL_GREENGreen component GL_BLUEBlue component GL_ALPHAAlpha component GL_LUMINANCELuminance component GL_LUMINANCE_ALPHALuminance and Alpha component GL_STENCIL_INDEXStencil value GL_DEPTH_COMPONENTDepth value Luminance = (Red + Green + Blue) / 3 Pixel data element formats (continued) GL_BGR and GL_BGRA pixel formats were added in OpenGL 1.2.
12
typeData type GL_UNSIGNED_BYTEunsigned 8-bit integer GL_BYTE8-bit integer GL_UNSIGNED_SHORTunsigned 16-bit integer GL_SHORT16-bit integer GL_UNSIGNED_INTunsigned 32-bit integer GL_INT32-bit integer GL_FLOATsingle-precision floating point GL_BITMAPsingle bits in unsigned 8-bit integer Normal data types for pixel data element Each element is scaled to fit the range of the specified data type.
13
typeData type GL_UNSIGNED_BYTE_3_3_2packed unsigned 8-bit integer GL_UNSIGNED_BYTE_2_3_3_REVpacked unsigned 8-bit integer GL_UNSIGNED_SHORT_5_6_5packed unsigned 16-bit integer GL_UNSIGNED_SHORT_5_6_5_REVpacked unsigned 16-bit integer GL_UNSIGNED_SHORT_4_4_4_4packed unsigned 16-bit integer GL_UNSIGNED_SHORT_4_4_4_4_REVpacked unsigned 16-bit integer GL_UNSIGNED_SHORT_5_5_5_1packed unsigned 16-bit integer GL_UNSIGNED_SHORT_1_5_5_5_REVpacked unsigned 16-bit integer GL_UNSIGNED_INT_8_8_8_8packed unsigned 32-bit integer GL_UNSIGNED_INT_8_8_8_8_REVpacked unsigned 32-bit integer GL_UNSIGNED_INT_10_10_10_2packed unsigned 32-bit integer GL_UNSIGNED_INT_2_10_10_10_REVpacked unsigned 32-bit integer Packed data types for pixel data element (added in OpenGL 1.2)
14
typeValid Pixel Element Formats GL_UNSIGNED_BYTE_3_3_2GL_RGB GL_UNSIGNED_BYTE_2_3_3_REVGL_RGB GL_UNSIGNED_SHORT_5_6_5GL_RGB GL_UNSIGNED_SHORT_5_6_5_REVGL_RGB GL_UNSIGNED_SHORT_4_4_4_4GL_RGBA, GL_BGRA GL_UNSIGNED_SHORT_4_4_4_4_REVGL_RGBA, GL_BGRA GL_UNSIGNED_SHORT_5_5_5_1GL_RGBA, GL_BGRA GL_UNSIGNED_SHORT_1_5_5_5_REVGL_RGBA, GL_BGRA GL_UNSIGNED_INT_8_8_8_8GL_RGBA, GL_BGRA GL_UNSIGNED_INT_8_8_8_8_REVGL_RGBA, GL_BGRA GL_UNSIGNED_INT_10_10_10_2GL_RGBA, GL_BGRA GL_UNSIGNED_INT_2_10_10_10_REVGL_RGBA, GL_BGRA Valid pixel element formats for packed data types
15
RedGreenBlue 01234567 GL_UNSIGNED_BYTE_3_3_2 with GL_RGB RedGreenBlue 01234567 GL_UNSIGNED_BYTE_2_3_3_REV with GL_RGB Example of packed data types:
16
RedGreenBlueAlpha 0123456789101112131415 GL_UNSIGNED_SHORT_4_4_4_4_REV with GL_RGBA RedGreenBlueAlpha 0123456789101112131415 GL_UNSIGNED_SHORT_4_4_4_4_REV with GL_BGRA RedGreenBlueAlpha 0123456789101112131415 GL_UNSIGNED_SHORT_4_4_4_4 with GL_RGBA RedGreenBlueAlpha 0123456789101112131415 GL_UNSIGNED_SHORT_4_4_4_4 with GL_BGRA
17
Writing Pixel Data from System Memory to Frame Buffer System Memory Frame Buffer Pixel Storage Modes Pixel Transfer Operations (Pixel Map) UnpackPack Rasterization (Pixel Zoom) Fragment Operations Texture Memory
18
void glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) Draw a rectangle of pixel data from system memory to frame buffer. The lower left corner of the pixel rectangle to be drawn is the current raster position. width, height:Width and height of the pixel rectangle format:Pixel data elements to be written type:Data type of each pixel data element pixels:System memory that stores the pixel data format and type have the same meaning as with glReadPixels().
19
Copying Pixel Data inside Frame Buffer System Memory Frame Buffer Pixel Storage Modes Pixel Transfer Operations (Pixel Map) UnpackPack Rasterization (Pixel Zoom) Fragment Operations Texture Memory
20
void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum buffer) Copy pixel data from one frame buffer rectangle (source) to another frame buffer rectangle (destination). The lower left corner of the destination rectangle is the current raster position. x, y:Lower left corner of the source rectangle width, height:Width and height of the pixel rectangle buffer:GL_COLOR, GL_STENCIL, GL_DEPTH Note: glCopyPixels() does not need data format or type information and it is not affected by pixel storage modes.
21
Pixel Storage Modes Packing:The way in which pixel data is written to system memory. Unpacking:The way in which pixel data is read from system memory. System Memory Frame Buffer Pixel Storage Modes Pixel Transfer Operations (Pixel Map) UnpackPack Rasterization (Pixel Zoom) Fragment Operations Texture Memory void glPixelStorei(GLenum pname, GLint param) void glPixelStoref(GLenum pname, GLfloat param) Set pixel storage modes. pname: parameter name. param: parameter value.
22
Parameter nameTypeInitial valueValid range GL_UNPACK_ALIGNMENT GL_PACK_ALIGNMENT GLint41, 2, 4, 8 GL_UNPACK_SWAP_BYTES GL_PACK_SWAP_BYTES GLbooleanGL_FALSEGL_TRUE, GL_FALSE GL_UNPACK_LSB_FIRST GL_PACK_LSB_FIRST GLbooleanGL_FALSEGL_TRUE, GL_FALSE GL_UNPACK_ROW_LENGTH GL_PACK_ROW_LENGTH GLint0non-negative integer GL_UNPACK_SKIP_ROWS GL_PACK_SKIP_ROWS GLint0non-negative integer GL_UNPACK_SKIP_PIXELS GL_PACK_SKIP_PIXELS GLint0non-negative integer LSB: Least Significant Bit.
23
*ALIGNMENT Sets the byte alignment requirement for pixel data in system memory. 1:Data is aligned on 8-bit address boundary in system memory 2:Data is aligned on 16-bit address boundary in system memory 4:Data is aligned on 32-bit address boundary in system memory 8:Data is aligned on 64-bit address boundary in system memory *SWAP_BYTES Defines if the byte order in multi-byte data element is reversed. *LSB_FIRST Defines if the bits within a byte data are ordered from least significant bit to most significant bit.
24
*ROW_LENGTH, *SKIP_ROWS, *SKIP_PIXELS These parameters are used when we only want to draw or read a sub-image of an entire image data in system memory. Sub-Image Image *ROW_LENGTH *SKIP_ROWS *SKIP_PIXELS
25
Pixel Transfer Operations Pixel transfer operations perform conversions on pixel data. void glPixelTransferi(GLenum pname, GLint param) void glPixelTransferf(GLenum pname, GLfloat param) void glPixelMapuiv(GLenum map, GLint size, const GLuint *values) void glPixelMapusv(GLenum map, GLint size, const GLushort *values) void glPixelMapfv(GLenum map, GLint size, const GLfloat *values)
26
Pixel Zoom void glPixelZoom(GLfloat zx, GLfloat zy) Set pixel zoom factors. zx:Pixel zoom factor in x direction. Default value is 1.0. zy:Pixel zoom factor in y direction. Default value is 1.0. Zoom factors with magnitude greater than one magnify the image. Zoom factors with magnitude less than one minify the image. Negative zoom factors reflect the image about the current raster position.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.