31
OpenGL Basics Compared to DirectX By Jin Li Jan 20th, 2005 Introduction to Computer Graphics

OpenGL Basics Compared to DirectX

  • Upload
    libra

  • View
    65

  • Download
    0

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

Page 1: OpenGL Basics Compared to DirectX

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

Page 2: OpenGL Basics Compared to DirectX

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

Page 3: OpenGL Basics Compared to DirectX

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

Page 4: OpenGL Basics Compared to DirectX

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

Page 5: OpenGL Basics Compared to DirectX

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

Page 6: OpenGL Basics Compared to DirectX

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

Page 7: OpenGL Basics Compared to DirectX

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

Page 8: OpenGL Basics Compared to DirectX

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

Page 9: OpenGL Basics Compared to DirectX

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

Page 10: OpenGL Basics Compared to DirectX

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

Page 11: OpenGL Basics Compared to DirectX

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

Page 12: OpenGL Basics Compared to DirectX

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

Page 13: OpenGL Basics Compared to DirectX

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

Page 14: OpenGL Basics Compared to DirectX

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

Page 15: OpenGL Basics Compared to DirectX

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

Page 16: OpenGL Basics Compared to DirectX

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

Page 17: OpenGL Basics Compared to DirectX

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

Page 18: OpenGL Basics Compared to DirectX

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

Page 19: OpenGL Basics Compared to DirectX

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

Page 20: OpenGL Basics Compared to DirectX

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

Page 21: OpenGL Basics Compared to DirectX

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

Page 22: OpenGL Basics Compared to DirectX

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

Page 23: OpenGL Basics Compared to DirectX

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

Page 24: OpenGL Basics Compared to DirectX

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

Page 25: OpenGL Basics Compared to DirectX

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

Page 26: OpenGL Basics Compared to DirectX

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

Page 27: OpenGL Basics Compared to DirectX

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

Page 28: OpenGL Basics Compared to DirectX

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

Page 29: OpenGL Basics Compared to DirectX

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

Page 30: OpenGL Basics Compared to 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

Page 31: OpenGL Basics Compared to DirectX

Thank You