Raster Images

     

A digital image is a 2 dimensional array of pixel colors

Pixel = "picture element"

Each pixel is a sample of a continuous, analog image






Pixels



Pointillism can be considered to take a similar approach -
breaking an image down into discrete samples






Visual Acuity

Resolution of the eye - approximately 0.5 arc-minute, at the center of vision

fovea: 1 - 2 degree area at center of retina with maximum density of cones

1280x1024, 17" monitor viewed from 2 feet : 1 pixel = ~ 1.4 arc-minutes




Image Data

Basic digital image data is a stream of numbers, representing pixel colors


1 239 120 1 1 37 94 8 92 31 80 92 134 89 2 3 50 9 3 10 93 109 134  ...

Important additional information is:


Total memory needed for a simple image:

    width * height * components * bytes_per_component

e.g. a 1024x768, RGB, 8-bit image requires 2.25 megabytes






Frame Buffer

The frame buffer is a chunk of graphics card memory that contains what is displayed on the screen.

Like an image, but for each pixel there can be additional data besides color - depth, masking, etc.

OpenGL renders shapes, images, etc. into pixels of the frame buffer.
rasterizing it - converting it into raster form in the frame buffer.










Coordinate Systems






Coordinate Systems

A coordinate system is needed for measuring objects' positions

It allows us to describe any location by a set of numbers - 2 numbers when working in 2 dimensions, 3 numbers for 3 dimensions.

A coordinate system has an origin (a reference point) and coordinate axes

In 2D we have an X axis and a Y axis. In 3D, we add a Z axis.

The axes are perpendicular - they are independent






Coordinate Systems






Coordinate Systems

Some coordinate systems used:






gluOrtho2D

For older, fixed-function pipeline

The default drawing coordinate system can be changed with the function gluOrtho2D

e.g.:

    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(0.0, 10.0, 0.0, 5.0)
    glMatrixMode(GL_MODELVIEW)





gluOrtho2D

gluOrtho2D is typically used either in the drawing function, or in GLUT's reshape callback.

The reshape callback is called whenever the window changes size.

e.g., to make the window always span -10 to +10 in X, while keeping the aspect ratio 1:1, the coordinate range in Y will depend on the window size:

def reshape(w, h):
    glViewport(0, 0, w, h)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluOrtho2D(-10.0, 10.0, -10.0*h/w, 10.0*h/w)
    glMatrixMode(GL_MODELVIEW)

glutReshapeFunc(reshape)









Geometry






OpenGL Geometry

OpenGL includes functions to draw points, lines, and triangles.

All other shapes are made up of these elements.

A basic shape is entirely described by its vertices, which are connected by straight edges.

The graphics hardware fills in all the necessary pixels.






OpenGL Geometry

For older, fixed-function pipeline

The basic method for drawing a shape is:

glBegin(...)
glVertex(...)
glVertex(...)
glVertex(...)
...

glEnd()

Always be sure to have a matching glEnd() for each glBegin()






OpenGL Geometry

GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP
   
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN





OpenGL Geometry

    glColor3f(1, 0.5, 0)
    glBegin(GL_TRIANGLES)
    glVertex2f(0, 0)
    glVertex2f(1, 0)
    glVertex2f(0.5, 0.5)
    glEnd()





Animation








Animation

Illusion of motion produced by rapidly displaying still frames that change

Animation frame rate can be independent of video display frequency

Traditional animation often works at 12 frames per second.
But faster rates will yield smoother motion.

Below ~ 10 fps, animation looks like a slide show, rather than motion




Double Buffering

Double-buffering hides the image being drawn until it is finished.

The previously completed image is displayed while the new one is drawn.

The frame buffer is split into two buffers - front buffer (displayed) and back buffer (drawn into).

Useful for smooth animation.




Double Buffering






Double Buffering

Pyglet enables and uses double-buffering by default.

The important steps are

  1. open a double-buffered window (double_buffer=true in the configuration)
  2. flip buffers after drawing is complete (window.flip())



Creative Commons License
This document is by Dave Pape, and is released under a Creative Commons License.