Download presentation
Presentation is loading. Please wait.
1
Programming With OpenGL
A Technical Overview of The OpenGL Graphics API Programming With OpenGL Computer Graphics
2
Graphics API OpenGL(All Platform) DirectX(Windows) -DirectDraw
-DirectSound -DirectPlay -DirectInput -DirectSetup OpenGL(All Platform) DirectX(Windows)
3
Programming With OpenGL
An Introduction OpenGL, the standard software interface for graphics hardware, allows programmers to create interactive 2D and 3D graphics applications on a variety of systems. With OpenGL you can create high-quality color images. OpenGL makes it easy to build geometric models, change the viewing position, control the color and lighting of geometric primitives, and manipulate pixel and texture map images. This course will cover an immediately applicable subset of OpenGL, so that you can write a simple graphics program. Computer Graphics
4
OpenGL Advantages OpenGL is the most logical extension of
Programming With OpenGL OpenGL Advantages Standard & Portability - Open OpenGL is the most logical extension of brilliant API called GL Supported through a larger number of vendors 1992, SGI SGI, IBM, DEC, Intel, Microsoft, Vendor and hardware independent Better integration into the windowing system Win95, Win98, WinNT, Win2000,WinXP Computer Graphics
5
Objectives Understand the order of operations, and the major libraries
Programming With OpenGL Objectives Become familiar with the capabilities of OpenGL Understand the order of operations, and the major libraries Know how to use viewing, lighting, shading, and hidden surface removal functionality Know how to draw images with OpenGL and process event-driven input See how code is written and compiled Computer Graphics
6
Programming With OpenGL
What is OpenGL? A low-level graphics modeling and rendering library (includes more than 100 functions) State machine A layer of abstraction between graphics hardware and an application program Hardware, Window System and Operating System independent Computer Graphics
7
Where is in the Graphics System
Programming With OpenGL Where is in the Graphics System Developing & Application OpenInventor, SoftImage 3D OpenGL Window System X-Windows, MS Windows … Operating System UNIX, MS Windows, OS/2... Graphics Hardware SGI-XZ, SGI-Extreme, AGC-3D.. Computer Graphics
8
What OpenGL Can Do For You
Programming With OpenGL What OpenGL Can Do For You Wireframe Models, Viewing, Transformation Antialiasing Flat And Smooth Shading Shadows Texture Mapping Motion Blur Haze and Fog, Depth -Of -Field Effect Evaluator Function: 1D & 2D Bezier Curves, NURBS ... Computer Graphics
9
Graphics Functions Primitive functions Attribute functions
Programming With OpenGL Graphics Functions Primitive functions Attribute functions Viewing functions Transformation functions Input functions / control functions Computer Graphics
10
Overview of OpenGL Components
Programming With OpenGL Overview of OpenGL Components OpenGL Library - gl OpenGL Utilities - glu OpenGL Extension to X Windows - glx OpenGL Programming Guide Auxiliary Library - aux Windows Graphics Library - wgl Computer Graphics
11
OpenGL Library GL Powerful But Primitive Set Of Rendering Commands
Programming With OpenGL OpenGL Library GL Powerful But Primitive Set Of Rendering Commands All high level drawing is done in terms of these commands You can write your own toolkit based on these functions The GL Library Includes Functions supporting drawing primitives Lines, Points, Circles, Polygons, Characters, ... Clipping, Viewing, Projections, Transformation Shading, Lighting Direct colors 3D rendering functions such as Antialiasing, Multi buffering, Texture, ... Pixels manipulation (read, write, copy) Computer Graphics
12
OpenGL Utility Library GLU
Programming With OpenGL OpenGL Utility Library GLU Utility library is a set of commonly used graphics routines built on top of OpenGL Uses lower level OpenGL commands for Setting up matrixes for viewing and projection Performing polygon tessellation - concave polygons, polygons with holes, self- intersecting polygons, .. Rendering surfaces (spheres, cylinders, disks, ..) Mipmapping NURBS (Non-Uniform Rational B-Spline) curves Error handling This library is part of the OpenGL implementation Computer Graphics
13
OpenGL Auxiliary Library
Programming With OpenGL OpenGL Auxiliary Library This is a simple, platform-dependent library Makes programming examples simpler & more complete Managing windows Handling input events Drawing classic 3-D objects Managing a background process Running a program Do not use them in a production application Computer Graphics
14
OpenGL Command Syntax OpenGL commands use : OpenGL define constants
Programming With OpenGL OpenGL Command Syntax OpenGL commands use : the prefix gl initial capital letters for each word making up the command name OpenGL define constants begin with GL use all capital letters use underscore to separate words OpenGL uses command extensions for clarification whenever the same command exists to use different arguments Examples : glClearColor() GL_COLOR_BUFFER_BIT glColor3fv() Computer Graphics
15
OpenGL Command Syntax glVertex3fv
Programming With OpenGL OpenGL Command Syntax glVertex3fv v indicates vector format, if present data type: f float d double float s signed short integer i signed integer number of components (2, 3, or 4) Other data types in OpenGL commands - b character - ub unsigned character - us unsigned short integer - ui unsinged integer Computer Graphics
16
Programming With OpenGL
Drawing Geometry Vertices can define a variety of geometric objects, and different numbers of vertices are required depending on the object. We can group as many vertices as desired, using the functions glBegin() and glEnd() Types of primitives glBegin (GLenum primitiveType) Example: glBegin (GL_POLYGON); glVertex3f(-. 5f, -. 5f, -. 5f); glVertex3f(. 5f, -. 5f, -. 5f); glVertex3f(-. 5f, .5f, -. 5f); glVertex3f(. 5f, .5f, -. 5f); glEnd(); Computer Graphics
17
Programming With OpenGL
Primitive Types Computer Graphics
18
Attributes primitive is to be rendered graphics system
Programming With OpenGL Attributes An attribute is any property that determines how a geometric primitive is to be rendered The present values of attribute are part of the state of the graphics system Each geometric type has a set of attributes Computer Graphics
19
Attributes Vertex attributes: glPointSize() point size
Programming With OpenGL Attributes Vertex attributes: glPointSize() point size glColor*()/ glIndex*() current vertex color glNormal*() current vertex normal (lighting) glMaterial*() current material property (lighting) glTexCoord*() current texture coordinate glEdgeFlag*() edge status (surface primitives) RGB colors: glColor3f(1.0,0.0,0.0) glClearColor(1.0,1.0,1.0,1.0) Indexed color: glIndexi(element) Alpha channel - opacity or transparency Computer Graphics
20
Drawing Geometry Example: Drawing a green, flat triangle strip:
Programming With OpenGL Drawing Geometry Example: Drawing a green, flat triangle strip: glBegin (GL_ TRIANGLE_ STRIP); glColor3f( 0. f, 1. f, 0. f); glNormal3f( 0. f, 0. f, 1. f); glVertex3f(-. 5f, -. 5f, -. 5f); glVertex3f(. 5f, -. 5f, -. 5f); glVertex3f(-. 5f, .5f, -. 5f); glVertex3f(. 5f, .5f, -. 5f); glEnd(); glBegin - glEnd paradigm allows great flexibility in describing primitives. Any combination of color, normal, texture, material etc. information can be bound with any given vertex. Computer Graphics
21
OpenGL The Statemachine
Programming With OpenGL OpenGL The Statemachine OpenGL knows about various different states or modes These states remain in effect until you change them Examples of states variables are: the current color current viewing and transformation matrix line and polygon stippling patterns polygon drawing modes shading modes pixel packing conventions position and characteristics of light sources material properties Each state variable has a default value You can query the current variable value Computer Graphics
22
States glEnable (GLenum capability) glDisable (GLenum capability)
Programming With OpenGL States glEnable (GLenum capability) glDisable (GLenum capability) GLboolean glIsEnabled (GLenum cap) - turn on and off OpenGL states - capability can be one of (partial list): GL_ BLEND (alpha blending) GL_ DEPTH_ TEST (depth buffer) GL_ FOG GL_ LIGHTING GL_ LINE_ SMOOTH (line antialiasing) Computer Graphics
23
Structure of a Typical Program
Programming With OpenGL Structure of a Typical Program main: create window initialize GL states (e. g., viewing, color, lighting) initialize display lists 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 & redraw Computer Graphics
24
Initialization void auxInitWindow(Glbyte *titleString)
Programming With OpenGL Initialization void auxInitWindow(Glbyte *titleString) - Win32 API: CreateWindow(…) void auxInitDisplayMode(Glbitfield mask) Mask: AUX_RGBA or AUX_INDEX AUX_SINGLE or AUX_DOUBLE AUX_DEPTH AUX_STENCIL AUX_ACCUM void auxInitPosition(Glint x,Glint y, Glsizei width,Glsizei height) - Win32 API: MoveWindow(…) Computer Graphics
25
Control Functions (GLsizei,Glsizei)) void(*function)(AUX_EVENTREC*))
Programming With OpenGL Control Functions void auxMainLoop(void(*displayFunc)void)) -Windows message: WM_PAINT void auxReshapeFunc(void(*function) (GLsizei,Glsizei)) -Windows message: WM_SIZE void auxMouseFunc(Glint button,Glint mode, void(*function)(AUX_EVENTREC*)) - Windows Message: WM_MOUSEDOWN Computer Graphics
26
Redraw redraw: clear screen (to background color)
Programming With OpenGL Redraw redraw: clear screen (to background color) change state( s), if needed render some graphics change more states render some more graphics .... Computer Graphics
27
Homework: The Sierpinski Gasket
Programming With OpenGL Homework: The Sierpinski Gasket 1. Pick an initial point at random inside the triangle. 2. Select one of the three vertices at random. 3. Find the point halfway between the initial point and the randomly selected vertex. 4. Display this new point by putting some sort of marker, such as a small circle, at its location. 5. Replace the initial point with this new point. 6. Return to step 2. V2 P0 P1 P2 V1 V3 Computer Graphics
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.