Académique Documents
Professionnel Documents
Culture Documents
1
Interactive computer graphics: APIs Interactive Computer Graphics: OpenGL
OpenGL can be used from The most common graphics device is the raster
C, C++ display where the programmer plots points or pixels.
Ada, Fortran
Java A typical (API) command might be:
OpenGL supports
polygon rendering SetPixel(x,y,colour)
texture mapping and anti-aliasing
OpenGL doesn’t support
Where x and y are pixel coordinates.
ray tracing
volume rendering
2
Pixel Addressing Different pixel addressing conventions
Some have the origin at the top left corner, some have 50
it at the bottom right hand corner.
50
x
y 100
Device Dependent Drawing Primitives Why aim for better device independence
Each operating system provides us with the 1. In normal applications we want our pictures to
possibility of drawing graphics at the pixel level. adjust their size if the window is changed.
For example in the Windows 32 API we have: 2. In graphics only applications we want our pictures
MoveToEx(hdc xpix, ypix); to be independent of resolution
LineTo(hdc, xpix, ypix);
TextOut(hdc, xpix, ypix, message, length); 3. We want to be able to move graphics applications
between different systems (PC, Workstation,
Where hdc is an identifier for the window, and xpix Supercomputer etc.)
and ypix are pixel coordinates
Graphics Lecture 1: Slide 15 Graphics Lecture 1: Slide 16
To achieve device independence we need to define a It is common, but not universal to define the world
world coordinate system. coordinates with the command:
This will define our drawing area in units that are SetWindow(left,bottom,right,top)
suited to the application:
meters We can think of this as a window onto the world
light years matching a window on the screen
microns
etc
3
World Coordinates Device independent Graphics Primitives
SetWindow(Left,Bottom,Right,Top)
Having defined our world coordinate system we can
top implement drawing primitives to use with it. For
example:
DrawLine(x1,y1,x2,y2);
Drawing Area DrawCircle(x1,y1,r);
DrawPolygon(PointArray);
DrawText(x1,y1,"A Message");
bottom Normally any part of a graphics object outside the
window is clipped.
left right
30 70
Attributes Normalisation
In device independent graphics primitives we usually We need to connect our device independent graphics
avoid having a comprehensive set of parameters. For primitives to the device dependent drawing
example, a line will have: commands so that we can see something on the
Style (solid or dotted) screen.
Thickness (points)
Colour
And text will have This is done by the process of normalisation.
Font
Size
Colour
These are called attributes
Graphics Lecture 1: Slide 23 Graphics Lecture 1: Slide 24
4
Normalisation Normalisation
[Xw,Yw]
First we must call the API to find out from the
operating system the pixel addresses of the corner of
the area we are using Wxmin Wxmax [Xd,Yd]
Dxmin Dxmax
Pixel Coords
Graphics Lecture 1: Slide 25 Graphics Lecture 1: Slide 26
Normalisation Normalisation
Having defined our world coordinates, and obtained A similar equation allows us to calculate the Y pixel
our device coordinates we relate the two by simple coordinate. The two can be combined into a simple
ratios: pair of linear equations:
Viewports
Normalised Device Coordinates
5
Normalisation with Viewports Input Devices
Using viewports simply changes our normalisation There are many input devices for computer graphics:
procedure. We now need to do the following:
Mouse
1. Call the operating system API to find out the pixel Joystick
addresses of the corners of the window Button Box
2. Use the viewport setting to calculate the pixel addresses Digitising Tablet
of the area where the drawing is to appear.
Light Pen
3. Compute the normalisation parameters A, B, C, D
etc.
The mouse is simply a device which supplies the A mouse event occurs when something changes, ie it
computer with three bytes of information (minimum) is moved or a button is pressed.
at a time, vis:
The mouse interrupts the operating system to tell it
Distance Moved in X direction (ticks) that an event has occurred and sends it the new data.
Distance Moved in Y direction (ticks)
Button Status
The operating system normally updates the position
of the marker on the screen.
The provision of a visible marker on the screen is
done by software.
Graphics Lecture 1: Slide 33 Graphics Lecture 1: Slide 34
6
Input Methods
Locator:
Identifies a point on the screen using a visible marker
Rubber Band:
Adjusts the size and position of a graphical object