Upload
libra
View
65
Download
0
Tags:
Embed Size (px)
DESCRIPTION
OpenGL Basics Compared to DirectX. By Jin Li Jan 20th, 2005 Introduction to Computer Graphics. Review of the major similarities and differences. DirectX is more than just a graphics API, OpenGL is strictly a graphics API - PowerPoint PPT Presentation
Citation preview
OpenGL Basics Compared to DirectX
By Jin Li
Jan 20th 2005
Introduction to Computer Graphics
Review of the major similarities and differences DirectX is more than just a graphics API
OpenGL is strictly a graphics API Both use the traditional hardware rendering
pipeline which is based on the z buffer Both describe vertices as a set of data
consisting of coordinates Graphics primitives are defined as an ordered set of vertices How each API handles vertices to form primitives is different
OpenGL Cross-platform open standard easier to
understandNo support for create graphic user interface needs
other supports
DirectX A Windows-specific proprietary standard harder to
understand But with Managed DirectX (DirectX wrapped into
very handy NET classes) easier to useFull support a Multimedia API
OpenGL
First from SGI (Silicon Graphics Inc) Now ARB( Architecture Review Board)
New functionalities through vendor-specific extensions The base API changes only slowly
DirectX
Developed by Microsoft with some other vendors
New functionalities through API changes quite severely
How to Start
Windows ndash Since Window 98 the library has already been included
LINUXBSD ndash There are several free implementations GLX Mesa TinyGL Ygl
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Review of the major similarities and differences DirectX is more than just a graphics API
OpenGL is strictly a graphics API Both use the traditional hardware rendering
pipeline which is based on the z buffer Both describe vertices as a set of data
consisting of coordinates Graphics primitives are defined as an ordered set of vertices How each API handles vertices to form primitives is different
OpenGL Cross-platform open standard easier to
understandNo support for create graphic user interface needs
other supports
DirectX A Windows-specific proprietary standard harder to
understand But with Managed DirectX (DirectX wrapped into
very handy NET classes) easier to useFull support a Multimedia API
OpenGL
First from SGI (Silicon Graphics Inc) Now ARB( Architecture Review Board)
New functionalities through vendor-specific extensions The base API changes only slowly
DirectX
Developed by Microsoft with some other vendors
New functionalities through API changes quite severely
How to Start
Windows ndash Since Window 98 the library has already been included
LINUXBSD ndash There are several free implementations GLX Mesa TinyGL Ygl
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
OpenGL Cross-platform open standard easier to
understandNo support for create graphic user interface needs
other supports
DirectX A Windows-specific proprietary standard harder to
understand But with Managed DirectX (DirectX wrapped into
very handy NET classes) easier to useFull support a Multimedia API
OpenGL
First from SGI (Silicon Graphics Inc) Now ARB( Architecture Review Board)
New functionalities through vendor-specific extensions The base API changes only slowly
DirectX
Developed by Microsoft with some other vendors
New functionalities through API changes quite severely
How to Start
Windows ndash Since Window 98 the library has already been included
LINUXBSD ndash There are several free implementations GLX Mesa TinyGL Ygl
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
OpenGL
First from SGI (Silicon Graphics Inc) Now ARB( Architecture Review Board)
New functionalities through vendor-specific extensions The base API changes only slowly
DirectX
Developed by Microsoft with some other vendors
New functionalities through API changes quite severely
How to Start
Windows ndash Since Window 98 the library has already been included
LINUXBSD ndash There are several free implementations GLX Mesa TinyGL Ygl
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
How to Start
Windows ndash Since Window 98 the library has already been included
LINUXBSD ndash There are several free implementations GLX Mesa TinyGL Ygl
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
GL UTILITIES (GLU) OpenGL Utility Library included in Standard OpenGL It includes a set of functions in
Texture mipmapping from a base image Draw quadric surfaces and NURBS Camera management
The GL Utility Library
Extends functionality of OpenGL libraryGeneral independent window supportManages keyboard mouse window Also provides some higher primitivesSimple non-convex polygoTexturing
They need to be downloaded
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
A fully installed Windows OpenGL development environment
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
For UNIX or UNIX-like operating systems
You need to point the compiler and linker to their location with the appropriate -I and -L options
-lglut -lGLU -lGL -lXmu -lX11 is typical
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
OpenGL basics
API conventions
bull10487081048708 Function names begin with gl and use mixed case glBegin glEnd glFrontFace
bull10487081048708 Constants begin with GL and use only upper case GL_TRIANGLES GL_BACK GL_LIGHT0
bull10487081048708 Types begin with GL and use only lower caseGLbyte GLubyte GLint GLfloat
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Setup an OpenGL project in Microsoft Visual Studio NET 2003
Create and manage drawing windows through GLUT
MainEventLoop
DisplayHandler
KeyboardHandler
MouseHandler
Event Driven Programming
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Clearing the window (Clear color buffer and depth buffer)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glClearDepth (10)
Specifying a Color glColor3f glClearColor() takes four parameters the fourth is alpha value
Forcing Completion of Drawing (glFlush() and glFinish())
glFlush() causes all OpenGL commands currently queued to be submitted to the hardware for execution
glFinish() with the addition that glFinish() will block until all commands submitted have been executed
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Hidden-Surface Removal (Using a depth buffer)
OpenGLglEnable(GL_DEPTH_TEST)glClear(GL_DEPTH_BUFFER_BIT)
DirectX presentParamsEnableAutoDepthStencil = true presentParamsAutoDepthStencilFormat = DepthFormatD16 deviceClear(ClearFlagsTarget | ClearFlagsZBuffer
ColorCornflowerBlue 10f 0)
In both cases there are more precision at the front of the depth buffer This will cause the problem of less precision in large scene
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Describing Points Lines and Polygons
Using glBegin() and glEnd() different from deviceBeginScene() and deviceEndScene() in
DirectX
Specifying Vertices 10487081048708 glVertex234sifd[v]() glVertex3i(Glint xGlint yGlint z) glVertex3fv(Glfloat v)
10487081048708 argument types ndash GL byte y GL short GL int GL float l GL double o ndash unsigned byte (ub) short ( us ) ) int (ui) 10487081048708 v indicates vector
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Drawing Primitives
OpenGL
glBegin(GLenum mode)
Primitive types 10487081048708 Points GL_POINTS 10487081048708 Lines GL_LINESGL_LINE_STRIPGL_LINE_LOOP 10487081048708 Triangles
GL_TRIANGLES GL_TRIANGLE_STRIP GL_TRIANGLE_FAN 10487081048708 Quadrilaterals and all other polygons
GL_QUADSGL_QUAD_STRIPGL_POLYGON 10487081048708Ordering of vertices (corners)
GL_CCW lt Default GL_CW
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Culling Polygon Faces
OpenGL glEnable(GL_CULL_FACE) glFrontFace(GLenum mode) Define the orientation of
front-facing polygons GL_CW and GL_CCW are accepted
DirectX Sounterclockwise cull mode is the default for Direct3D
deviceRenderStateCullMode = CullNone(Turn off culling) CullNone CullCounterClockwise CullClockwise
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
bullViewing and Transformations
Transformation Pipeline
Stages of vertex transformations
Objectcoords
ModelviewMatrix
ProjectionMatrix
ViewportMapping
Cameracoords
Normalizedcoords
Windowcoords
OpenGL has only two matrices MODELVIEW and PROJECTION glMatrixMode(GL_MODELVIEW)
glMatrixMode(GL_PROJECTION)
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
DirectX has three matrices World View Perspective deviceTransformWorld =deviceTransformProjection = deviceTransformView =
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Projection Transformations
1 Perspective Projection gluPerspective(GLdouble fovy GLdouble aspect
GLdouble zNear GLdouble zFar) ndash (DirectXdeviceTransformProjection = MatrixPerspectiveFovLH())
glFrustum(GLdouble left GLdouble right GLdouble bottom GLdouble top GLdouble near GLdouble far)
2 Orthographic Projection-- parallel viewing volume glOrtho(GLdouble left GLdouble right GLdouble
bottom GLdouble top GLdouble near GLdouble far)
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Viewing Transformations
gluLookAt (eyeX eyeY eyeZ centerX centerY centerZ upX upY upZ)
deviceTransformView = MatrixLookAtLH()
Modeling transformations
glTranslate() glRotate() and glScale() ---
deviceTransformWorld = MatrixRotationZ
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Multiply Current Matrix by a RotationTranslation or Scaling Matrix
NEW_MATRIX = CURRENT_MATRIX NEW_TRANSFORM
void glTranslatef(float x y z) void glRotatef(float angle x y z) void glScalef(float x y z)
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Order of Specification isOpposite Order of Operation bull Specification order in program code ndash First glRotatef(hellipR2hellip) ndash Second glRotatef(hellipR1) ndash Third glTranslatef( hellipThellip) bull Resulting composed transformation R2bullR1bullT bull Order in which operations are applied to vertices First T Second R1 Third R2
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Manipulating the Matrix Stacks glPushMatrix()-- It copies the current matrix and
adds the copy to the top of the stack glPopMatrix() which discards the top matrix on
the stack and uses this matrix as the current matrix
glLoadIdentity() command to clear the currently modifiable matrix for future transformation commands Typically you always call this command before specifying projection or viewing transformations
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Transformation PipelineHierarchical Modelling
glTranslatef(waistxwaistywaistz)glPushMatrix() glRotatef(rarxryrz) draw right armglPopMatrix()glPushMatrix() glRotatef(lalxlylz) draw left armglPopMatrix()
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Lights Three main types of light source in OpenGL
directional point and spot lights
To directional lights the 4th value is different GLfloat lightPosition[] = 07f 07f 07f 00f
To point lights GLfloat lightPosition[] = 07f 07f 07f 10f
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Defining Lights
glLightfv(GLenum light GLenum pname GLfloat param)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)
Parameters
GL_AMBIENT - RGBA ambient intensityGL_DIFFUSE - RGBA diffuse intensityGL_SPECULAR - RGBA specular intensityGL_POSITION ndash light position
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
MaterialsDefining Material Properties
glMaterialfv(GLenum face GLenum pname GLfloat param)
Faces
GL_FRONT GL_BACK GL_FRONT_AND_BACK
ParametersGL_AMBIENT GL_DIFFUSE GL_SPECULARGL_EMISSION GL_SHININESS
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Drawing ExampleAdding Lightingfloat lPos[] = 10101010glLightfv(GL_LIGHT0GL_POSITIONlPos)
float diffuse[] = 10000010glMaterialfv(GL_FRONTGL_DIFFUSEdiffuse)
glEnable(GL_LIGHTING)glEnable(GL_LIGHT0)glShadeModel(GL_SMOOTH) Setup camera Draw objects
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Blending
OpenGLAlpha values can be specified with glColor() the 4th value glBlendFunc(GLenum sfactor GLenum dfactor)glEnable(GL_BLEND)GL_ZERO GL_ONE GL_DST_COLOR
GL_SRC_COLOR GL_ONE_MINUS_DST_COLOR GL_ONE_MINUS_SRC_COLOR GL_SRC_ALPHAhelliphelliphellip
In DirectX for exampledeviceRenderStateAlphaBlendEnable = truedeviceRenderStateDestinationBlend = BlendOnedeviceRenderStateSourceBlend = BlendSourceAlphadeviceRenderStateBlendOperation=BlendOperationMax
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Texture mapping
Texture Coordinate System in OpenGL Texture Coordinate System in DirectX
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Steps to apply a texture
Create a texture object and specify a texture for that object (Loading a texture from file is not a built-in feature of OpenGLglauxlib is used here )
Generate texture namesvoid glGenTextures(GLsize nGLuint textures)
Bind texture objects to texture data amp parameters void glBindTexture(GLenum target GLuint textureName)
Indicate how the texture is to be applied to each pixelint gluBuild2DMipmaps(GLenum targetGLint componentsGLint widthGLint
heightGLenum formatGLenum typeconst void data)
Enable texture mapping glEnable(GL_TEXTURE_2D)
Draw the scene supplying both texture and geometric coordinates glTexCoord2f(00f 00f) glVertex3f(-10f -10f 10f)
Thank You
Thank You