56
06/27/22 07:34 AM 1 CSE 307 COMPUTER GRAPHICS OVERVIEW OF GRAPHICS SYSTEMS GRAPHICS OUTPUT PRIMITIVES GEOMETRICAL TRANSFORMATIONS TWO DIMENSIONAL VIEWING THREE DIMENSIONAL VIEWING PARAMETRIC CURVES VISIBLE SURFACE DETECTION METHODS ILLUMINATION MODELS COMPUTER ANIMATION Narendra V G CSE MIT

6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS OVERVIEW OF GRAPHICS SYSTEMS GRAPHICS OUTPUT PRIMITIVES GEOMETRICAL TRANSFORMATIONS TWO DIMENSIONAL

Embed Size (px)

Citation preview

Page 1: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

04/18/23 08:31 PM 1

CSE 307 COMPUTER GRAPHICS

OVERVIEW OF GRAPHICS SYSTEMS

GRAPHICS OUTPUT PRIMITIVES

GEOMETRICAL TRANSFORMATIONS

TWO DIMENSIONAL VIEWING

THREE DIMENSIONAL VIEWING

PARAMETRIC CURVES

VISIBLE SURFACE DETECTION METHODS

ILLUMINATION MODELS

COMPUTER ANIMATION

Narendra V G CSE MIT

Page 2: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

04/18/23 08:31 PM 2

Text Book:1. Donald Hearn, Pauline Baker M., “Computer Graphics with OpenGL”, Pearson Education, 3rd Edition, (2010)References:1.Edward Angel, “Interactive Computer Graphics- A top down approach using OpenGL”, Pearson Education, 5th Edition.2.Foley J. D., VanDam A., Feiner S. K., Hughes J. F., “Computer Graphics, Principles and Practice” , Addision-Wesley, 2nd Edition.3.Malay Pakhira K., “Computer Graphics Multimedia and Animation”, PHI Learning, . 2nd Edition.4.Amarendra Sinha N., Arun Udai D., “Computer Graphics”, Tata McGraw Hill publishing.

5.Er. Rajiv Chopra “Computer Graphics”, S. Chand & Company Ltd. 2nd Edition.

Narendra V G CSE MIT

Page 3: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

04/18/23 08:31 PM 3

Computer Graphics Applications

Narendra V G CSE MIT

Page 4: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics is about animation (films)

Major driving force now

04/18/23 08:31 PM 4Narendra V G CSE MIT

Page 5: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Games are very important in Computer Graphics

04/18/23 08:31 PM 5Narendra V G CSE MIT

Page 6: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Medical Imaging is another driving force

Much financial support

Promotes linking of graphics with video, scans, etc.

04/18/23 08:31 PM 6Narendra V G CSE MIT

Page 7: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Aided Design too

04/18/23 08:31 PM 7Narendra V G CSE MIT

Page 8: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Scientific Visualisation

To view below and above our visual range

04/18/23 08:31 PM 8Narendra V G CSE MIT

Page 9: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Graphics Pipelines

• Graphics processes generally execute sequentially• Typical ‘pipeline’ model• There are two ‘graphics’ pipelines

– The Geometry or 3D pipeline– The Imaging or 2D pipeline

04/18/23 08:31 PM 9Narendra V G CSE MIT

Page 10: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

04/18/23 08:31 PM 10

Computer Graphics ?

Narendra V G CSE MIT

Page 11: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics

• Computer graphics deals with all aspects of creating images with a computer– Hardware– Software– Applications

1104/18/23 08:31 PM Narendra V G CSE MIT

Page 12: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Example

• Where did this image come from?

• What hardware/software did we need to produce it?

1204/18/23 08:31 PM Narendra V G CSE MIT

Page 13: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Preliminary Answer

• Application: The object is an artist’s rendition of the sun for an animation to be shown in a domed environment (planetarium)

• Software: Maya for modeling and rendering but Maya is built on top of OpenGL

• Hardware: PC with graphics card for modeling and rendering

1304/18/23 08:31 PM Narendra V G CSE MIT

Page 14: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Basic Graphics System

14

Input devices

Output device

Image formed in FB

04/18/23 08:31 PM Narendra V G CSE MIT

Page 15: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

CRT

Can be used either as a line-drawing device (calligraphic) or to display contents of frame buffer (raster mode)

1504/18/23 08:31 PM Narendra V G CSE MIT

Page 16: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1950-1960

• Computer graphics goes back to the earliest days of computing– Strip charts– Pen plotters– Simple displays using A/D converters to go from

computer to calligraphic CRT

• Cost of refresh for CRT too high – Computers slow, expensive, unreliable

1604/18/23 08:31 PM Narendra V G CSE MIT

Page 17: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1960-1970

• Wireframe graphics– Draw only lines

• Sketchpad• Display Processors• Storage tube

17

wireframe representationof sun object

04/18/23 08:31 PM Narendra V G CSE MIT

Page 18: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Sketchpad

• Ivan Sutherland’s PhD thesis at MIT– Recognized the potential of man-machine

interaction – Loop

• Display something• User moves light pen• Computer generates new display

– Sutherland also created many of the now common algorithms for computer graphics

1804/18/23 08:31 PM Narendra V G CSE MIT

Page 19: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Display Processor

• Rather than have the host computer try to refresh display use a special purpose computer called a display processor (DPU)

• Graphics stored in display list (display file) on display processor

• Host compiles display list and sends to DPU

1904/18/23 08:31 PM Narendra V G CSE MIT

Page 20: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Direct View Storage Tube

• Created by Tektronix– Did not require constant refresh– Standard interface to computers

• Allowed for standard software• Plot3D in Fortran

– Relatively inexpensive• Opened door to use of computer graphics for CAD

community

2004/18/23 08:31 PM Narendra V G CSE MIT

Page 21: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1970-1980

• Raster Graphics• Beginning of graphics standards

– IFIPS• GKS: European effort

– Becomes ISO 2D standard

• Core: North American effort– 3D but fails to become ISO standard

• Workstations and PCs

2104/18/23 08:31 PM Narendra V G CSE MIT

Page 22: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Raster Graphics

• Image produced as an array (the raster) of picture elements (pixels) in the frame buffer

2204/18/23 08:31 PM Narendra V G CSE MIT

Page 23: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Raster Graphics

• Allows us to go from lines and wire frame images to filled polygons

2304/18/23 08:31 PM Narendra V G CSE MIT

Page 24: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

PCs and Workstations

• Although we no longer make the distinction between workstations and PCs, historically they evolved from different roots– Early workstations characterized by

• Networked connection: client-server model• High-level of interactivity

– Early PCs included frame buffer as part of user memory

• Easy to change contents and create images

2404/18/23 08:31 PM Narendra V G CSE MIT

Page 25: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1980-1990

Realism comes to computer graphics

25

smooth shading environment mapping

bump mapping

04/18/23 08:31 PM Narendra V G CSE MIT

Page 26: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1980-1990

• Special purpose hardware– Silicon Graphics geometry engine

• VLSI implementation of graphics pipeline

• Industry-based standards– PHIGS– RenderMan

• Networked graphics: X Window System• Human-Computer Interface (HCI)

2604/18/23 08:31 PM Narendra V G CSE MIT

Page 27: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 1990-2000

• OpenGL API• Completely computer-generated feature-

length movies (Toy Story) are successful• New hardware capabilities

– Texture mapping– Blending– Accumulation, stencil buffers

2704/18/23 08:31 PM Narendra V G CSE MIT

Page 28: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Computer Graphics: 2000-

• Photorealism• Graphics cards for PCs dominate market

– Nvidia, ATI

• Game boxes and game players determine direction of market

• Computer graphics routine in movie industry: Maya, Lightwave

• Programmable pipelines

2804/18/23 08:31 PM Narendra V G CSE MIT

Page 29: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Graphics Definitions

• Point– a location in space, 2D or 3D– sometimes denotes one pixel

• Line– straight path connecting two points– infinitesimal width, consistent density– beginning and end on points

04/18/23 08:31 PM 29Narendra V G CSE MIT

Page 30: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Graphics Definitions

• Vertex– point in 3D

• Edge– line in 3D connecting two vertices

• Polygon/Face/Facet– arbitrary shape formed by connected vertices– fundamental unit of 3D computer graphics

04/18/23 08:31 PM 30Narendra V G CSE MIT

Page 31: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Graphics Definitions

• Raster– derived from TV systems for a row of pixels– commonly referred to as a scanline– does influence algorithms – reducing memory

requirements, parallelism, etc.– is the derivation of rasterization, scan-line

algorithms

04/18/23 08:31 PM 31Narendra V G CSE MIT

Page 32: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Summary

• The course is about algorithms, not applications

• Graphics execution is a pipelined approach

• Basic definitions presented

04/18/23 08:31 PM 32Narendra V G CSE MIT

Page 33: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Programming with OpenGL

Basics

Page 34: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Objectives

• Development of the OpenGL API• OpenGL Architecture

– OpenGL as a state machine

• Functions – Types– Formats

• Simple program

Narendra V G CSE MIT 3404/18/23 08:31 PM

Page 35: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Early History of APIs

• IFIPS (1973) formed two committees to come up with a standard graphics API– Graphical Kernel System (GKS)

• 2D but contained good workstation model

– Core • Both 2D and 3D

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

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

Narendra V G CSE MIT 3504/18/23 08:31 PM

Page 36: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

PHIGS and X

• Programmers Hierarchical Graphics System (PHIGS)– Arose from CAD community– Database model with retained graphics

(structures)• X Window System

– DEC/MIT effort– Client-server architecture with graphics

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

Narendra V G CSE MIT 3604/18/23 08:31 PM

Page 37: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

SGI and GL

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

• To access the system, application programmers used a library called GL

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

Narendra V G CSE MIT 3704/18/23 08:31 PM

Page 38: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL

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

performance– Focus on rendering– Omitted windowing and input to avoid window

system dependencies

Narendra V G CSE MIT 3804/18/23 08:31 PM

Page 39: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL Evolution

• Originally controlled by an Architectural Review Board (ARB)– Members included SGI, Microsoft, Nvidia, HP, 3DLabs,

IBM,…….– Relatively stable (present version 2.1)

• Evolution reflects new hardware capabilities– 3D texture mapping and texture objects– Vertex programs

– Allows for platform specific features through extensions

– ARB replaced by Kronos

Narendra V G CSE MIT 3904/18/23 08:31 PM

Page 40: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL Libraries

• OpenGL core library– OpenGL32 on Windows– GL on most unix/linux systems (libGL.a)

• OpenGL Utility Library (GLU)– Provides functionality in OpenGL core but avoids

having to rewrite code• Links with window system

– GLX for X window systems– WGL for Windows– AGL for Macintosh

Narendra V G CSE MIT 4004/18/23 08:31 PM

Page 41: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

GLUT

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

systems• Open a window• Get input from mouse and keyboard• Menus• Event-driven

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

• No slide barsNarendra V G CSE MIT 4104/18/23 08:31 PM

Page 42: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Software Organization

Narendra V G CSE MIT 42

GLUT

GLU

GL

GLX, AGLor WGL

X, Win32, Mac O/S

software and/or hardware

application program

OpenGL Motifwidget or similar

04/18/23 08:31 PM

Page 43: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL Architecture

Narendra V G CSE MIT 43

Immediate Mode

DisplayList

PolynomialEvaluator

Per VertexOperations &

PrimitiveAssembly

RasterizationPer Fragment

Operations

TextureMemory

CPU

PixelOperations

FrameBuffer

geometry pipeline

04/18/23 08:31 PM

Page 44: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL Functions

• Primitives– Points– Line Segments– Polygons

• Attributes• Transformations

– Viewing– Modeling

• Control (GLUT)• Input (GLUT)• Query

Narendra V G CSE MIT 4404/18/23 08:31 PM

Page 45: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL State

• OpenGL is a state machine• OpenGL functions are of two types

– Primitive generating• Can cause output if primitive is visible• How vertices are processed and appearance of

primitive are controlled by the state

– State changing• Transformation functions• Attribute functions

Narendra V G CSE MIT 4504/18/23 08:31 PM

Page 46: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Lack of Object Orientation

• OpenGL is not object oriented so that there are multiple functions for a given logical function– glVertex3f – glVertex2i – glVertex3dv

• Underlying storage mode is the same• Easy to create overloaded functions in C++ but

issue is efficiency

Narendra V G CSE MIT 4604/18/23 08:31 PM

Page 47: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL function format

Narendra V G CSE MIT 47

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

04/18/23 08:31 PM

Page 48: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

OpenGL #defines

• Most constants are defined in the include files gl.h, glu.h and glut.h– Note #include <GL/glut.h> should

automatically include the others– Examples– glBegin(GL_POLYGON)– glClear(GL_COLOR_BUFFER_BIT)

• include files also define OpenGL data types: GLfloat, GLdouble,….

Narendra V G CSE MIT 4804/18/23 08:31 PM

Page 49: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

A Simple Program

Generate a square on a solid background

Narendra V G CSE MIT 4904/18/23 08:31 PM

Page 50: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

simple.c

Narendra V G CSE MIT 50

#include <GL/glut.h>void mydisplay(){ glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_POLYGON); glVertex2f(-0.5, -0.5); glVertex2f(-0.5, 0.5); glVertex2f(0.5, 0.5); glVertex2f(0.5, -0.5);

glEnd();glFlush();

}int main(int argc, char** argv){

glutCreateWindow("simple"); glutDisplayFunc(mydisplay); glutMainLoop();

}04/18/23 08:31 PM

Page 51: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Event Loop

• Note that the program defines a display callback function named mydisplay– Every glut program must have a display callback– The display callback is executed whenever

OpenGL decides the display must be refreshed, for example when the window is opened

– The main function ends with the program entering an event loop

Narendra V G CSE MIT 5104/18/23 08:31 PM

Page 52: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Defaults

• simple.c is too simple• Makes heavy use of state variable default

values for– Viewing– Colors– Window parameters

• Next version will make the defaults more explicit

Narendra V G CSE MIT 5204/18/23 08:31 PM

Page 53: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Notes on compilation

• See website and ftp for examples• Unix/linux

– Include files usually in …/include/GL– Compile with –lglut –lGLU –lGL loader flags– May have to add –L flag for X libraries– Mesa implementation included with most linux

distributions– Check web for latest versions of Mesa and glut

Narendra V G CSE MIT 5304/18/23 08:31 PM

Page 54: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

Compilation on Windows

• Visual C++– Get glut.h, glut32.lib and glut32.dll from web– Create a console application– Add opengl32.lib, glut32.lib, glut32.lib to project

settings (under link tab)

• Borland C similar• Cygwin (linux under Windows)

– Can use gcc and similar makefile to linux– Use –lopengl32 –lglu32 –lglut32 flags

Narendra V G CSE MIT 5404/18/23 08:31 PM

Page 55: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

To display window and line segment #include<GL/gl.h>#include<GL/glu.h>#include<GL/glut.h>void init (void){ glClearColor(1.0,1.0,1.0,0.0) ;//set display-window color to white glMatrixMode(GL_PROJECTION); //set projection parameter gluOrtho2D(0.0,200.0,0.0,150.0); }void lineSegment(void){ glClear(GL_COLOR_BUFFER_BIT); //clear display window glColor3f(1.0,0.0,0.0); //set line segment color to red glBegin(GL_LINES);

glVertex2i(180,15); //specify line-segment geometry glVertex2i(10,145); glEnd(); glFlush(); }

04/18/23 08:31 PM Narendra V G CSE MIT 55

Page 56: 6/10/2015 3:41:00 AM 1 CSE 307 COMPUTER GRAPHICS  OVERVIEW OF GRAPHICS SYSTEMS  GRAPHICS OUTPUT PRIMITIVES  GEOMETRICAL TRANSFORMATIONS  TWO DIMENSIONAL

void main(int argc, char** argv) { glutInit(&argc, argv); // Initialize GLUT glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB); //set display mode glutInitWindowPosition(50,100); //set top-left display window position glutInitWindowSize(400,300); //set display window width and height glutCreateWindow(“An Example OpenGL Program”); //create dis-win init( ); //Execute initialization procedure glutDisplayFunc(lineSegment); //send graphics to display window glutMainLoop( );//Display everything and wait}

04/18/23 08:31 PM Narendra V G CSE MIT 56

To display window and line segment