up to Schedule & Notes

Vertex Array Objects (VAOs)

A VAO stores:

Use a VAO to define, typically, a single object. Then draw the object by

	
	  enable VAO
	  glDrawBuffer( ... )
	  disable VAO
	
      

Enabling a particular VAO gives OpenGL all the information (buffers and attributes) that are needed for glDrawBuffer().

With a VAO, you don't have to redefine your object and attributes every time it is drawn.

See 00-intro/src/demo4.cpp in openGL.zip

Simplified Pipeline

The pipeline is the set of operations that are sequentially performed to convert vertices into pixels.

Vertices

A vertex is a collection of attributes, typically from a VBO and usually including position and colour.

Vertex Shader

A small GPU program that processes vertices.

Input: vertex attributes (e.g. position, colour, normal, ...) and global variables called "uniforms" (e.g. the viewing transform, light positions, global colours, ...)

Output: vertex attributes, possibly modified and gl_Position, the vertex position transformed to the "clipping coordinate system" (CCS).

Primitives

Primitives are groups of vertices that form basic objects, like points or lines or triangles or quads.

Clipping

Cuts a primitive to fit within the window boundaries.

Rasterization

Converts a single primitive into a set of fragments.

Fragments

Fragments are potential pixels which have a position on the screen, a depth, and other attributes.

Fragment Shader

A small GPU program that processes fragments.

Input: A fragment with depth, attributes, and an implicit (!) position.

Output: The colour and depth of the pixel at that position

See 00-intro/src/demo5.cpp in openGL.zip

Additional Vertex Attributes

A VBO can contains any number of attributes.

Attributes could be arranged in the vertex buffer in different ways. For example:

See 00-intro/src/demo6.cpp in openGL.zip for two different ways of providing position and colour attributes on vertices.

Mouse Interaction

When dragging an object with the mouse, be careful that any changes you make to the scene are undone if the mouse moves back to its initial position.

  1. On the mouse click, record the initial mouse position and the initial object position. Enable the mouse movement callback.
  2. On mouse movement, calculate the difference in mouse position now from the initial mouse position. Convert that difference to world coordinates. Apply that world coordinate difference to the initial object position to get the current object position.
  3. Upon the mouse release, disable the mouse movement callback.

Mouse/World Coordinate Conversion

Mouse coordinates are in [0,width] x [0,height], measured in pixels to the outside edges of the window.

The mouse y coordinates are reversed, with mouse y=0 at the top edge and mouse y=height at the bottom edge.

World coordinates (at least for now) are [-1,+1] x [-1,+1].

To map mouse coordinates, $(x_m,y_m)$, to world coordinates, $(x_w,y_w)$:

${\large x_m - 0 \over \large \textrm{width} - 0} = {\large x_w - (-1) \over \large (+1) - (-1)}$

$x_w = {\large 2 \; x_m \over \large \textrm{width}} - 1$

Similarly in $y$, but matching the corresponding endpoints of the $y$ axis, which is reversed:

${\large y_m - 0 \over \large \textrm{height} - 0} = {\large y_w - (+1) \over \large (-1) - (+1)}$

$y_w = {\large -2 \; y_m \over \large \textrm{height}} + 1$

See 00-intro/src/demo7.cpp in openGL.zip for mouse dragging and mouse-to-world coordinate transforms.

up to Schedule & Notes