introduction to opengl programming jian-liang lin 2002

26
Introduction to OpenGL Programming Jian-Liang Lin 2002

Upload: beverley-hill

Post on 03-Jan-2016

251 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Introduction to OpenGL Programming Jian-Liang Lin 2002

Introduction to OpenGL Programming

Jian-Liang Lin2002

Page 2: Introduction to OpenGL Programming Jian-Liang Lin 2002

What is OpenGL? -1

OpenGL is a cross-platform standard for 3D rendering. and software interface to graphics hardware. The OpenGL Architecture Review Board(ARB), and independent consortium formed in 1992, governs the OpenGL specification.OpenGL routines use the prefix gl.

Page 3: Introduction to OpenGL Programming Jian-Liang Lin 2002

What is OpenGL? -2

Designed as a hardware-independent interface and implemented on many different hardware platforms. No commands for performing windowing tasks or obtaining user input are included in OpenGL.You must work through whatever windowing system controls the particular hardware you're using.

Page 4: Introduction to OpenGL Programming Jian-Liang Lin 2002

What is OpenGL? -3

OpenGL doesn't provide high-level commands for describing models of three-dimensional objects. With OpenGL, you must build up your desired model from a small set of geometric primitives.– points, lines, triangles, and polygons

…etc.

Page 5: Introduction to OpenGL Programming Jian-Liang Lin 2002

The Advantages of OpenGL

Industry standardFastPortableEasy to useWell-documented

Page 6: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL rendering pipeline

Page 7: Introduction to OpenGL Programming Jian-Liang Lin 2002

Color Models

RGBA color– Red, Green, Blue, and Alpha channels– Up to 16M colors

Color-indexed– Small numbers of colors accessed by

indices from a color lookup table(palette)

– 8 bits = 256 colors

Page 8: Introduction to OpenGL Programming Jian-Liang Lin 2002

Basic Features

TransformationMaterials Lighting & Smooth ShadingTexture mappingDepth buffer test (Z-Buffer)Alpha blendingDouble buffering for animationPixel operations

Page 9: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL Buffering -1

OpenGL supports a variety of buffers for advanced rendering– Depended on driver implementation

Color buffers– Front-left, front-right, back-left, back-

right, and any number of auxiliary buffers

Depth buffer– Also known as Z-Buffer for HSR

Page 10: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL Buffering -2

Alpha buffer– Blending

Stencil buffer– To restrict drawing to certain portions

of the screen. (basic application)

Accumulation buffer– Full scene manipulation

Page 11: Introduction to OpenGL Programming Jian-Liang Lin 2002

API Hierarchy

Page 12: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL library -1

SGI’s OpenGL SDK– OpenGL.DLL & GLU.DLL– Open source implementation for

hardware vendor reference.– Best software rendering library.– Can be downloaded from SGI’s

website.

Page 13: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL library -2

Microsoft’s implementation– From Win95 OSR2, Microsoft Windows

ship with OpenGL32.DLL.– For old Win95 users, you still can

download OPENGL95.EXE via Microsoft website.

– Header files and import library files are already included in Win32 Platform SDK.

Page 14: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL library -3

Microsoft’s OpenGL32.DLL applies a hardware accelerated driver registered in Registry.

– HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\OpenGLDrivers

– You can search it by using REGEDIT.EXE

Page 15: Introduction to OpenGL Programming Jian-Liang Lin 2002

Mesa Graphics Library

A OpenGL clone library.You can use it as using OpenGL.Portable on many OS.You can download it in the following website– http://www.mesa3d.org/

Page 16: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL Utility Library

The OpenGL Utility Library(GLU) provides many of the modeling features, such as quadric surfaces and NURBS curves and surfaces. GLU is a standard part of every OpenGL implementationGLU routines use the prefix glu.– gluLookAt( … );– …

Page 17: Introduction to OpenGL Programming Jian-Liang Lin 2002

Windows system related helper library

For every window system, there is a library that extends the functionality of that window system to support OpenGL rendering. – X Window System -> GLX – Microsoft Windows -> WGL– IBM OS/2 -> PGL

Page 18: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL Utility Toolkit -1

The OpenGL Utility Toolkit (GLUT) is a window system-independent toolkit, written by Mark Kilgard, to hide the complexities of differing window system APIs. GLUT routines use the prefix glut.– glutPostRedisplay();– …

Page 19: Introduction to OpenGL Programming Jian-Liang Lin 2002

OpenGL Utility Toolkit -2

You can download this toolkit in the following website– http://reality.sgi.com/mjk_asd

/glut3/glut3.html

We focus on this toolkit.

Page 20: Introduction to OpenGL Programming Jian-Liang Lin 2002

Programming Environment -1

PC(X86)– OpenGL v1.1 software runtime is

included as part of operating system for Win 2000, Windows 98, Windows 95 (OSR2) and Windows NT

– Linux, FreeBSD, …other UNIX-like OS can use Mesa graphics library.

Page 21: Introduction to OpenGL Programming Jian-Liang Lin 2002

Programming Environment -2

SGI workstation– Personal IRIS, Indigo, Indy, Indigo2

O2, – Octane in CGGM Lab. – All with IRIS Operating System and X

Window System

Page 22: Introduction to OpenGL Programming Jian-Liang Lin 2002

Compilers – Microsoft Visual C++

Start a new workspace of Win32 Console application.Add OpenGL32.lib glu32.lib glut32.lib in Projects/Setting/Link/Library modules column for linking

Page 23: Introduction to OpenGL Programming Jian-Liang Lin 2002

Compilers – Unix-like OS

Library files needed– libGL.so, libGLU.so, libglut.a, libX11.a,

libX11.so …etc

Command line:– gcc [source files] –o [output file] –lglut

–lGLU –lGL –lX11 –lm– The ordering of the linking flags is not

changeable.– Suggest to write a Makefile.

Page 24: Introduction to OpenGL Programming Jian-Liang Lin 2002

Where is the reference?

OpenGL official site– http://www.opengl.org

You refer to OpenGL API documentation in MSDN Library.

Page 25: Introduction to OpenGL Programming Jian-Liang Lin 2002

How can you start?

Choose your platformGet your desire OpenGL related library.Start a GLUT simple program, build and test.Refine the code as you wish.Refer to some reference materials.Consult with TA Feel happy to see the result.

Page 26: Introduction to OpenGL Programming Jian-Liang Lin 2002

Any Question?

?