SlideShare a Scribd company logo
Noggin
(BYU Students,
SIGGRAPH 2006)
Introduction to
OpenGL Programming
Rick Skarbez, Instructor
COMP 575
September 11, 2007
Announcements
• Reminder: Homework 1 is due
Thursday
• Questions?
• Class next Tuesday (9/18) will be held
in SN 014
• Extended transformations to 3D
• Introduced some principles of computer
animation
• Lasseter’s “Principles of Traditional
Animation Applied to 3D Computer
Graphics”
• How to create “The Illusion of Life”
Last Time
Today
• Learning how to program in OpenGL
• OpenGL
• C/C++
• GLUT, FLTK, Cocoa
OpenGL in Java
• I have never used Java for OpenGL
programming
• I can’t be much help in getting it set up
• If you really want to try using OpenGL in
Java
• The JOGL API Project
• https://jogl.dev.java.net/
• Go there and follow the instructions
What is OpenGL?
• The standard specification defining an
API that interfaces with the computer’s
graphics system
• Cross-language
• Cross-platform
• Vendor-independent
• Competes with DirectX on Windows
The Rendering
Datapath
Computer
Software
Graphics
Driver
Frame
Buffer
Scanout
Logic
Display
VGA / DVI
OpenGL API
PCI Express Bus
High-Speed, Guaranteed Latency Interconnect
3D
Hardware
An older version is available (free!)
online:
http://fly.cc.fer.hr/~unreal/theredboo
k/
The “Red Book”
Online Resources
http://nehe.gamedev.net
http://www.opengl.org
The Camera Analogy
OpenGL’s World
Camera
Description
(Intrinsic &
Extrinsic)
Scene Object
Transforms
What To
Display On Screen
Code
Specified
Parameters
Contexts and
Viewports?
• Each OpenGL application creates a
context to issue rendering commands to
• The application must also define a
viewport, a region of pixels on the
screen that can see the context
• Can be
• Part of a window
• An entire window
• The whole screen
OpenGL as a State
Machine
• OpenGL is designed as a finite state
machine
• Graphics system is a “black box”
• Most functions change the state of the
machine
• One function runs input through the
machine
OpenGL State
• Some attributes of the OpenGL state
• Current color
• Camera properties (location, orientation,
field of view, etc.)
• Lighting model (flat, smooth, etc.)
• Type of primitive being drawn
• And many more...
Our First OpenGL
Code
...
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
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();
...
OpenGL Input
• All inputs (i.e. geometry) to an OpenGL
context are defined as vertex lists
• glVertex*
• * = nt OR ntv
• n - number (2, 3, 4)
• t - type (i = integer, f = float, etc.)
• v - vector
OpenGL Types
Suffix Data Type
Typical Corresponding
C-Language Type
OpenGL Type
Definition
b 8-bit integer signed char GLbyte
s 16-bit integer short GLshort
i 32-bit integer long GLint, GLsizei
f 32-bit floating-point float GLfloat, GLclampf
d 64-bit floating-point double GLdouble, GLclampd
ub 8-bit unsigned integer unsigned char GLubyte, GLboolean
us 16-bit unsigned integer unsigned short GLushort
ui 32-bit unsigned integer unsigned long
GLuint, GLenum,
GLbitfield
OpenGL Input
• Examples:
• glVertex2i(5, 4);
• Specifies a vertex at location (5, 4) on the
z = 0 plane
• “2” tells the system to expect a 2-vector
(a vertex defined in 2D)
• “i” tells the system that the vertex will
have integer locations
OpenGL Input
• More examples:
• glVertex3f(.25, .25, .5);
• double vertex[3] = {1.0, .33, 3.14159};
glVertex3dv(vertex);
• “v” tells the system to expect the
coordinate list in a single data structure,
instead of a list of n numbers
OpenGL Primitive
Types
• All geometry is specified by vertex lists
• But can draw multiple types of things
• Points
• Lines
• Triangles
• etc.
• The different things the system knows
how to draw are the system primitives
Specifying the
OpenGL Primitive
Type
• glBegin(primitiveType);
// A list of glVertex* calls goes here
// ...
glEnd();
• primitiveType can be any of several
things
• See the next slide
OpenGL Primitive
Types
OpenGL Primitives
Example
glBegin(GL_POLYGON);
glVertex2f(0.0, 0.0);
glVertex2f(0.0, 3.0);
glVertex2f(3.0, 3.0);
glVertex2f(4.0, 1.5);
glVertex2f(3.0, 0.0);
glEnd();
Color in OpenGL
• Monitors can have different color
resolutions
• Black & white
• 256 color
• 16.8M color
• Want to specify color in a device-
independent way
Color in OpenGL
• glColor4f(r, g, b, a);
• r, g, b, a - should all be between [0.0, 1.0]
• r, g, b - amounts of red, green, and blue
• a - alpha
• Defines how opaque a primitive is
• 0.0 = totally transparent, 1.0 = totally
opaque
• Usually want a = 1.0
Finishing Up Your
OpenGL Program
• OpenGL commands are not executed
immediately
• They are put into a command buffer that
gets fed to the hardware
• When you’re done drawing, need to
send the commands to the graphics
hardware
• glFlush() or glFinish()
glFlush vs. glFinish
• glFlush();
• Forces all issued commands to begin
execution
• Returns immediately (asynchronous)
• glFinish();
• Forces all issued commands to execute
• Does not return until execution is complete
(synchronous)
Matrices in OpenGL
• Vertices are transformed by 2 matrices:
• ModelView
• Maps 3D to 3D
• Transforms vertices from object
coordinates to eye coordinates
• Projection
• Maps 3D to 2D (sort of)
• Transforms vertices from eye coordinates
to clip coordinates
The ModelView
Matrix
• In OpenGL, the viewing and modeling
transforms are combined into a single
matrix - the modelview matrix
• Viewing Transform - positioning the camera
• Modeling Transform - positioning the object
• Why?
• Consider how you would “translate” a fixed
object with a real camera
Placing the Camera
• gluLookAt(
GLdouble eyeX, GLdouble eyeY, GLdouble
eyeZ, GLdouble midX, GLdouble midY,
GLdouble midZ,
GLdouble upX, GLdouble upY, GLdouble upZ)
• (eyeX, eyeY, eyeZ) - location of the
viewpoint
• (midX, midY, midZ) - location of a point on
the line of sight
• (upX, upY, upZ) - direction of the up vector
• By default the camera is at the origin,
looking down negative z, and the up
vector is the positive y axis
WARNING!
OpenGL Matrices
• In C/C++, we are used to row-major
matrices
• In OpenGL, matrices are specified in
column-major order
Row-Major Order Column-Major Order
Using OpenGL
Matrices
• Use the following function to specify
which matrix you are changing:
• glMatrixMode(whichMatrix);
• whichMatrix = GL_PROJECTION |
GL_MODELVIEW
• To guarantee a “fresh start”, use
glLoadIdentity();
• Loads the identity matrix into the active
matrix
Using OpenGL
Matrices
• To load a user-defined matrix into the
current matrix:
• glLoadMatrix{fd}(TYPE *m)
• To multiply the current matrix by a user
defined matrix
• glMultMatrix{fd}(TYPE *m)
• SUGGESTION: To avoid row-/column-
major confusion, specify matrices as
m[16] instead of m[4][4]
Transforms in
OpenGL
• OpenGL uses 4x4 matrices for all its
transforms
• But you don’t have to build them all by hand!
• glRotate{fd}(angle, x, y, z)
• Rotates counter-clockwise by angle degrees
about the vector (x, y, z)
• glTranslate{fd}(x, y, z)
• glScale{fd}(x, y, z)
• In OpenGL, the last transform in a list is
applied FIRST
• Think back to right-multiplication of
transforms
• Example:
• glRotatef(45.0f, 0.0f, 0.0f, 0.0f);
glTranslatef(10.0f, 0.0f, 0.0f);
drawSomeVertices();
• Translates first, then rotates
WARNING!Order of
Transforms
Projection
Transforms
• The projection matrix defines the
viewing volume
• Used for 2 things:
• Projects an object onto the screen
• Determines how objects are clipped
• The viewpoint (the location of the
“camera”) that we’ve been talking about
is at one end of the viewing volume
Projection
Transforms
• Perspective
• Viewing volume is a truncated pyramid
• aka frustum
• Orthographic
• Viewing volume is a box
Perspective
Orthographic
Perspective
Projection
• The most noticeable effect of
perspective projection is foreshortening
• OpenGL provides several functions to
define a viewing frustum
• glFrustum(...)
• gluPerspective(...)
glFrustum
• glFrustum(GLdouble left, GLdouble
right, GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far)
• (left, bottom, -near) and (right, top, -near)
are the bottom-left and top-right corners of
the near clip plane
• far is the distance
to the far clip
plane
• near and far
should always be
positive
gluPerspective
• This GL Utility Library function provides a
more intuitive way (I think) to define a
frustum
• gluPerspective(GLdouble fovy, GLdouble
aspect, GLdouble near, GLdouble far)
• fovy - field of view in y (in degrees)
• aspect - aspect ratio (width / height)
• near and far - same as with glFrustum()
Orthographic
Projection
• With orthographic projection, there is no
foreshortening
• Distance from the camera does not change
apparent size
• Again, there are several
functions that can define
an orthographic projection
• glOrtho()
• gluOrtho2D()
glOrtho
• glOrtho(GLdouble left, GLdouble right,
GLdouble bottom, GLdouble top,
GLdouble near, GLdouble far)
• Arguments are the same as glPerspective()
• (left, bottom, -near) and (right, top, -near)
are the bottom-left and top-right corners of
the near clip plane
• near and far can be any
values, but they should
not be the same
gluOrtho2D
• This GL Utility Library function provides
a more intuitive way (I think) to define a
frustum
• gluOrtho2D(GLdouble left, GLdouble
right, GLdouble bottom, GLdouble top)
• (left, bottom) and (right, top) define the (x, y)
coordinates of the bottom-left and top-right
corners of the clipping region
• Automatically clips to between -1.0 and 1.0
in z
Viewport
• The viewport is the part of the window
your drawing is displayed to
• By default, the viewport is the entire window
• Modifying the viewport is analogous to
changing the size of the final picture
• From the camera analogy
• Can have multiple viewports in the
same window for a split-screen effect
Setting the Viewport
• glViewport(int x, int y, int width, int
height)
• (x, y) is the location of the origin (lower-left)
within the window
• (width, height) is the size of the viewport
• The aspect ratio of the viewport should
be the same as that of the viewing
volume
(0,0) width
height
(x,y)
Viewport
Window

More Related Content

Similar to september11.ppt

18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
NatsuDragoneel5
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
AnandM62785
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
Prachi Mishra
 
CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...
rsebbe
 
Open Graphics Library
Open Graphics  Library Open Graphics  Library
Open Graphics Library
Azmeen Gadit
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
Syed Zaid Irshad
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
Kunal Verma
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
💻 Anton Gerdelan
 
Grafika komputer 2
Grafika komputer 2Grafika komputer 2
Grafika komputer 2
Nur Fadli Utomo
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
Jayant Mukherjee
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
Mohammad Hosein Nemati
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
Jungsoo Nam
 
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMPImplementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
lgworld
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
Wingston
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
Mohammad Hosein Nemati
 
2D graphics
2D graphics2D graphics
2D graphics
Muhammad Rashid
 
Open gl
Open glOpen gl
Open gl
ch samaram
 

Similar to september11.ppt (20)

18csl67 vtu lab manual
18csl67 vtu lab manual18csl67 vtu lab manual
18csl67 vtu lab manual
 
Computer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptxComputer Graphics with OpenGL presentation Slides.pptx
Computer Graphics with OpenGL presentation Slides.pptx
 
Open gl basics
Open gl basicsOpen gl basics
Open gl basics
 
Graphics Libraries
Graphics LibrariesGraphics Libraries
Graphics Libraries
 
CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...CeedMath & CeedGL, Let's talk 3D...
CeedMath & CeedGL, Let's talk 3D...
 
Open Graphics Library
Open Graphics  Library Open Graphics  Library
Open Graphics Library
 
Bai 1
Bai 1Bai 1
Bai 1
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
Hill ch2ed3
Hill ch2ed3Hill ch2ed3
Hill ch2ed3
 
Computer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming IComputer Graphics - Lecture 01 - 3D Programming I
Computer Graphics - Lecture 01 - 3D Programming I
 
Opengl basics
Opengl basicsOpengl basics
Opengl basics
 
Grafika komputer 2
Grafika komputer 2Grafika komputer 2
Grafika komputer 2
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
What is OpenGL ?
What is OpenGL ?What is OpenGL ?
What is OpenGL ?
 
OpenGL Shading Language
OpenGL Shading LanguageOpenGL Shading Language
OpenGL Shading Language
 
Implementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMPImplementing OpenCL support in GEGL and GIMP
Implementing OpenCL support in GEGL and GIMP
 
C game programming - SDL
C game programming - SDLC game programming - SDL
C game programming - SDL
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
 
2D graphics
2D graphics2D graphics
2D graphics
 
Open gl
Open glOpen gl
Open gl
 

More from CharlesMatu2

The cause of ww1 happened 1914 this was after the the asssasination of Arc...
The  cause of ww1  happened  1914 this was after the the asssasination of Arc...The  cause of ww1  happened  1914 this was after the the asssasination of Arc...
The cause of ww1 happened 1914 this was after the the asssasination of Arc...
CharlesMatu2
 
AP Ch 1.ppt
AP Ch 1.pptAP Ch 1.ppt
AP Ch 1.ppt
CharlesMatu2
 
history_of_american_agriculture.ppt
history_of_american_agriculture.ppthistory_of_american_agriculture.ppt
history_of_american_agriculture.ppt
CharlesMatu2
 
Origin of Agriculture.ppt
Origin of Agriculture.pptOrigin of Agriculture.ppt
Origin of Agriculture.ppt
CharlesMatu2
 
History of Science and Technology.ppt
History of Science and Technology.pptHistory of Science and Technology.ppt
History of Science and Technology.ppt
CharlesMatu2
 
september13.ppt
september13.pptseptember13.ppt
september13.ppt
CharlesMatu2
 
september18.ppt
september18.pptseptember18.ppt
september18.ppt
CharlesMatu2
 
september4.ppt
september4.pptseptember4.ppt
september4.ppt
CharlesMatu2
 
september6.ppt
september6.pptseptember6.ppt
september6.ppt
CharlesMatu2
 
august23.ppt
august23.pptaugust23.ppt
august23.ppt
CharlesMatu2
 
november6.ppt
november6.pptnovember6.ppt
november6.ppt
CharlesMatu2
 
november29.ppt
november29.pptnovember29.ppt
november29.ppt
CharlesMatu2
 
october9.ppt
october9.pptoctober9.ppt
october9.ppt
CharlesMatu2
 
october23.ppt
october23.pptoctober23.ppt
october23.ppt
CharlesMatu2
 
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.pptLighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
CharlesMatu2
 
BBM3117 CAT 31ST.docx
BBM3117 CAT 31ST.docxBBM3117 CAT 31ST.docx
BBM3117 CAT 31ST.docx
CharlesMatu2
 
Computer graphics.docx
Computer graphics.docxComputer graphics.docx
Computer graphics.docx
CharlesMatu2
 
BIT4103 HUMAN COMPUTER INTERACTION CAT.docx
BIT4103 HUMAN COMPUTER INTERACTION CAT.docxBIT4103 HUMAN COMPUTER INTERACTION CAT.docx
BIT4103 HUMAN COMPUTER INTERACTION CAT.docx
CharlesMatu2
 

More from CharlesMatu2 (18)

The cause of ww1 happened 1914 this was after the the asssasination of Arc...
The  cause of ww1  happened  1914 this was after the the asssasination of Arc...The  cause of ww1  happened  1914 this was after the the asssasination of Arc...
The cause of ww1 happened 1914 this was after the the asssasination of Arc...
 
AP Ch 1.ppt
AP Ch 1.pptAP Ch 1.ppt
AP Ch 1.ppt
 
history_of_american_agriculture.ppt
history_of_american_agriculture.ppthistory_of_american_agriculture.ppt
history_of_american_agriculture.ppt
 
Origin of Agriculture.ppt
Origin of Agriculture.pptOrigin of Agriculture.ppt
Origin of Agriculture.ppt
 
History of Science and Technology.ppt
History of Science and Technology.pptHistory of Science and Technology.ppt
History of Science and Technology.ppt
 
september13.ppt
september13.pptseptember13.ppt
september13.ppt
 
september18.ppt
september18.pptseptember18.ppt
september18.ppt
 
september4.ppt
september4.pptseptember4.ppt
september4.ppt
 
september6.ppt
september6.pptseptember6.ppt
september6.ppt
 
august23.ppt
august23.pptaugust23.ppt
august23.ppt
 
november6.ppt
november6.pptnovember6.ppt
november6.ppt
 
november29.ppt
november29.pptnovember29.ppt
november29.ppt
 
october9.ppt
october9.pptoctober9.ppt
october9.ppt
 
october23.ppt
october23.pptoctober23.ppt
october23.ppt
 
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.pptLighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
Lighting & Shading in OpenGL Non-Photorealistic Rendering.ppt
 
BBM3117 CAT 31ST.docx
BBM3117 CAT 31ST.docxBBM3117 CAT 31ST.docx
BBM3117 CAT 31ST.docx
 
Computer graphics.docx
Computer graphics.docxComputer graphics.docx
Computer graphics.docx
 
BIT4103 HUMAN COMPUTER INTERACTION CAT.docx
BIT4103 HUMAN COMPUTER INTERACTION CAT.docxBIT4103 HUMAN COMPUTER INTERACTION CAT.docx
BIT4103 HUMAN COMPUTER INTERACTION CAT.docx
 

Recently uploaded

The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
iraqartsandculture
 
A Brief Introduction About Hadj Ounis
A Brief  Introduction  About  Hadj OunisA Brief  Introduction  About  Hadj Ounis
A Brief Introduction About Hadj Ounis
Hadj Ounis
 
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
zeyhe
 
Caffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire WilsonCaffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire Wilson
ClaireWilson398082
 
ashokathegreat project class 12 presentation
ashokathegreat project class 12 presentationashokathegreat project class 12 presentation
ashokathegreat project class 12 presentation
aditiyad2020
 
Codes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new newCodes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new new
ZackSpencer3
 
2137ad Merindol Colony Interiors where refugee try to build a seemengly norm...
2137ad  Merindol Colony Interiors where refugee try to build a seemengly norm...2137ad  Merindol Colony Interiors where refugee try to build a seemengly norm...
2137ad Merindol Colony Interiors where refugee try to build a seemengly norm...
luforfor
 
Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)
SuryaKalyan3
 
Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)
SuryaKalyan3
 
Fed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine ZorbaFed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine Zorba
mariavlachoupt
 
IrishWritersCtrsPersonalEssaysMay29.pptx
IrishWritersCtrsPersonalEssaysMay29.pptxIrishWritersCtrsPersonalEssaysMay29.pptx
IrishWritersCtrsPersonalEssaysMay29.pptx
Aine Greaney Ellrott
 
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
zvaywau
 
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
taqyed
 
ART FORMS OF KERALA: TRADITIONAL AND OTHERS
ART FORMS OF KERALA: TRADITIONAL AND OTHERSART FORMS OF KERALA: TRADITIONAL AND OTHERS
ART FORMS OF KERALA: TRADITIONAL AND OTHERS
Sandhya J.Nair
 
一比一原版(DU毕业证)迪肯大学毕业证成绩单
一比一原版(DU毕业证)迪肯大学毕业证成绩单一比一原版(DU毕业证)迪肯大学毕业证成绩单
一比一原版(DU毕业证)迪肯大学毕业证成绩单
zvaywau
 
2137ad - Characters that live in Merindol and are at the center of main stories
2137ad - Characters that live in Merindol and are at the center of main stories2137ad - Characters that live in Merindol and are at the center of main stories
2137ad - Characters that live in Merindol and are at the center of main stories
luforfor
 
acting board rough title here lolaaaaaaa
acting board rough title here lolaaaaaaaacting board rough title here lolaaaaaaa
acting board rough title here lolaaaaaaa
angelicafronda7
 
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
zeyhe
 
Inter-Dimensional Girl Boards Segment (Act 3)
Inter-Dimensional Girl Boards Segment (Act 3)Inter-Dimensional Girl Boards Segment (Act 3)
Inter-Dimensional Girl Boards Segment (Act 3)
CristianMestre
 

Recently uploaded (19)

The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
The Last Polymath: Muntadher Saleh‎‎‎‎‎‎‎‎‎‎‎‎
 
A Brief Introduction About Hadj Ounis
A Brief  Introduction  About  Hadj OunisA Brief  Introduction  About  Hadj Ounis
A Brief Introduction About Hadj Ounis
 
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
一比一原版(QUT毕业证)昆士兰科技大学毕业证成绩单如何办理
 
Caffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire WilsonCaffeinated Pitch Bible- developed by Claire Wilson
Caffeinated Pitch Bible- developed by Claire Wilson
 
ashokathegreat project class 12 presentation
ashokathegreat project class 12 presentationashokathegreat project class 12 presentation
ashokathegreat project class 12 presentation
 
Codes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new newCodes n Conventionss copy (2).pptx new new
Codes n Conventionss copy (2).pptx new new
 
2137ad Merindol Colony Interiors where refugee try to build a seemengly norm...
2137ad  Merindol Colony Interiors where refugee try to build a seemengly norm...2137ad  Merindol Colony Interiors where refugee try to build a seemengly norm...
2137ad Merindol Colony Interiors where refugee try to build a seemengly norm...
 
Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)Memory Rental Store - The Ending(Storyboard)
Memory Rental Store - The Ending(Storyboard)
 
Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)Memory Rental Store - The Chase (Storyboard)
Memory Rental Store - The Chase (Storyboard)
 
Fed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine ZorbaFed by curiosity and beauty - Remembering Myrsine Zorba
Fed by curiosity and beauty - Remembering Myrsine Zorba
 
IrishWritersCtrsPersonalEssaysMay29.pptx
IrishWritersCtrsPersonalEssaysMay29.pptxIrishWritersCtrsPersonalEssaysMay29.pptx
IrishWritersCtrsPersonalEssaysMay29.pptx
 
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
一比一原版(GU毕业证)格里菲斯大学毕业证成绩单
 
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
一比一原版(qut毕业证)昆士兰科技大学毕业证如何办理
 
ART FORMS OF KERALA: TRADITIONAL AND OTHERS
ART FORMS OF KERALA: TRADITIONAL AND OTHERSART FORMS OF KERALA: TRADITIONAL AND OTHERS
ART FORMS OF KERALA: TRADITIONAL AND OTHERS
 
一比一原版(DU毕业证)迪肯大学毕业证成绩单
一比一原版(DU毕业证)迪肯大学毕业证成绩单一比一原版(DU毕业证)迪肯大学毕业证成绩单
一比一原版(DU毕业证)迪肯大学毕业证成绩单
 
2137ad - Characters that live in Merindol and are at the center of main stories
2137ad - Characters that live in Merindol and are at the center of main stories2137ad - Characters that live in Merindol and are at the center of main stories
2137ad - Characters that live in Merindol and are at the center of main stories
 
acting board rough title here lolaaaaaaa
acting board rough title here lolaaaaaaaacting board rough title here lolaaaaaaa
acting board rough title here lolaaaaaaa
 
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
一比一原版(UniSA毕业证)南澳大学毕业证成绩单如何办理
 
Inter-Dimensional Girl Boards Segment (Act 3)
Inter-Dimensional Girl Boards Segment (Act 3)Inter-Dimensional Girl Boards Segment (Act 3)
Inter-Dimensional Girl Boards Segment (Act 3)
 

september11.ppt

  • 2. Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007
  • 3. Announcements • Reminder: Homework 1 is due Thursday • Questions? • Class next Tuesday (9/18) will be held in SN 014
  • 4. • Extended transformations to 3D • Introduced some principles of computer animation • Lasseter’s “Principles of Traditional Animation Applied to 3D Computer Graphics” • How to create “The Illusion of Life” Last Time
  • 5. Today • Learning how to program in OpenGL • OpenGL • C/C++ • GLUT, FLTK, Cocoa
  • 6. OpenGL in Java • I have never used Java for OpenGL programming • I can’t be much help in getting it set up • If you really want to try using OpenGL in Java • The JOGL API Project • https://jogl.dev.java.net/ • Go there and follow the instructions
  • 7. What is OpenGL? • The standard specification defining an API that interfaces with the computer’s graphics system • Cross-language • Cross-platform • Vendor-independent • Competes with DirectX on Windows
  • 8. The Rendering Datapath Computer Software Graphics Driver Frame Buffer Scanout Logic Display VGA / DVI OpenGL API PCI Express Bus High-Speed, Guaranteed Latency Interconnect 3D Hardware
  • 9. An older version is available (free!) online: http://fly.cc.fer.hr/~unreal/theredboo k/ The “Red Book”
  • 12. OpenGL’s World Camera Description (Intrinsic & Extrinsic) Scene Object Transforms What To Display On Screen Code Specified Parameters
  • 13. Contexts and Viewports? • Each OpenGL application creates a context to issue rendering commands to • The application must also define a viewport, a region of pixels on the screen that can see the context • Can be • Part of a window • An entire window • The whole screen
  • 14. OpenGL as a State Machine • OpenGL is designed as a finite state machine • Graphics system is a “black box” • Most functions change the state of the machine • One function runs input through the machine
  • 15. OpenGL State • Some attributes of the OpenGL state • Current color • Camera properties (location, orientation, field of view, etc.) • Lighting model (flat, smooth, etc.) • Type of primitive being drawn • And many more...
  • 16. Our First OpenGL Code ... glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); 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(); ...
  • 17. OpenGL Input • All inputs (i.e. geometry) to an OpenGL context are defined as vertex lists • glVertex* • * = nt OR ntv • n - number (2, 3, 4) • t - type (i = integer, f = float, etc.) • v - vector
  • 18. OpenGL Types Suffix Data Type Typical Corresponding C-Language Type OpenGL Type Definition b 8-bit integer signed char GLbyte s 16-bit integer short GLshort i 32-bit integer long GLint, GLsizei f 32-bit floating-point float GLfloat, GLclampf d 64-bit floating-point double GLdouble, GLclampd ub 8-bit unsigned integer unsigned char GLubyte, GLboolean us 16-bit unsigned integer unsigned short GLushort ui 32-bit unsigned integer unsigned long GLuint, GLenum, GLbitfield
  • 19. OpenGL Input • Examples: • glVertex2i(5, 4); • Specifies a vertex at location (5, 4) on the z = 0 plane • “2” tells the system to expect a 2-vector (a vertex defined in 2D) • “i” tells the system that the vertex will have integer locations
  • 20. OpenGL Input • More examples: • glVertex3f(.25, .25, .5); • double vertex[3] = {1.0, .33, 3.14159}; glVertex3dv(vertex); • “v” tells the system to expect the coordinate list in a single data structure, instead of a list of n numbers
  • 21. OpenGL Primitive Types • All geometry is specified by vertex lists • But can draw multiple types of things • Points • Lines • Triangles • etc. • The different things the system knows how to draw are the system primitives
  • 22. Specifying the OpenGL Primitive Type • glBegin(primitiveType); // A list of glVertex* calls goes here // ... glEnd(); • primitiveType can be any of several things • See the next slide
  • 24. OpenGL Primitives Example glBegin(GL_POLYGON); glVertex2f(0.0, 0.0); glVertex2f(0.0, 3.0); glVertex2f(3.0, 3.0); glVertex2f(4.0, 1.5); glVertex2f(3.0, 0.0); glEnd();
  • 25. Color in OpenGL • Monitors can have different color resolutions • Black & white • 256 color • 16.8M color • Want to specify color in a device- independent way
  • 26. Color in OpenGL • glColor4f(r, g, b, a); • r, g, b, a - should all be between [0.0, 1.0] • r, g, b - amounts of red, green, and blue • a - alpha • Defines how opaque a primitive is • 0.0 = totally transparent, 1.0 = totally opaque • Usually want a = 1.0
  • 27. Finishing Up Your OpenGL Program • OpenGL commands are not executed immediately • They are put into a command buffer that gets fed to the hardware • When you’re done drawing, need to send the commands to the graphics hardware • glFlush() or glFinish()
  • 28. glFlush vs. glFinish • glFlush(); • Forces all issued commands to begin execution • Returns immediately (asynchronous) • glFinish(); • Forces all issued commands to execute • Does not return until execution is complete (synchronous)
  • 29. Matrices in OpenGL • Vertices are transformed by 2 matrices: • ModelView • Maps 3D to 3D • Transforms vertices from object coordinates to eye coordinates • Projection • Maps 3D to 2D (sort of) • Transforms vertices from eye coordinates to clip coordinates
  • 30. The ModelView Matrix • In OpenGL, the viewing and modeling transforms are combined into a single matrix - the modelview matrix • Viewing Transform - positioning the camera • Modeling Transform - positioning the object • Why? • Consider how you would “translate” a fixed object with a real camera
  • 31. Placing the Camera • gluLookAt( GLdouble eyeX, GLdouble eyeY, GLdouble eyeZ, GLdouble midX, GLdouble midY, GLdouble midZ, GLdouble upX, GLdouble upY, GLdouble upZ) • (eyeX, eyeY, eyeZ) - location of the viewpoint • (midX, midY, midZ) - location of a point on the line of sight • (upX, upY, upZ) - direction of the up vector • By default the camera is at the origin, looking down negative z, and the up vector is the positive y axis
  • 32. WARNING! OpenGL Matrices • In C/C++, we are used to row-major matrices • In OpenGL, matrices are specified in column-major order Row-Major Order Column-Major Order
  • 33. Using OpenGL Matrices • Use the following function to specify which matrix you are changing: • glMatrixMode(whichMatrix); • whichMatrix = GL_PROJECTION | GL_MODELVIEW • To guarantee a “fresh start”, use glLoadIdentity(); • Loads the identity matrix into the active matrix
  • 34. Using OpenGL Matrices • To load a user-defined matrix into the current matrix: • glLoadMatrix{fd}(TYPE *m) • To multiply the current matrix by a user defined matrix • glMultMatrix{fd}(TYPE *m) • SUGGESTION: To avoid row-/column- major confusion, specify matrices as m[16] instead of m[4][4]
  • 35. Transforms in OpenGL • OpenGL uses 4x4 matrices for all its transforms • But you don’t have to build them all by hand! • glRotate{fd}(angle, x, y, z) • Rotates counter-clockwise by angle degrees about the vector (x, y, z) • glTranslate{fd}(x, y, z) • glScale{fd}(x, y, z)
  • 36. • In OpenGL, the last transform in a list is applied FIRST • Think back to right-multiplication of transforms • Example: • glRotatef(45.0f, 0.0f, 0.0f, 0.0f); glTranslatef(10.0f, 0.0f, 0.0f); drawSomeVertices(); • Translates first, then rotates WARNING!Order of Transforms
  • 37. Projection Transforms • The projection matrix defines the viewing volume • Used for 2 things: • Projects an object onto the screen • Determines how objects are clipped • The viewpoint (the location of the “camera”) that we’ve been talking about is at one end of the viewing volume
  • 38. Projection Transforms • Perspective • Viewing volume is a truncated pyramid • aka frustum • Orthographic • Viewing volume is a box Perspective Orthographic
  • 39. Perspective Projection • The most noticeable effect of perspective projection is foreshortening • OpenGL provides several functions to define a viewing frustum • glFrustum(...) • gluPerspective(...)
  • 40. glFrustum • glFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) • (left, bottom, -near) and (right, top, -near) are the bottom-left and top-right corners of the near clip plane • far is the distance to the far clip plane • near and far should always be positive
  • 41. gluPerspective • This GL Utility Library function provides a more intuitive way (I think) to define a frustum • gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble near, GLdouble far) • fovy - field of view in y (in degrees) • aspect - aspect ratio (width / height) • near and far - same as with glFrustum()
  • 42. Orthographic Projection • With orthographic projection, there is no foreshortening • Distance from the camera does not change apparent size • Again, there are several functions that can define an orthographic projection • glOrtho() • gluOrtho2D()
  • 43. glOrtho • glOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble near, GLdouble far) • Arguments are the same as glPerspective() • (left, bottom, -near) and (right, top, -near) are the bottom-left and top-right corners of the near clip plane • near and far can be any values, but they should not be the same
  • 44. gluOrtho2D • This GL Utility Library function provides a more intuitive way (I think) to define a frustum • gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top) • (left, bottom) and (right, top) define the (x, y) coordinates of the bottom-left and top-right corners of the clipping region • Automatically clips to between -1.0 and 1.0 in z
  • 45. Viewport • The viewport is the part of the window your drawing is displayed to • By default, the viewport is the entire window • Modifying the viewport is analogous to changing the size of the final picture • From the camera analogy • Can have multiple viewports in the same window for a split-screen effect
  • 46. Setting the Viewport • glViewport(int x, int y, int width, int height) • (x, y) is the location of the origin (lower-left) within the window • (width, height) is the size of the viewport • The aspect ratio of the viewport should be the same as that of the viewing volume (0,0) width height (x,y) Viewport Window