Presentation is loading. Please wait.

Presentation is loading. Please wait.

“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.

Similar presentations


Presentation on theme: "“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra."— Presentation transcript:

1 “Computer Science is no more about computers than astronomy is about telescopes.”
Professor Edsger Dijkstra

2 OpenGL Notes & Guides

3 Required files for Windows
In the System Directory glu32.dll opengl32.dll glut32.dll In the C++ Include Directory gl\gl.h l\glu.h gl\glaux.h (probably won't need it) gl\glut.h (includes both gl.h and glu.h) In the C++ Library Directory gl\glu32.lib l\opengl32.lib gl\glaux.lib (probably won't need it) gl\glut32.lib

4 OpenGL Libraries OpenGL Application GLU GL GLUT GLX Frame Buffer
Display

5 Event Loop OpenGL programs often run in an event loop:
Start the program Run some initialization code Run an infinite loop and wait for events such as Key press Mouse move, click Reshape window Expose event

6 OpenGL Command Syntax (1)
OpenGL commands start with “gl” OpenGL constants start with “GL_” Some commands end in a number and one, two or three letters at the end (indicating number and type of arguments) A Number indicates number of arguments Characters indicate type of argument

7 OpenGL Command Syntax (2)
`f' float `d' double float `s' signed short integer `i' signed integer `b' character `ub' unsigned character `us' unsigned short integer `ui' unsigned integer

8 OpenGL Command Syntax (3)
“v” at the end of the name indicates a vector format. Examples: glColor*() glColor3b, glColor3d, glColor3f, glColor3i, glColor3s, glColor3ub, glColor3ui, glColor3us, glColor4b, glColor4d, glColor4f, glColor4i, glColor4s, glColor4ub, glColor4ui, glColor4us, glColor3bv, glColor3dv, glColor3fv, glColor3iv, glColor3sv, glColor3ubv, glColor3uiv, glColor3usv, glColor4bv, glColor4dv, glColor4fv, glColor4iv, glColor4sv, glColor4ubv, glColor4uiv, glColor4usv

9 OpenGL Primitives GL_POINTS GL_LINES GL_LINE_STRIP GL_LINE_LOOP
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN GL_QUADS GL_QUAD_STRIP GL_POLYGON

10 Scene Graph Ground T1 Body T4 T2 T3 Head Left Arm Right Arm

11 OpenGL Program Organization
main: find GL visual and create window initialize GL states (e.g. viewing, color, lighting) initialize display lists loop check for events (and process them) if window event (window moved, exposed, etc.) modify viewport, if needed redraw else if mouse or keyboard do something, e.g., change states and redraw redraw: clear screen (to background color) change state(s), if needed render some graphics change more states render some more graphics . swap buffers

12 glMatrixMode glMatrixMode C Specification Parameters Description
- specify which matrix is the current matrix C Specification void glMatrixMode( GLenum mode ) Parameters mode Specifies which matrix stack is the target for subsequent matrix operations. Three values are accepted: GL_MODELVIEW, GL_PROJECTION, and GL_TEXTURE. The default value is GL_MODELVIEW. Description glMatrixMode sets the current matrix mode. mode can assume one of three values: GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix stack. GL_PROJECTION Applies subsequent matrix operations to the projection matrix stack.

13 Viewing Pipeline

14 General 3D Viewing Pipeline
Modeling coordinates (MC) World coordinates (WC) Viewing coordinates (VC) Projection coordinates (PC) Normalized coordinates (NC) Device coordinates (DC)

15 Virtual Camera Model Viewing Transformation Projection Transformation
The camera position and orientation is determined Projection Transformation The selected view of a 3D scene is projected onto a view plane

16 Viewing-Coordinate Parameters
Look-at point Pref View-up vector V N and V are specified in the world coordinates

17 Viewing-Coordinate Reference Frame
The camera orientation is determined by the uvn reference frame u v n

18 World-to-Viewing Transformation

19 Perspective-Projection View Volume
Viewing frustum Why do we need near and far clipping plane ?

20 Normalizing Transformation
Transform an arbitrary perspective-projection view volume into the canonical view volume Step 1: from frustum to parallelepiped

21 Normalizing Transformation
Transform an arbitrary perspective-projection view volume into the canonical view volume Step 2: from parallelepiped to normalized

22 Orthographic Transformation
Preserves relative dimension The center of projection at infinity The direction of projection is parallel to a principle axis Architectural and engineering drawings

23 OpenGL 3D Viewing Functions
Viewing-transformation function glMatrixMode(GL_MODELVIEW); gluLookAt(x0,y0,z0,xref,yref,zref,vx,vy,vz); Default: gluLookAt(0,0,0, 0,0,-1, 0,1,0); OpenGL orthogonal-projection function glMatrixMode(GL_PROJECTION); gluOrtho(xwmin,xwmax, ywmin,ywmax, dnear,dfar); Default: gluOrtho(-1,1, -1,1, -1,1); Note that dnear and dfar must be assigned positive values znear=-dnear and zfar=-dfar The near clipping plane is the view plane

24 glViewport C Specification Parameters
void glViewport(GLint x, GLint y, GLsizei width, GLsizei height) Parameters x, y: Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0, 0). width, height: Specify the width and height of the viewport. When a GL context is first attached to a surface (e.g. window), width and height are set to the dimensions of that surface. glViewport specifies the affine transformation of x and y from normalized device coordinates to window coordinates. Let (xnd, ynd) be normalized device coordinates. Then the window coordinates (xw, yw) are computed as follows:

25 OpenGL 3D Viewing Functions
OpenGL perspective-projection function The projection reference point is the viewing-coordinate origin The near clipping plane is the view plane Symmetric: gluPerspective(theta,aspect,dnear,dfar) General: glFrustum(xwmin,xwmax,ywmin,ywmax,dnear,dfar)


Download ppt "“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra."

Similar presentations


Ads by Google