CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL...

20
CSC 461: Lecture 4 CSC 461: Lecture 4 1 CSC461: Lecture 4 Introduction to OpenGL Objectives: Objectives: Development of the OpenGL API Development of the OpenGL API OpenGL Architecture -- OpenGL OpenGL Architecture -- OpenGL as a state machine as a state machine Functions – Types and Formats Functions – Types and Formats Compilation Compilation

Transcript of CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL...

Page 1: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 11

CSC461: Lecture 4Introduction to OpenGL

Objectives:Objectives:

Development of the OpenGL APIDevelopment of the OpenGL API

OpenGL Architecture -- OpenGL as a OpenGL Architecture -- OpenGL as a state machinestate machine

Functions – Types and FormatsFunctions – Types and Formats

CompilationCompilation

Page 2: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 22

Early History of APIsEarly History of APIsIFIPS (1973) formed two committees to IFIPS (1973) formed two committees to come up with a standard graphics APIcome up with a standard graphics API–Graphical Kernel System (GKS)Graphical Kernel System (GKS)

2D but contained good workstation model2D but contained good workstation model

–Core Core Both 2D and 3DBoth 2D and 3D

–GKS adopted as IS0 and later ANSI standard GKS adopted as IS0 and later ANSI standard (1980s)(1980s)

GKS not easily extended to 3D (GKS-3D)GKS not easily extended to 3D (GKS-3D)Far behind hardware developmentFar behind hardware development

Page 3: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 33

PHIGS and XPHIGS and XPProgrammers rogrammers HiHierarchical erarchical GGraphics raphics SSystem (PHIGS)ystem (PHIGS)–Arose from CAD communityArose from CAD community–Database model with retained graphics Database model with retained graphics (structures)(structures)

X Window SystemX Window System–DEC/MIT effortDEC/MIT effort–Client-server architecture with graphicsClient-server architecture with graphics

PEX combined the twoPEX combined the two–Not easy to use (all the defects of each)Not easy to use (all the defects of each)

Page 4: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 44

SGI and GLSGI and GL

Silicon Graphics (SGI) revolutionized Silicon Graphics (SGI) revolutionized the graphics workstation by the graphics workstation by implementing the pipeline in implementing the pipeline in hardware (1982)hardware (1982)

To use the system, application To use the system, application programmers used a library called GLprogrammers used a library called GL

With GL, it was relatively simple to With GL, it was relatively simple to program three dimensional program three dimensional interactive applications interactive applications

Page 5: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 55

OpenGLOpenGLThe success of GL lead to The success of GL lead to OpenGL (1992), a platform-OpenGL (1992), a platform-independent API that was independent API that was –Easy to useEasy to use–Close enough to the hardware to get Close enough to the hardware to get excellent performanceexcellent performance

–Focus on renderingFocus on rendering–Omitted windowing and input to Omitted windowing and input to avoid window system dependencies avoid window system dependencies

Page 6: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 66

OpenGL EvolutionOpenGL Evolution

Controlled by an Architectural Review Controlled by an Architectural Review Board (ARB)Board (ARB)–Members include SGI, Microsoft, Nvidia, Members include SGI, Microsoft, Nvidia, HP, 3DLabs,IBM,…….HP, 3DLabs,IBM,…….

–Relatively stable (present version 1.4)Relatively stable (present version 1.4)Evolution reflects new hardware capabilitiesEvolution reflects new hardware capabilities

– 3D texture mapping and texture objects3D texture mapping and texture objects– Vertex programsVertex programs

–Allows for platform specific features Allows for platform specific features through extensionsthrough extensions

Page 7: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 77

OpenGL LibrariesOpenGL Libraries

OpenGL core libraryOpenGL core library–OpenGL32 on WindowsOpenGL32 on Windows–GL on most unix/linux systemsGL on most unix/linux systems

OpenGL Utility Library (GLU)OpenGL Utility Library (GLU)–Provides functionality in OpenGL core but Provides functionality in OpenGL core but avoids having to rewrite codeavoids having to rewrite code

Links with window systemLinks with window system–GLX for X window systemsGLX for X window systems–WGL for WidowsWGL for Widows–AGL for MacintoshAGL for Macintosh

Page 8: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 88

GLUTGLUT

OpenGL Utility Toolkit (GLUT)OpenGL Utility Toolkit (GLUT)–Provides functionality common to all Provides functionality common to all window systemswindow systems

Open a windowOpen a window

Get input from mouse and keyboardGet input from mouse and keyboard

MenusMenus

Event-drivenEvent-driven

–Code is portable but GLUT lacks the Code is portable but GLUT lacks the functionality of a good toolkit for a functionality of a good toolkit for a specific platformspecific platform

Slide barsSlide bars

Page 9: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 99

Software OrganizationSoftware Organization

GLUT

GLU

GL

GLX, AGLor WGL

X, Win32, Mac O/S

software and/or hardware

application program

OpenGL Motifwidget or similar

Page 10: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1010

OpenGL ArchitectureOpenGL ArchitectureImmediate Mode

DisplayList

PolynomialEvaluator

Per VertexOperations &

PrimitiveAssembly

RasterizationPer Fragment

Operations

TextureMemory

CPU

PixelOperations

FrameBuffer

Geometric pipeline

Page 11: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1111

Programmer’s View Programmer’s View

Three componentsThree components– Specify a set of objects to renderSpecify a set of objects to render– Describe properties of these objectsDescribe properties of these objects– Define how these objects should be Define how these objects should be

viewedviewed

Page 12: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1212

OpenGL FunctionsOpenGL FunctionsPrimitivesPrimitives– PointsPoints– Line SegmentsLine Segments– PolygonsPolygons

AttributesAttributes

TransformationsTransformations– ViewingViewing– Modeling -- WindowingModeling -- Windowing

ControlControl

Input (GLUT)Input (GLUT)

Page 13: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1313

OpenGL StateOpenGL StateOpenGL is a state machineOpenGL is a state machine

Application Program OpenGL Display

Function calls Pixels

OpenGL PipelineOpenGL Pipelineapplication program display

Page 14: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1414

OpenGL Function TypesOpenGL Function Types

OpenGL functions are of two typesOpenGL functions are of two types– Primitive generatingPrimitive generating

Can cause output if primitive is visibleCan cause output if primitive is visible

How vertices are processes and appearance How vertices are processes and appearance of primitive are controlled by the stateof primitive are controlled by the state

– State changingState changingTransformation functionsTransformation functions

Attribute functions Attribute functions – Colors, viewing conditions, material properties, Colors, viewing conditions, material properties,

lighting, shading, etc.lighting, shading, etc.

Page 15: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1515

Lack of Object OrientationLack of Object Orientation

OpenGL is not object oriented so that OpenGL is not object oriented so that there are multiple functions for a there are multiple functions for a given logical function, e.g.given logical function, e.g.– glVertex3fglVertex3f, , – glVertex2iglVertex2i,,– glVertex3dvglVertex3dv,…..,…..

Underlying storage mode is the sameUnderlying storage mode is the same

Easy to create overloaded functions Easy to create overloaded functions in C++ but issue is efficiencyin C++ but issue is efficiency

Page 16: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1616

OpenGL function formatOpenGL 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

Page 17: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1717

OpenGL #definesOpenGL #defines

Most constants are defined in the Most constants are defined in the include files include files gl.hgl.h, , glu.hglu.h and and glut.hglut.h–Note Note #include <glut.h>#include <glut.h> should should automatically include the othersautomatically include the others

–ExamplesExamples

glBegin(GL_PLOYGON)glBegin(GL_PLOYGON)

glClear(GL_COLOR_BUFFER_BIT)glClear(GL_COLOR_BUFFER_BIT)

include files also define OpenGL data include files also define OpenGL data types: types: GlfloatGlfloat, , GldoubleGldouble,….,….

Page 18: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1818

Notes on compilationNotes on compilationUnix/linuxUnix/linux–Include files usually in …/include/GLInclude files usually in …/include/GL–Compile with –lglut –lglu –lgl loader flagsCompile with –lglut –lglu –lgl loader flags–May have to add –L flag for X librariesMay have to add –L flag for X libraries–Mesa implementation included with most Mesa implementation included with most linux distributionslinux distributions

–Check web for latest versions of Mesa and Check web for latest versions of Mesa and glutglut

See website and ftp for your computerSee website and ftp for your computer

Page 19: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 1919

CompilerCompiler

ExampleExample– UnixUnix

cc myapp.c –o myapp –lglut –lglu –lgl –lX11 -lmcc myapp.c –o myapp –lglut –lglu –lgl –lX11 -lm

– LinuxLinuxcc myapp.c –o myapp –lglut –lglu –lgl –l/usr/X11R6/lib -lmcc myapp.c –o myapp –lglut –lglu –lgl –l/usr/X11R6/lib -lm

Page 20: CSC 461: Lecture 41 CSC461: Lecture 4 Introduction to OpenGL Objectives: Development of the OpenGL API OpenGL Architecture -- OpenGL as a state machine.

CSC 461: Lecture 4CSC 461: Lecture 4 2020

Compilation on WindowsCompilation on WindowsVisual C++Visual C++– Get glut.h, glut32.lib and glut32.dll from web in Get glut.h, glut32.lib and glut32.dll from web in

the system folderthe system folder– Create a console applicationCreate a console application– Add opengl32.lib, glut32.lib to project settings Add opengl32.lib, glut32.lib to project settings

(under link tab)(under link tab)– Lib files should be Lib files should be ..\VC\lib..\VC\lib– Include files should be Include files should be ..\VC\include\GL..\VC\include\GL

Borland C similarBorland C similar

Cygwin (linux under Windows)Cygwin (linux under Windows)– Can use gcc and similar makefile to linuxCan use gcc and similar makefile to linux– Use –lopengl32 –lglu32 –lglut32 flagsUse –lopengl32 –lglu32 –lglut32 flags