CIS 636
Download
1 / 81

original - PowerPoint PPT Presentation


  • 250 Views
  • Updated On :

CIS 636 Introduction to Computer Graphics CG Basics 5 of 8: OpenGL Primer, Part 2 of 3 William H. Hsu Department of Computing and Information Sciences, KSU KSOL course pages: http://snipurl.com/1y5gc Course web site: http://www.kddresearch.org/Courses/CIS636

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'original' - paul


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Slide1 l.jpg

CIS 636Introduction to Computer Graphics

CG Basics 5 of 8:

OpenGL Primer, Part 2 of 3

William H. Hsu

Department of Computing and Information Sciences, KSU

KSOL course pages: http://snipurl.com/1y5gc

Course web site: http://www.kddresearch.org/Courses/CIS636

Instructor home page: http://www.cis.ksu.edu/~bhsu

Readings:

All slides from SIGGRAPH 2000 tutorial on OpenGL, Shreiner, Angel, Shreiner: http://www.cs.unm.edu/~angel/SIGGRAPH/

Sections 2.6, 3.1, 20.3 – 20.13, Eberly 2e – see http://snurl.com/1ye72

NeHe tutorials: 6 – 10, http://nehe.gamedev.net

Article: http://www.kuro5hin.org/story/2003/10/28/9853/1617

CIS 636/736: (Introduction to) Computer Graphics


Slide2 l.jpg

Lecture Outline

  • Four More Short OpenGL Tutorials from SIGGRAPH 2000

  • Vicki Shreiner: Animation and Depth Buffering

    • Double buffering

    • Illumination: light positioning, light models, attenuation

    • Material properties

    • Animation basics in OpenGL

  • Vicki Shreiner: Imaging and Raster Primitives

  • Ed Angel: Texture Mapping

  • Dave Shreiner: Advanced Topics

    • Display lists and vertex arrays

    • Accumulation buffer

    • Fog

    • Stencil buffering

    • Fragment programs (to be concluded in Tutorial 3)

CIS 636/736: (Introduction to) Computer Graphics


Animation and depth buffering l.jpg

Animation and Depth Buffering

Vicki Shreiner

CIS 636/736: (Introduction to) Computer Graphics


Animation and depth buffering4 l.jpg
Animation and Depth Buffering

  • Double buffering and animation

  • Using depth buffer

    • Hidden surface removal

    • aka visible surface determination

CIS 636/736: (Introduction to) Computer Graphics


Double buffering l.jpg

Per

Vertex

Poly.

Frag

FB

Raster

CPU

DL

Texture

Pixel

1

1

2

2

4

4

Front

Buffer

Back

Buffer

8

8

16

16

Display

Double Buffering

CIS 636/736: (Introduction to) Computer Graphics


Animation using double buffering l.jpg
Animation using Double Buffering

  • Request a double buffered color buffer

    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );

  • Clear color buffer

    glClear( GL_COLOR_BUFFER_BIT );

  • Render scene

  • Request swap of front and back buffers

    glutSwapBuffers();

  • Repeat steps 2 - 4 for animation

CIS 636/736: (Introduction to) Computer Graphics


Depth buffering and hidden surface removal l.jpg
Depth Buffering andHidden Surface Removal

1

1

2

2

4

4

Color

Buffer

Depth

Buffer

8

8

16

16

Display

CIS 636/736: (Introduction to) Computer Graphics


Depth buffering using opengl l.jpg
Depth Buffering Using OpenGL

  • Request a depth buffer

    glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );

  • Enable depth buffering

    glEnable( GL_DEPTH_TEST );

  • Clear color and depth buffers

    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

  • Render scene

  • Swap color buffers

CIS 636/736: (Introduction to) Computer Graphics


Updated program template 1 l.jpg
Updated Program Template [1]

void main( int argc, char** argv )

{

glutInit( &argc, argv );

glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );

glutCreateWindow( “Tetrahedron” );

init();

glutIdleFunc( idle );

glutDisplayFunc( display );

glutMainLoop();

}

CIS 636/736: (Introduction to) Computer Graphics


Updated program template 2 l.jpg
Updated Program Template [2]

void init( void ){ glClearColor( 0.0, 0.0, 1.0, 1.0 );}void idle( void ){ glutPostRedisplay();}

CIS 636/736: (Introduction to) Computer Graphics


Updated program template 3 l.jpg
Updated Program Template [3]

void drawScene( void )

{

GLfloat vertices[] = { … };

GLfloat colors[] = { … };

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glBegin( GL_TRIANGLE_STRIP );

/* calls to glColor*() and glVertex*() */

glEnd();

glutSwapBuffers();

}

CIS 636/736: (Introduction to) Computer Graphics


Lighting l.jpg

Lighting

Dave Shreiner

CIS 636/736: (Introduction to) Computer Graphics


Lighting principles l.jpg
Lighting Principles

  • Lighting simulates how objects reflect light

    • material composition of object

    • light’s color and position

    • global lighting parameters

      • ambient light

      • two sided lighting

    • available in both color indexand RGBA mode

CIS 636/736: (Introduction to) Computer Graphics


How opengl simulates lights l.jpg
How OpenGL Simulates Lights

  • Phong lighting model

    • Computed at vertices

  • Lighting contributors

    • Surface material properties

    • Light properties

    • Lighting model properties

CIS 636/736: (Introduction to) Computer Graphics


Surface normals l.jpg

Per

Vertex

Poly.

Frag

FB

Raster

CPU

DL

Texture

Pixel

Surface Normals

  • Normals define how a surface reflects light

    glNormal3f( x, y, z )

    • Current normal is used to compute vertex’s color

    • Use unit normals for proper lighting

      • scaling affects a normal’s length

        glEnable( GL_NORMALIZE )orglEnable( GL_RESCALE_NORMAL )

CIS 636/736: (Introduction to) Computer Graphics


Material properties l.jpg
Material Properties

  • Define the surface properties of a primitive

    glMaterialfv( face, property, value );

    • separate materials for front and back

CIS 636/736: (Introduction to) Computer Graphics


Light properties l.jpg
Light Properties

glLightfv( light, property, value );

  • light specifies which light

    • multiple lights, starting with GL_LIGHT0

      glGetIntegerv( GL_MAX_LIGHTS, &n );

  • properties

    • colors

    • position and type

    • attenuation

CIS 636/736: (Introduction to) Computer Graphics


Light sources l.jpg
Light Sources

  • Light color properties

    • GL_AMBIENT

    • GL_DIFFUSE

    • GL_SPECULAR

CIS 636/736: (Introduction to) Computer Graphics


Types of lights l.jpg
Types of Lights

  • OpenGL supports two types of Lights

    • Local (Point) light sources

    • Infinite (Directional) light sources

  • Type of light controlled by w coordinate

CIS 636/736: (Introduction to) Computer Graphics


Turning on the lights l.jpg
Turning on the Lights

  • Flip each light’s switch

    glEnable( GL_LIGHTn );

  • Turn on power

    glEnable( GL_LIGHTING );

CIS 636/736: (Introduction to) Computer Graphics


Light material tutorial l.jpg
Light Material Tutorial

CIS 636/736: (Introduction to) Computer Graphics


Controlling a light s position l.jpg
Controlling a Light’s Position

  • Modelview matrix affects a light’s position

    • Different effects based on whenposition is specified

      • eye coordinates

      • world coordinates

      • model coordinates

    • Push and pop matrices to uniquely control a light’s position

CIS 636/736: (Introduction to) Computer Graphics


Light position tutorial l.jpg
Light Position Tutorial

CIS 636/736: (Introduction to) Computer Graphics


Advanced lighting features 1 l.jpg
Advanced Lighting Features [1]

  • Spotlights

    • localize lighting affects

      • GL_SPOT_DIRECTION

      • GL_SPOT_CUTOFF

      • GL_SPOT_EXPONENT

CIS 636/736: (Introduction to) Computer Graphics


Advanced lighting features 2 l.jpg
Advanced Lighting Features [2]

  • Light attenuation

    • decrease light intensity with distance

      • GL_CONSTANT_ATTENUATION

      • GL_LINEAR_ATTENUATION

      • GL_QUADRATIC_ATTENUATION

CIS 636/736: (Introduction to) Computer Graphics


Light model properties l.jpg
Light Model Properties

glLightModelfv( property, value );

  • Enabling two sided lighting

    GL_LIGHT_MODEL_TWO_SIDE

  • Global ambient color

    GL_LIGHT_MODEL_AMBIENT

  • Local viewer mode

    GL_LIGHT_MODEL_LOCAL_VIEWER

  • Separate specular color

    GL_LIGHT_MODEL_COLOR_CONTROL

CIS 636/736: (Introduction to) Computer Graphics


Tips for better lighting l.jpg
Tips for Better Lighting

  • Recall lighting computed only at vertices

    • model tessellation heavily affects lighting results

      • better results but more geometry to process

  • Use a single infinite light for fastest lighting

    • minimal computation per vertex

CIS 636/736: (Introduction to) Computer Graphics


Imaging and raster primitives l.jpg

Imaging and Raster Primitives

Vicki Shreiner

CIS 636/736: (Introduction to) Computer Graphics


Imaging and raster primitives29 l.jpg
Imaging and Raster Primitives

  • Describe OpenGL’s raster primitives: bitmaps and image rectangles

  • Demonstrate how to get OpenGL to read and render pixel rectangles

CIS 636/736: (Introduction to) Computer Graphics


Pixel based primitives l.jpg
Pixel-based primitives

  • Bitmaps

    • 2D array of bit masks for pixels

      • update pixel color based on current color

  • Images

    • 2D array of pixel color information

      • complete color information for each pixel

  • OpenGL doesn’t understand image formats

CIS 636/736: (Introduction to) Computer Graphics


Pixel pipeline l.jpg

Per

Vertex

Poly.

Frag

FB

Raster

CPU

DL

Texture

Pixel

Pixel Pipeline

  • Programmable pixel storage and transfer operations

glBitmap(), glDrawPixels()

Rasterization

(including

Pixel Zoom)

Pixel

Storage

Modes

Pixel-Transfer

Operations

(and Pixel Map)

Per FragmentOperations

FrameBuffer

CPU

glCopyTex*Image();

TextureMemory

glReadPixels(), glCopyPixels()

CIS 636/736: (Introduction to) Computer Graphics


Positioning image primitives l.jpg
Positioning Image Primitives

glRasterPos3f( x, y, z )

  • raster position transformed like geometry

  • discarded if raster position isoutside of viewport

    • may need to fine tuneviewport for desired results

Raster Position

CIS 636/736: (Introduction to) Computer Graphics


Rendering bitmaps l.jpg

height

yorig

width

xorig

xmove

Rendering Bitmaps

glBitmap( width, height, xorig, yorig, xmove, ymove, bitmap )

  • render bitmap in current colorat

  • advance raster position by after rendering

CIS 636/736: (Introduction to) Computer Graphics


Rendering fonts using bitmaps l.jpg
Rendering Fonts using Bitmaps

  • OpenGL uses bitmaps for font rendering

    • each character stored in display list containing bitmap

    • window system specific routines to access system fonts

      • glXUseXFont()

      • wglUseFontBitmaps()

CIS 636/736: (Introduction to) Computer Graphics


Rendering images l.jpg
Rendering Images

glDrawPixels( width, height, format, type, pixels )

  • render pixels with lower left ofimage at current raster position

  • numerous formats and data typesfor specifying storage in memory

    • best performance by using format and type that matches hardware

CIS 636/736: (Introduction to) Computer Graphics


Reading pixels l.jpg
Reading Pixels

glReadPixels( x, y, width, height, format, type, pixels )

  • read pixels from specified (x,y) position in framebuffer

  • pixels automatically converted from framebuffer format into requested format and type

  • Framebuffer pixel copy

    glCopyPixels( x, y, width, height, type )

  • CIS 636/736: (Introduction to) Computer Graphics


    Pixel zoom l.jpg

    RasterPosition

    glPixelZoom(1.0, -1.0);

    Pixel Zoom

    glPixelZoom( x, y )

    • expand, shrink or reflect pixelsaround current raster position

    • fractional zoom supported

    CIS 636/736: (Introduction to) Computer Graphics


    Storage and transfer modes l.jpg
    Storage and Transfer Modes

    • Storage modes control accessing memory

      • byte alignment in host memory

      • extracting a subimage

    • Transfer modes allow modify pixel values

      • scale and bias pixel component values

      • replace colors using pixel maps

    CIS 636/736: (Introduction to) Computer Graphics


    Texture mapping l.jpg

    Texture Mapping

    Ed Angel

    CIS 636/736: (Introduction to) Computer Graphics


    Texture mapping40 l.jpg

    Per

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Texture Mapping

    • Apply 1-D, 2-D, or 3-D image to geometric primitives

    • Uses of Texturing

      • simulating materials

      • reducing geometric complexity

      • image warping

      • reflections

    CIS 636/736: (Introduction to) Computer Graphics


    Texture mapping41 l.jpg

    y

    z

    x

    t

    s

    Texture Mapping

    screen

    geometry

    image

    CIS 636/736: (Introduction to) Computer Graphics


    Texture mapping and opengl pipeline l.jpg

    Images and geometry flow through separate pipelines that join at the rasterizer

    “complex” textures do not affect geometric complexity

    geometry pipeline

    vertices

    rasterizer

    image

    pixel pipeline

    Texture Mapping andOpenGL Pipeline

    CIS 636/736: (Introduction to) Computer Graphics


    Texture example l.jpg
    Texture Example join at the rasterizer

    • The texture (below) is a 256 x 256 image that has beenmapped to a rectangularpolygon which is viewed inperspective

    CIS 636/736: (Introduction to) Computer Graphics


    Applying textures 1 l.jpg
    Applying Textures [1] join at the rasterizer

    • Three steps

      • specify texture

        • read or generate image

        • assign to texture

      • assign texture coordinates to vertices

      • specify texture parameters

        • wrapping, filtering

    CIS 636/736: (Introduction to) Computer Graphics


    Applying textures 2 l.jpg
    Applying Textures [2] join at the rasterizer

    • specify textures in texture objects

    • set texture filter

    • set texture function

    • set texture wrap mode

    • set optional perspective correction hint

    • bind texture object

    • enable texturing

    • supply texture coordinates for vertex

      • coordinates can also be generated

    CIS 636/736: (Introduction to) Computer Graphics


    Texture objects 1 l.jpg
    Texture Objects [1] join at the rasterizer

    • Like display lists for texture images

      • one image per texture object

      • may be shared by several graphics contexts

    • Generate texture names

      glGenTextures(n,*texIds );

    CIS 636/736: (Introduction to) Computer Graphics


    Texture objects 2 l.jpg
    Texture Objects [2] join at the rasterizer

    • Create texture objects with texture data and state

      glBindTexture( target, id );

    • Bind textures before using

      glBindTexture( target, id );

    CIS 636/736: (Introduction to) Computer Graphics


    Specify texture image l.jpg

    Per join at the rasterizer

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Specify Texture Image

    • Define a texture image from array of texels in CPU memory

      glTexImage2D( target, level, components, w, h, border, format, type, *texels );

      • dimensions of image must be powers of 2

    • Texel colors are processed by pixel pipeline

      • pixel scales, biases and lookups can bedone

    CIS 636/736: (Introduction to) Computer Graphics


    Converting texture images l.jpg
    Converting Texture Images join at the rasterizer

    • If dimensions of image are not power of 2

      gluScaleImage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out );

      • *_in is for source image

      • *_out is for destination image

    • Image interpolated and filtered during scaling

    CIS 636/736: (Introduction to) Computer Graphics


    Specifying textures other methods l.jpg
    Specifying Textures: join at the rasterizerOther Methods

    • Use frame buffer as source of texture image

      • uses current buffer assource image

        glCopyTexImage2D(...)

        glCopyTexImage1D(...)

    • Modify part of a defined texture

      glTexSubImage2D(...)

      glTexSubImage1D(...)

    • Do both with glCopyTexSubImage2D(...), etc.

    CIS 636/736: (Introduction to) Computer Graphics


    Mapping a texture l.jpg

    Per join at the rasterizer

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Texture Space

    Object Space

    t

    1, 1

    (s, t) = (0.2, 0.8)

    A

    a

    c

    (0.4, 0.2)

    b

    B

    C

    (0.8, 0.4)

    s

    0, 0

    1, 0

    Mapping aTexture

    • Based on parametric texture coordinates

    • glTexCoord*() specified at each vertex

    0, 1

    CIS 636/736: (Introduction to) Computer Graphics


    Generating texture coordinates l.jpg
    Generating Texture Coordinates join at the rasterizer

    • Automatically generate texture coords

      glTexGen{ifd}[v]()

    • specify a plane

      • generate texture coordinates based upon distance from plane

    • generation modes

      • GL_OBJECT_LINEAR

      • GL_EYE_LINEAR

      • GL_SPHERE_MAP

    CIS 636/736: (Introduction to) Computer Graphics


    Tutorial texture l.jpg
    Tutorial: Texture join at the rasterizer

    CIS 636/736: (Introduction to) Computer Graphics


    Texture application methods l.jpg
    Texture Application Methods join at the rasterizer

    • Filter Modes

      • minification or magnification

      • special mipmap minification filters

    • Wrap Modes

      • clamping or repeating

    • Texture Functions

      • how to mix primitive’s color with texture’s color

        • blend, modulate or replace texels

    CIS 636/736: (Introduction to) Computer Graphics


    Filter modes l.jpg
    Filter Modes join at the rasterizer

    Example:

    glTexParameteri( target, type, mode );

    Texture

    Polygon

    Texture

    Polygon

    Magnification

    Minification

    CIS 636/736: (Introduction to) Computer Graphics


    Mipmapped textures l.jpg
    Mipmapped Textures join at the rasterizer

    • Mipmap allows for prefiltered texture maps of decreasing resolutions

    • Lessens interpolation errors for smaller textured objects

    • Declare mipmap level during texture definition

      glTexImage*D( GL_TEXTURE_*D, level, … )

    • GLU mipmap builder routines

      gluBuild*DMipmaps( … )

    • OpenGL 1.2 introduces advanced LOD controls

    CIS 636/736: (Introduction to) Computer Graphics


    Wrapping mode l.jpg
    Wrapping Mode join at the rasterizer

    • Example:

      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP )

      glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT )

    t

    s

    GL_REPEAT

    wrapping

    GL_CLAMP

    wrapping

    texture

    CIS 636/736: (Introduction to) Computer Graphics


    Texture functions l.jpg
    Texture Functions join at the rasterizer

    • Controls how texture is applied

      glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param )

    • GL_TEXTURE_ENV_MODE modes

      • GL_MODULATE

      • GL_BLEND

      • GL_REPLACE

    • Set blend color with GL_TEXTURE_ENV_COLOR

    CIS 636/736: (Introduction to) Computer Graphics


    Perspective correction hint l.jpg
    Perspective Correction Hint join at the rasterizer

    • Texture coordinate and color interpolation

      • either linearly in screen space

      • or using depth/perspective values (slower)

    • Noticeable for polygons “on edge”

      glHint( GL_PERSPECTIVE_CORRECTION_HINT, hint )

      where hint is one of

      • GL_DONT_CARE

      • GL_NICEST

      • GL_FASTEST

    CIS 636/736: (Introduction to) Computer Graphics


    Is there room for a texture l.jpg
    Is There Room for a Texture? join at the rasterizer

    • Query largest dimension of texture image

      • typically largest square texture

      • doesn’t consider internal format size

        glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size )

    • Texture proxy

      • will memory accommodate requested texture size?

      • no image specified; placeholder

      • if texture won’t fit, texture state variables set to 0

        • doesn’t know about other textures

        • only considers whether this one texture will fit all of memory

    CIS 636/736: (Introduction to) Computer Graphics


    Texture residency l.jpg
    Texture Residency join at the rasterizer

    • Working set of textures

      • high-performance, usually hardware accelerated

      • textures must be in texture objects

      • a texture in the working set is resident

      • for residency of current texture, check GL_TEXTURE_RESIDENT state

    • If too many textures, not all are resident

      • can set priority to have some kicked out first

      • establish 0.0 to 1.0 priorities for texture objects

    CIS 636/736: (Introduction to) Computer Graphics


    Advanced opengl topics l.jpg

    Advanced OpenGL Topics join at the rasterizer

    Dave Shreiner

    CIS 636/736: (Introduction to) Computer Graphics


    Advanced opengl topics63 l.jpg
    Advanced OpenGL Topics join at the rasterizer

    • Display Lists and Vertex Arrays

    • Alpha Blending and Antialiasing

    • Using the Accumulation Buffer

    • Fog

    • Feedback & Selection

    • Fragment Tests and Operations

    • Using the Stencil Buffer

    CIS 636/736: (Introduction to) Computer Graphics


    Rendering immediate mode versus display listed 1 l.jpg
    Rendering: join at the rasterizer Immediate Mode versus Display Listed [1]

    • Immediate Mode Graphics

      • Primitives are sent to pipeline and display right away

      • No memory of graphical entities

    • Display Listed Graphics

      • Primitives placed in display lists

      • Display lists kept on graphics server

      • Can be redisplayed with different state

      • Can be shared among OpenGL graphics contexts

    CIS 636/736: (Introduction to) Computer Graphics


    Rendering immediate mode versus display listed 2 l.jpg
    Rendering: join at the rasterizer Immediate Mode versus Display Listed [2]

    Immediate Mode

    Per Vertex

    Operations &

    Primitive

    Assembly

    Polynomial

    Evaluator

    DisplayList

    Per Fragment

    Operations

    Frame

    Buffer

    CPU

    Rasterization

    Display Listed

    Texture

    Memory

    Pixel

    Operations

    CIS 636/736: (Introduction to) Computer Graphics


    Display lists 1 l.jpg

    Per join at the rasterizer

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Display Lists [1]

    • Creating a display list

      GLuint id;

      void init( void )

      {

      id = glGenLists( 1 );

      glNewList( id, GL_COMPILE );

      /* other OpenGL routines */

      glEndList();

      }

    • Call a created list

      void display( void )

      {

      glCallList( id );

      }

    CIS 636/736: (Introduction to) Computer Graphics


    Display lists 2 l.jpg
    Display Lists [2] join at the rasterizer

    • Not all OpenGL routines can be stored in display lists

    • State changes persist, even after a display list is finished

    • Display lists can call other display lists

    • Display lists are not editable, but you can fake it

      • make a list (A) which calls other lists (B, C, and D)

      • delete and replace B, C, and D, as needed

    CIS 636/736: (Introduction to) Computer Graphics


    Display lists and hierarchy l.jpg
    Display Lists and Hierarchy join at the rasterizer

    • Consider model of a car

      • Create display list for chassis

      • Create display list for wheel

        glNewList( CAR, GL_COMPILE );

        glCallList( CHASSIS );

        glTranslatef( … );

        glCallList( WHEEL );

        glTranslatef( … );

        glCallList( WHEEL );

        glEndList();

    CIS 636/736: (Introduction to) Computer Graphics


    Vertex arrays l.jpg

    Per join at the rasterizer

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Color

    data

    Vertex

    data

    Vertex Arrays

    • Pass arrays of vertices, colors, etc. to OpenGL in large chunk

      glVertexPointer( 3, GL_FLOAT, 0, coords)

      glColorPointer( 4, GL_FLOAT, 0, colors)

      glEnableClientState( GL_VERTEX_ARRAY)

      glEnableClientState( GL_COLOR_ARRAY)

      glDrawArrays( GL_TRIANGLE_STRIP, 0, numVerts );

    • All active arrays are used in rendering

    CIS 636/736: (Introduction to) Computer Graphics


    Why use display lists or vertex arrays l.jpg
    Why use Display Lists join at the rasterizeror Vertex Arrays?

    • May provide better performance than immediate mode rendering

    • Display lists can be shared between multiple OpenGL context

      • reduce memory usage for multi-context applications

    • Vertex arrays may format data for better memory access

    CIS 636/736: (Introduction to) Computer Graphics


    Multi pass rendering l.jpg
    Multi-pass Rendering join at the rasterizer

    • Blending allows results from multiple drawing passes to be combined together

      • enables more complex rendering algorithms

    Example of bump-mapping

    done with multi-pass

    OpenGL algorithm

    CIS 636/736: (Introduction to) Computer Graphics


    Next time opengl part 3 of 3 accumulation buffer l.jpg
    Next Time (OpenGL Part 3 of 3): join at the rasterizerAccumulation Buffer

    • Problems of compositing into color buffers

      • Limited color resolution

        • clamping

        • loss of accuracy

      • Accumulation buffer acts as “floating point” color buffer

        • accumulate into accumulation buffer

        • transfer results to frame buffer

    CIS 636/736: (Introduction to) Computer Graphics


    Next time opengl part 3 of 3 fog l.jpg
    Next Time (OpenGL Part 3 of 3): join at the rasterizerFog

    CIS 636/736: (Introduction to) Computer Graphics


    Getting to framebuffer l.jpg

    Scissor join at the rasterizer

    Test

    Alpha

    Test

    Stencil

    Test

    Fragment

    Depth

    Test

    LogicalOperations

    Blending

    Dithering

    Framebuffer

    Getting to Framebuffer

    CIS 636/736: (Introduction to) Computer Graphics


    Next time opengl part 3 of 3 stencil buffer l.jpg

    Per join at the rasterizer

    Vertex

    Poly.

    Frag

    FB

    Raster

    CPU

    DL

    Texture

    Pixel

    Next Time (OpenGL Part 3 of 3):Stencil Buffer

    • Used to control drawing based on values in the stencil buffer

      • Fragments that fail the stencil test are not drawn

      • Example: create a mask in stencil buffer and draw only objects not in mask area

    CIS 636/736: (Introduction to) Computer Graphics


    Next time opengl part 3 of 3 advanced imaging l.jpg
    Next Time (OpenGL Part 3 of 3): join at the rasterizerAdvanced Imaging

    • Imaging Subset

      • Only available if GL_ARB_imagingdefined

        • Color matrix

        • Convolutions

        • Color tables

        • Histogram

        • MinMax

        • Advanced Blending

    CIS 636/736: (Introduction to) Computer Graphics


    On line resources l.jpg
    On-Line Resources join at the rasterizer

    • http://www.opengl.org

      • start here; up to date specification and lots of sample code

    • news:comp.graphics.api.opengl

    • http://www.sgi.com/software/opengl

    • http://www.mesa3d.org/

      • Brian Paul’s Mesa 3D

    • http://www.cs.utah.edu/~narobins/opengl.html

      • very special thanks to Nate Robins for the OpenGL Tutors

      • source code for tutors available here!

    • http://nehe.gamedev.net

    CIS 636/736: (Introduction to) Computer Graphics


    Books l.jpg
    Books join at the rasterizer

    • OpenGL Programming Guide, 5th – 6th Edition

    • OpenGL Shading Language, 2nd Edition

    • OpenGL Programming for the X Window System

      • includes many GLUT examples

    • Interactive Computer Graphics: A top-down approach with OpenGL, 4th – 5th Edition

    CIS 636/736: (Introduction to) Computer Graphics


    Slide79 l.jpg

    Summary join at the rasterizer

    • Four More Short OpenGL Tutorials from SIGGRAPH 2000

    • Vicki Shreiner: Animation and Depth Buffering

      • Double buffering

      • Illumination: light positioning, light models, attenuation

      • Material properties

      • Animation basics in OpenGL

    • Vicki Schreiner: Imaging and Raster Primitives

    • Ed Angel: Texture Mapping in OpenGL

    • Dave Shreiner: Advanced Topics

      • Display lists and vertex arrays

      • Fog

      • Stencil buffering, fragment programs (to be continued)

    CIS 636/736: (Introduction to) Computer Graphics


    Slide80 l.jpg

    Terminology join at the rasterizer

    • Double Buffering

    • Lighting

    • Illumination Equation – describes light in scene

      • Ambient light – catch-all term for whole scene, all lights

      • Diffuse reflectance – omnidirectional, from matte surfaces

      • Specular reflectance – unidirectional, for highlights: shiny surfaces

      • Attenuation – how quickly light drops off as function of distance

    • Pixel and Fragment Programs (“Pixel Shaders”)

    • Vertex Shaders

    • Texture Maps

    • Other Mappings Discussed in Course

      • Bumpakadisplacement – perturb surface normal, calculate lighting

      • Reflection and transparency

      • Shadow

      • Environment

    CIS 636/736: (Introduction to) Computer Graphics


    Slide81 l.jpg

    Next: Polygons, OpenGL Tutorial 3 join at the rasterizer

    • Dave Shreiner: Advanced Topics (concluded)

      • Advanced Primitives: Cubic Curves, Bicubic Surfaces

      • More on Shadow Stencil Buffer

      • Alpha, Blending, Antialiasing

      • Accumulation Buffer, Fog, Jitter

    • Using the OpenGL Shading Language

      • More on fragment programs

      • Demo: color interpolation

      • Example: Fast Phong shading

    • Special Effects

    CIS 636/736: (Introduction to) Computer Graphics


    ad