Docsity

Interactive Computer Graphics: Blending, Compositing, and Transparency - Prof. David E. Br, Study notes of Computer Graphics

Partial preview of the text

Download Interactive Computer Graphics: Blending, Compositing, and Transparency - Prof. David E. Br and more Study notes Computer Graphics in PDF only on Docsity!

Buffers,

Compositing and Blending

Week 8

David Breen

Department of Computer Science

Drexel University

Based on material from Ed Angel, University of New Mexico

Han-Wei Shen, Ohio State University

David Blythe, Silicon Graphics & Tom McReynolds, Gigapixel

CS 432/

INTERACTIVE COMPUTER GRAPHICS

Angel: Interactive Computer Graphics 3E 2

Objectives

• Introduce additional OpenGL buffers

• Learn to read and write buffers

• Learn to use blending

• Learn depth-of-field and reflection

effects

Angel: Interactive Computer Graphics 3E 4

OpenGL Frame Buffer

Angel: Interactive Computer Graphics 3E 5

OpenGL Buffers

  • Color buffers can be displayed
    • Front
    • Back
    • Auxiliary
    • Overlay
  • Depth
  • Accumulation
    • High resolution buffer
  • Stencil
    • Holds masks

Angel: Interactive Computer Graphics 3E 7

Writing Model

Read destination pixel before writing source

glLogicOp(GLenum op)

Angel: Interactive Computer Graphics 3E 8

Writing Modes

  • Source and destination bits are combined

bitwise

  • 16 possible functions (one per column in table)

replace OR

XOR

AND NOT(s)

Angel: Interactive Computer Graphics 3E 10

The Pixel Pipeline

  • OpenGL has a separate pipeline for pixels
    • Writing pixels involves
      • Moving pixels from processor memory to the frame buffer
      • Packing (Format conversions, swapping & alignment)
      • Transfer ops, Map Lookups, Tests
    • Reading pixels
      • Unpacking (Format conversion, swapping & alignment)

Angel: Interactive Computer Graphics 3E 11

Pixel Transfer Operations

• Color Scale & Bias

• Color Index Shift & Offset

• Convolution

• Matrix multiply

glPixelTransferf(GL_RED_SCALE, s);

glPixelTransferf(GL_BLUE_BIAS, b);

Angel: Interactive Computer Graphics 3E 13

Pixel Tests

• Scissor glScissor()

  • Only draw in a rectangular portion of screen

• Alpha glAlphaFunc()

  • Draw based on alpha value

• Stencil glStencilFunc(), glStencilOp()

  • Draw based on stencil value

• Depth glDepthFunc(),

  • Draw based on depth value

Angel: Interactive Computer Graphics 3E 14

Raster Position

  • OpenGL maintains a raster position as part of

the state

  • Set by glRasterPos()*
    • glRasterPos3f(x, y, z);
  • The raster position is a geometric entity (like

a vertex)

  • Passes through geometric pipeline
  • Eventually yields a 2D position in screen

coordinates

  • This position in the frame buffer is where the next

raster primitive is drawn

Angel: Interactive Computer Graphics 3E 16

Buffer Selection

  • OpenGL can draw into or read from any of the color

buffers (front, back, auxiliary)

  • Default to the back buffer
  • Change with glDrawBuffer and glReadBuffer
  • Note 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 places

  • Need packing and unpacking
  • Drawing and reading can be slow

Angel: Interactive Computer Graphics 3E 17

Bitmaps

  • OpenGL treats 1-bit pixels ( bitmaps )

differently than multi-bit pixels ( pixelmaps )

  • Bitmaps are masks which determine if the

corresponding pixel in the frame buffer is

drawn with the present raster color

  • 0 ⇒ color unchanged
  • 1 ⇒ color changed based on writing mode
  • Bitmaps are useful for raster text
  • GLUT_BIT_MAP_8_BY_

Angel: Interactive Computer Graphics 3E 19

Drawing Bitmaps

glBitmap(width, height, x0, y0, xi, yi,

bitmap)

first raster position

second raster position

offset from raster

position

increments in

raster

position after

bitmap drawn

Angel: Interactive Computer Graphics 3E 20

Example: Checker Board

GLubyte wb[2] = {0 x 00, 0 x ff};

GLubyte check[4096];

int i, j;

for(i=0; i<64; i++) for (j=0; j<64, j++)

check[i*8+j] = wb[(i/8+j/8)%2];

glBitmap( 64, 64, 0.0, 0.0, 0.0, 0.0, check);