Date post: | 29-Sep-2015 |
Category: |
Documents |
Upload: | nghia-tran |
View: | 219 times |
Download: | 3 times |
COMPUTER GRAPHICSHochiminh city University of TechnologyFaculty of Computer Science and EngineeringCHAPTER 8:Texture Mapping
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
OUTLINEBuffersIntroduce additional OpenGL buffersLearn to read and write buffersLearn to use blendingTexture MappingTexture Mapping in OpenGLCompositing and Blending
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
BufferDefine a buffer by its spatial resolution (n x m) and its depth (or precision) k, the number of bits/pixel
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
BufferOpenGL Frame Buffer
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
BufferColor buffers can be displayedFrontBackAuxiliaryOverlayDepthAccumulationHigh resolution bufferStencilHolds masks
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing in BuffersConceptually, we can consider all of memory as a large two-dimensional array of pixelsWe read and write rectangular block of pixelsBit block transfer (bitblt) operationsThe frame buffer is part of this memory
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing ModeRead destination pixel before writing source
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing ModeSource and destination bits are combined bitwise16 possible functions (one per column in table)replaceORXOR
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing ModeglEnable(GL_COLOR_LOGIC_OP);glDisable(GL_COLOR_LOGIC_OP);glLogicOp(parameter)GL_CLEAR, GL_SET, GL_COPY, GL_COPY_INVERTED, GL_NOOP, GL_INVERT, GL_AND, GL_NAND, GL_OR, GL_NOR, GL_XOR, GL_EQUIV, GL_AND_REVERSE, GL_AND_INVERTED, GL_OR_REVERSE, GL_OR_INVERTED.
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing ModeglDisable(GL_COLOR_LOGIC_OP);glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0, 1.0, 0.0);glBegin(GL_POLYGON);glVertex2f(-1.0, -0.5); glVertex2f(-1.0, 0.5);glVertex2f(1.0, 0.5); glVertex2f(1.0, -0.5);glEnd();glEnable(GL_COLOR_LOGIC_OP);glLogicOp(GL_OR);glColor3f(0.0, 1.0, 1.0);glBegin(GL_POLYGON);glVertex2f(-0.5, -1.0); glVertex2f(-0.5, 1.0);glVertex2f(0.5, 1.0); glVertex2f(0.5, -1.0);glEnd();
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Writing ModeGL_COPYGL_ANDGL_OR
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
XOR modeUsual (default) mode: source replaces destination (d = s)Cannot write temporary lines this way because we cannot recover what was under the line in a fast simple wayExclusive OR mode (XOR) (d = d s)x y x =yHence, if we use XOR mode to write a line, we can draw it a second time and line is erased!
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
XOR modeXOR is especially useful for swapping blocks of memory such as menus that are stored off screen
If S represents screen and M represents a menuthe sequence S S M M S M S S Mswaps the S and M
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
The Pixel PipelineOpenGL has a separate pipeline for pixelsWriting pixels involvesMoving pixels from processor memory to the frame bufferFormat conversionsMapping, Lookups, TestsReading pixelsFormat conversion
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Raster PositionOpenGL maintains a raster position as part of the stateSet by glRasterPos*()glRasterPos3f(x, y, z);The raster position is a geometric entityPasses through geometric pipelineEventually yields a 2D position in screen coordinatesThis position in the frame buffer is where the next raster primitive is drawn
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Buffer SelectionOpenGL can draw into or read from any of the color buffers (front, back, auxiliary)Default to the back bufferChange with glDrawBuffer and glReadBufferNote that format of the pixels in the frame buffer is different from that of processor memory and these two types of memory reside in different placesNeed packing and unpackingDrawing and reading can be slow
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
BitmapsOpenGL treats 1-bit pixels (bitmaps) differently from multi-bit pixels (pixelmaps)Bitmaps are masks that determine if the corresponding pixel in the frame buffer is drawn with the present raster color0 color unchanged1 color changed based on writing modeBitmaps are useful for raster textGLUT font: GLUT_BIT_MAP_8_BY_13
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Raster ColorSame as drawing color set by glColor*()Fixed by last call to glRasterPos*()glColor3f(1.0, 0.0, 0.0);glRasterPos3f(x, y, z);glColor3f(0.0, 0.0, 1.0);glBitmap(.glBegin(GL_LINES); glVertex3f(..)Geometry drawn in blueOnes in bitmap use a drawing color of red
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Drawing Bitmaps
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Example: Checker Board
Faculty of Computer Science and Engineering
Slide *Faculty of Computer Science and Engineering - HCMUT
Example: Checker BoardGLubyte wb[2] = {0x00, 0xff};GLubyte check[512];intidx, i, j;for(i=0; i