OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.

Slides:



Advertisements
Similar presentations
©Zachary Wartell, UNCC9/28/ :30 AM 1 Overview of OpenGL Revision: 1.2 Copyright Professor Zachary Wartell, University of North Carolina All Rights.
Advertisements

Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
OpenGL Fragment Operations
Graphics Pipeline.
Computer Graphics(Fall 2003) COMS 4160, Lecture 7: OpenGL 3 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
OPENGL Return of the Survival Guide. Buffers (0,0) OpenGL holds the buffers in a coordinate system such that the origin is the lower left corner.
University of Sulaimani - School of Science - Computer Dept.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
OpenGL Son of the Survival Guide. Last Time on OpenGL Windowing … glut Rendering Primatives Transformations Projections State Management.
Buffers Mohan Sridharan Based on slides created by Edward Angel 1 CS4395: Computer Graphics.
Buffers Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Introduction to OpenGL (Part 3) Ref: OpenGL Programming Guide (The Red Book)
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Picking. What is picking? Selecting an object on the screen What does this require? –Get Mouse Location –Compute what objects are rendered at the position.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
 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:
Computer Graphics Texture Mapping Eriq Muhammad Adams
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
Texture Mapping + Texture Object = Texture Mapped Object.
Speeding Up Rendering After Deciding What to Draw.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
2002 by Jim X. Chen: 1 So far, we only concerned with the rendering of geometric data. Two other important classes of data:
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
OpenGL Conclusions OpenGL Programming and Reference Guides, other sources CSCI 6360/4360.
Discrete Techniques Chapter 7 Begun February 22, 2005 Finished April 26, 2005.
Review of OpenGL Basics
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
CSE 381 – Advanced Game Programming GLSL. Rendering Revisited.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chap 11. Raster Graphics in OpenGL. Chap 11. Raster Graphic in OpenGL2 Content Draw bitmap image Use bitmap fonts Draw color images Read and copy color.
Computer Graphics Bing-Yu Chen National Taiwan University.
Buffers Computer Graphics I, Fall 2010.
Lecture 2: Introduction to OpenGL
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
Buffers. 2 Objectives Introduce additional OpenGL buffers Learn to read and write buffers Learn to use blending.
Programming with Visual Studio MFC and OpenGL. Outline Creating a project Adding OpenGL initialization code and libraries Creating a mouse event Drawing.
Tan-Chi Ho, CGGM Lab., CSIE of NCTU Pixel Operations and Buffers.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
Chapter 8. Drawing Pixels, Bitmaps, Fonts, and Images Computer Graphics (spring, 2009) School of Computer Science University of Seoul.
Buffers Ed Angel Professor Emeritus of Computer Science
Texture Mapping Fall, 2016.
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Introduction to Computer Graphics with WebGL
Geb Thomas Adapted from the OpenGL Programming Guide
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Class 26 more textures environmental textures Color ramps
Display Lists & Text Glenn G. Chappell
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Computer Graphics Buffers
Textures Lecture 11 Wed, Oct 5, 2005.
Buffers Ed Angel Professor Emeritus of Computer Science
Class 27 more textures environmental textures Color ramps
Presentation transcript:

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.

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.

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

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_ point Times Roman GLUT_BITMAP_TIMES_ROMAN_ point Times Roman GLUT_BITMAP_HELVETICA_10 10-point Helvetica GLUT_BITMAP_HELVETICA_12 12-point Helvetica GLUT_BITMAP_HELVETICA_18 18-point Helvetica

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

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);

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.

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

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

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

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.

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.

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)

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

RedGreenBlue GL_UNSIGNED_BYTE_3_3_2 with GL_RGB RedGreenBlue GL_UNSIGNED_BYTE_2_3_3_REV with GL_RGB Example of packed data types:

RedGreenBlueAlpha GL_UNSIGNED_SHORT_4_4_4_4_REV with GL_RGBA RedGreenBlueAlpha GL_UNSIGNED_SHORT_4_4_4_4_REV with GL_BGRA RedGreenBlueAlpha GL_UNSIGNED_SHORT_4_4_4_4 with GL_RGBA RedGreenBlueAlpha GL_UNSIGNED_SHORT_4_4_4_4 with GL_BGRA

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

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().

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

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.

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.

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.

*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.

*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

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)

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.