Docsity

OpenGL: Understanding the Application Programmer Interface (API), Study notes of Computer Graphics

Partial preview of the text

Download OpenGL: Understanding the Application Programmer Interface (API) and more Study notes Computer Graphics in PDF only on Docsity!

Introduction to OpenGL

TA: Mani Thomas^ CISC 440/640^ [email protected]

Acknowledgements z^ Most of the material for the slides wereadapted from^ •^ E. Angel, “Interactive Computer Graphics”, 4

th^ edition

z^ Some of the slides were taken from^ •^ CISC 440/640 Computer Graphics (Spring 2005) z^ Some of the images were taken from^ •^ F.S.Hill, “Computer Graphics using OpenGL” z^ Other resources^ •^ http://www.lighthouse3d.com/opengl/glut/^ •^ Jackie Neider, Tom Davis, and Mason Woo, “TheOpenGL Programming Guide” (The Red Book)

API Contents z^ Functions that specify what we need to form animage^ •^ Objects^ •^ Viewer^ •^ Light Source(s)^ •^ Materials z^ Other information^ •^ Input from devices such as mouse and keyboard^ •^ Capabilities of system

History of OpenGL z^ Silicon Graphics (SGI) revolutionized thegraphics workstation by implementingthe pipeline in hardware (1982) z^ To access the system, applicationprogrammers used a library called GL z^ With GL, it was relatively simple toprogram three dimensional interactiveapplications

OpenGL Evolution z^ Controlled by an Architectural ReviewBoard (ARB)^ •^ Members include SGI, Microsoft, Nvidia, HP,3DLabs, IBM,…….^ •^ Relatively stable (present version 2.0)^ •^

Evolution reflects new hardware capabilities^ •^ 3D texture mapping and texture objects^ •^ Vertex programs • Allows for platform specific features throughextensions

OpenGL Libraries z^ GL^ ( G

raphics^

L ibrary): Library of 2-D, 3-D

drawing primitives and operations^ •^ API for 3-D hardware acceleration z GLU^ ( GL U

tilities): Miscellaneous functions dealing with camera set-up and higher-levelshape descriptions z GLUT^ (

GL U tility

T oolkit): Window-system independent toolkit with numerous utilityfunctions, mostly dealing with user interface

Lack of Object Orientation z^ OpenGL is not object oriented so thatthere are multiple functions for a givenlogical function^ • glVertex3f^ • glVertex2i^ • glVertex3dv z^ Underlying storage mode is the same z^ Easy to create overloaded functions inC++ but issue is efficiency

OpenGL function format

glVertex3f(x,y,z) belongs to GL library

function name

x,y,z^ are floats glVertex3fv(p)

p^ is a pointer to an array

dimensions

Event Loop z^ Note that the program defines a

display

callback

function named

mydisplay

-^ Every glut program must have a displaycallback •^ The display callback is executed wheneverOpenGL decides the display must berefreshed, for example when the window isopened •^ The^ main

function ends with the program entering an event loop

Default parameters z^ simple.c

is too simple z^ Makes heavy use of state variabledefault values for^ •^ Viewing^ •^ Colors^ •^ Window parameters

Coordinate Systems z^ The units in

glVertex

are determined by the application andare called^

object^ or^ problem coordinates z The viewing specifications arealso in object coordinates and it isthe size of the viewing volumethat determines what will appearin the image z Internally, OpenGL will convert to camera (eye) coordinates

and later to^ screen coordinates

Transformations in OpenGl z^ Modeling transformation^ •^ Refer to the transformation of models (i.e., thescenes, or objects) z^ Viewing transformation^ •^ Refer to the transformation on the camera z^ Projection transformation^ •^ Refer to the transformation from scene toimage

Model/View transformation

Courtesy: Neider, Davis and Woo, “The OpenGL Programming Guide”

Projection Transformation z^ Transformation of the 3D scene into the2D rendered image plane^ •^ Before applying projection transformations,need to set

glMatrixMode(

GL_PROJECTION

)

-^ Orthographic projection^ •^ glOrtho(left, right, bottom, top, near, far) •^ Perspective projection^ •^ glFrustum (left, right, bottom, top, near, far)