SlideShare a Scribd company logo
CSC 307 1.0
Graphics Programming
Budditha Hettige
Department of Statistics and Computer Science
Graphics Programming
Texture Mapping
2Budditha Hettige
3
• Apply a 1D, 2D, or 3D image to geometric
primitives
• Uses of Texturing
– simulating materials
– reducing geometric complexity
– image warping
– reflections
Texture
Mapping CPUCPU DLDL
Poly.Poly.
Per
Vertex
Per
Vertex
RasterRaster FragFrag FBFB
PixelPixel
TextureTexture
Budditha Hettige
4
Texture Mapping
s
t
x
y
z
image
geometry screen
Budditha Hettige
5
Texture Mapping and the OpenGL
Pipeline
geometry pipelinevertices
pixel pipeline
image
rasterizer
• Images and geometry flow through
separate pipelines that join at the
rasterizer
– “complex” textures do not affect geometric
complexity
Budditha Hettige
6
Texture Example
• The texture (below) is a
256 x 256 image that has been
mapped to a rectangular
polygon which is viewed in
perspective
Budditha Hettige
7
Applying Textures I
• Three steps
 specify texture
• read or generate image
• assign to texture
• enable texturing
 assign texture coordinates to vertices
 specify texture parameters
• wrapping, filtering
Budditha Hettige
8
Applying Textures II
– specify textures in texture objects
– set texture filter
– set texture function
– set texture wrap mode
– set optional perspective correction hint
– bind texture object
– enable texturing
– supply texture coordinates for vertex
• coordinates can also be generated
Budditha Hettige
9
Texture Objects
• Like display lists for texture images
– one image per texture object
– may be shared by several graphics contexts
• Generate texture names
glGenTextures( n, *texIds );
Budditha Hettige
10
Texture Objects (cont.)
• Create texture objects with texture data and
state
glBindTexture( target, id );
• Bind textures before using
glBindTexture( target, id );
Budditha Hettige
11
• Define a texture image from an array of
texels in CPU memory
• glTexImage2D( target, level, components,
w, h, border, format, type, *texels );
– dimensions of image must be powers of 2
• Texel colors are processed by pixel
pipeline
– pixel scales, biases and lookups can be
done
Specify Texture
Image CPUCPU DLDL
Poly.Poly.
Per
Vertex
Per
Vertex
RasterRaster FragFrag FBFB
PixelPixel
TextureTexture
Budditha Hettige
12
Converting A Texture Image
• If dimensions of image are not power of 2
• gluScaleImage( format, w_in, h_in,
type_in, *data_in, w_out, h_out,
type_out, *data_out );
– *_in is for source image
– *_out is for destination image
• Image interpolated and filtered during scaling
Budditha Hettige
13
Specifying a Texture:
Other Methods
• Use frame buffer as source of texture image
– uses current buffer as source image
glCopyTexImage1D(...)
glCopyTexImage2D(...)
• Modify part of a defined texture
glTexSubImage1D(...)
glTexSubImage2D(...)
glTexSubImage3D(...)
• Do both with glCopyTexSubImage2D(...), etc.
Budditha Hettige
14
• Based on parametric texture coordinates
• glTexCoord*() specified at each vertex
s
t
1, 1
0, 1
0, 0 1, 0
(s, t) = (0.2, 0.8)
(0.4, 0.2)
(0.8, 0.4)
A
B C
a
b
c
Texture Space Object Space
Mapping a
Texture CPUCPU DLDL
Poly.Poly.
Per
Vertex
Per
Vertex
RasterRaster FragFrag FBFB
PixelPixel
TextureTexture
Budditha Hettige
15
Generating Texture Coordinates
• Automatically generate texture coords
glTexGen{ifd}[v]()
• specify a plane
– generate texture coordinates based upon distance from
plane
• generation modes
– GL_OBJECT_LINEAR
– GL_EYE_LINEAR
– GL_SPHERE_MAP
0 DCzByAx
Budditha Hettige
16
Tutorial: Texture
Budditha Hettige
17
• Filter Modes
– minification or magnification
– special mipmap minification filters
• Wrap Modes
– clamping or repeating
• Texture Functions
– how to mix primitive’s color with texture’s color
• blend, modulate or replace texels
Texture Application Methods
Budditha Hettige
18
Filter Modes
Texture Polygon
Magnification Minification
PolygonTexture
Example:
glTexParameteri( target, type, mode );
Budditha Hettige
19
Mipmapped Textures
• Mipmap allows for prefiltered texture maps of
decreasing resolutions
• Lessens interpolation errors for smaller textured objects
• Declare mipmap level during texture definition
glTexImage*D( GL_TEXTURE_*D, level, … )
• GLU mipmap builder routines
gluBuild*DMipmaps( … )
• OpenGL 1.2 introduces advanced LOD controls
Budditha Hettige
20
Wrapping Mode
• Example:
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_CLAMP )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_REPEAT )
texture
s
t
GL_CLAMP
wrapping
GL_REPEAT
wrapping
Budditha Hettige
21
Texture Functions
• Controls how texture is applied
• glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop,
param )
• GL_TEXTURE_ENV_MODE modes
– GL_MODULATE
– GL_BLEND
– GL_REPLACE
• Set blend color with
GL_TEXTURE_ENV_COLOR
Budditha Hettige
22
Perspective Correction Hint
• Texture coordinate and color interpolation
– either linearly in screen space
– or using depth/perspective values (slower)
• Noticeable for polygons “on edge”
• glHint( GL_PERSPECTIVE_CORRECTION_HINT, hint )
where hint is one of
• GL_DONT_CARE
• GL_NICEST
• GL_FASTEST
Budditha Hettige
23
Is There Room for a Texture?
• Query largest dimension of texture image
– typically largest square texture
– doesn’t consider internal format size
• glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size )
• Texture proxy
– will memory accommodate requested texture size?
– no image specified; placeholder
– if texture won’t fit, texture state variables set to 0
• doesn’t know about other textures
• only considers whether this one texture will fit all of memory
Budditha Hettige
24
Texture Residency
• Working set of textures
– high-performance, usually hardware accelerated
– textures must be in texture objects
– a texture in the working set is resident
– for residency of current texture, check GL_TEXTURE_RESIDENT
state
• If too many textures, not all are resident
– can set priority to have some kicked out first
– establish 0.0 to 1.0 priorities for texture objects
Budditha Hettige
Example
25Budditha Hettige

More Related Content

PDF
Drawing Fonts
DOCX
Project004
PDF
E-Learning: Introduction to GPGPU
DOCX
Resize image vb.net
PPTX
DCT image compression
DOCX
Zooming an image in visual basic
PDF
Ultra Fast SOM using CUDA
PDF
Digital Image Compression using Hybrid Transform with Kekre Transform and Oth...
Drawing Fonts
Project004
E-Learning: Introduction to GPGPU
Resize image vb.net
DCT image compression
Zooming an image in visual basic
Ultra Fast SOM using CUDA
Digital Image Compression using Hybrid Transform with Kekre Transform and Oth...

What's hot (20)

PDF
Foss4 g 2017-kansai-ryoo-kim
PPT
OpenGL Texture Mapping
PPTX
Texture mapping in_opengl
PPT
Dital Image Processing (Lab 2+3+4)
DOC
Simple Matlab tutorial using matlab inbuilt commands
PPTX
Interactive Rendering and Stylization of Transportation Networks Using Distan...
PPTX
Digital Image Processing (Lab 05)
PPT
Image processing using matlab
PPTX
Digital Image Processing (Lab 09 and 10)
PDF
2013.10.24 big datavisualization
PPT
Matlab
PPT
igarss2011.ppt
PDF
IITB Poster. Benchmarking GPU-based Acceleration of Spark in ML Workload usin...
PDF
Histogram Operation in Image Processing
PDF
cuSTINGER: Supporting Dynamic Graph Aigorithms for GPUs : NOTES
PDF
cuSTINGER: Supporting Dynamic Graph Aigorithms for GPUs (NOTES)
PDF
3Dtexture_doc_rep
PPTX
GRPHICS01 - Introduction to 3D Graphics
PPT
fundamentals of Computer graphics(Computer graphics tutorials)
PPTX
Digital Image Processing (Lab 06)
Foss4 g 2017-kansai-ryoo-kim
OpenGL Texture Mapping
Texture mapping in_opengl
Dital Image Processing (Lab 2+3+4)
Simple Matlab tutorial using matlab inbuilt commands
Interactive Rendering and Stylization of Transportation Networks Using Distan...
Digital Image Processing (Lab 05)
Image processing using matlab
Digital Image Processing (Lab 09 and 10)
2013.10.24 big datavisualization
Matlab
igarss2011.ppt
IITB Poster. Benchmarking GPU-based Acceleration of Spark in ML Workload usin...
Histogram Operation in Image Processing
cuSTINGER: Supporting Dynamic Graph Aigorithms for GPUs : NOTES
cuSTINGER: Supporting Dynamic Graph Aigorithms for GPUs (NOTES)
3Dtexture_doc_rep
GRPHICS01 - Introduction to 3D Graphics
fundamentals of Computer graphics(Computer graphics tutorials)
Digital Image Processing (Lab 06)
Ad

Similar to Texture Mapping (20)

PDF
OpenGL L05-Texturing
PPT
CS 354 Texture Mapping
PDF
201707 SER332 Lecture 21
KEY
8thlightu3
PPT
Topic 6 Graphic Transformation and Viewing.ppt
PPTX
GFX Part 4 - Introduction to Texturing in OpenGL ES
PDF
6 texture mapping computer graphics
PPTX
Opengl texturing
PDF
Open gl
PPTX
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
PPT
Anatomy of a Texture Fetch
PDF
iOS Visual F/X Using GLSL
PDF
reflective bump environment mappings.pdf
PPT
OpenGL ES based UI Development on TI Platforms
PDF
The Ring programming language version 1.5.4 book - Part 113 of 185
PDF
PPT
OpenGL for 2015
PDF
OpenGL L03-Utilities
PDF
Smedberg niklas bringing_aaa_graphics
PPTX
Approaching zero driver overhead
OpenGL L05-Texturing
CS 354 Texture Mapping
201707 SER332 Lecture 21
8thlightu3
Topic 6 Graphic Transformation and Viewing.ppt
GFX Part 4 - Introduction to Texturing in OpenGL ES
6 texture mapping computer graphics
Opengl texturing
Open gl
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Anatomy of a Texture Fetch
iOS Visual F/X Using GLSL
reflective bump environment mappings.pdf
OpenGL ES based UI Development on TI Platforms
The Ring programming language version 1.5.4 book - Part 113 of 185
OpenGL for 2015
OpenGL L03-Utilities
Smedberg niklas bringing_aaa_graphics
Approaching zero driver overhead
Ad

More from Budditha Hettige (20)

PDF
Algorithm analysis
PDF
PDF
Link List
PDF
PDF
Data Structures 01
PDF
PDF
OpenGL 3D Drawing
PDF
2D Drawing
PDF
Graphics Programming OpenGL & GLUT in Code::Blocks
PDF
Introduction to Computer Graphics
PPTX
Computer System Architecture Lecture Note 9 IO fundamentals
PPTX
Computer System Architecture Lecture Note 8.1 primary Memory
PPTX
Computer System Architecture Lecture Note 8.2 Cache Memory
PPTX
Computer System Architecture Lecture Note 7 addressing
PPT
Computer System Architecture Lecture Note 6: hardware performance
PPT
Computer System Architecture Lecture Note 5: microprocessor technology
PPT
Computer System Architecture Lecture Note 3: computer architecture
PPT
Computer System Architecture Lecture Note 2: History
PPT
Computer System Architecture Lecture Note 1: introduction
Algorithm analysis
Link List
Data Structures 01
OpenGL 3D Drawing
2D Drawing
Graphics Programming OpenGL & GLUT in Code::Blocks
Introduction to Computer Graphics
Computer System Architecture Lecture Note 9 IO fundamentals
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.2 Cache Memory
Computer System Architecture Lecture Note 7 addressing
Computer System Architecture Lecture Note 6: hardware performance
Computer System Architecture Lecture Note 5: microprocessor technology
Computer System Architecture Lecture Note 3: computer architecture
Computer System Architecture Lecture Note 2: History
Computer System Architecture Lecture Note 1: introduction

Recently uploaded (20)

PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Pre independence Education in Inndia.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
master seminar digital applications in india
Week 4 Term 3 Study Techniques revisited.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Final Presentation General Medicine 03-08-2024.pptx
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Renaissance Architecture: A Journey from Faith to Humanism
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
human mycosis Human fungal infections are called human mycosis..pptx
Cell Structure & Organelles in detailed.
TR - Agricultural Crops Production NC III.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pre independence Education in Inndia.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
master seminar digital applications in india

Texture Mapping

  • 1. CSC 307 1.0 Graphics Programming Budditha Hettige Department of Statistics and Computer Science
  • 3. 3 • Apply a 1D, 2D, or 3D image to geometric primitives • Uses of Texturing – simulating materials – reducing geometric complexity – image warping – reflections Texture Mapping CPUCPU DLDL Poly.Poly. Per Vertex Per Vertex RasterRaster FragFrag FBFB PixelPixel TextureTexture Budditha Hettige
  • 5. 5 Texture Mapping and the OpenGL Pipeline geometry pipelinevertices pixel pipeline image rasterizer • Images and geometry flow through separate pipelines that join at the rasterizer – “complex” textures do not affect geometric complexity Budditha Hettige
  • 6. 6 Texture Example • The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective Budditha Hettige
  • 7. 7 Applying Textures I • Three steps  specify texture • read or generate image • assign to texture • enable texturing  assign texture coordinates to vertices  specify texture parameters • wrapping, filtering Budditha Hettige
  • 8. 8 Applying Textures II – specify textures in texture objects – set texture filter – set texture function – set texture wrap mode – set optional perspective correction hint – bind texture object – enable texturing – supply texture coordinates for vertex • coordinates can also be generated Budditha Hettige
  • 9. 9 Texture Objects • Like display lists for texture images – one image per texture object – may be shared by several graphics contexts • Generate texture names glGenTextures( n, *texIds ); Budditha Hettige
  • 10. 10 Texture Objects (cont.) • Create texture objects with texture data and state glBindTexture( target, id ); • Bind textures before using glBindTexture( target, id ); Budditha Hettige
  • 11. 11 • Define a texture image from an array of texels in CPU memory • glTexImage2D( target, level, components, w, h, border, format, type, *texels ); – dimensions of image must be powers of 2 • Texel colors are processed by pixel pipeline – pixel scales, biases and lookups can be done Specify Texture Image CPUCPU DLDL Poly.Poly. Per Vertex Per Vertex RasterRaster FragFrag FBFB PixelPixel TextureTexture Budditha Hettige
  • 12. 12 Converting A Texture Image • If dimensions of image are not power of 2 • gluScaleImage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out ); – *_in is for source image – *_out is for destination image • Image interpolated and filtered during scaling Budditha Hettige
  • 13. 13 Specifying a Texture: Other Methods • Use frame buffer as source of texture image – uses current buffer as source image glCopyTexImage1D(...) glCopyTexImage2D(...) • Modify part of a defined texture glTexSubImage1D(...) glTexSubImage2D(...) glTexSubImage3D(...) • Do both with glCopyTexSubImage2D(...), etc. Budditha Hettige
  • 14. 14 • Based on parametric texture coordinates • glTexCoord*() specified at each vertex s t 1, 1 0, 1 0, 0 1, 0 (s, t) = (0.2, 0.8) (0.4, 0.2) (0.8, 0.4) A B C a b c Texture Space Object Space Mapping a Texture CPUCPU DLDL Poly.Poly. Per Vertex Per Vertex RasterRaster FragFrag FBFB PixelPixel TextureTexture Budditha Hettige
  • 15. 15 Generating Texture Coordinates • Automatically generate texture coords glTexGen{ifd}[v]() • specify a plane – generate texture coordinates based upon distance from plane • generation modes – GL_OBJECT_LINEAR – GL_EYE_LINEAR – GL_SPHERE_MAP 0 DCzByAx Budditha Hettige
  • 17. 17 • Filter Modes – minification or magnification – special mipmap minification filters • Wrap Modes – clamping or repeating • Texture Functions – how to mix primitive’s color with texture’s color • blend, modulate or replace texels Texture Application Methods Budditha Hettige
  • 18. 18 Filter Modes Texture Polygon Magnification Minification PolygonTexture Example: glTexParameteri( target, type, mode ); Budditha Hettige
  • 19. 19 Mipmapped Textures • Mipmap allows for prefiltered texture maps of decreasing resolutions • Lessens interpolation errors for smaller textured objects • Declare mipmap level during texture definition glTexImage*D( GL_TEXTURE_*D, level, … ) • GLU mipmap builder routines gluBuild*DMipmaps( … ) • OpenGL 1.2 introduces advanced LOD controls Budditha Hettige
  • 20. 20 Wrapping Mode • Example: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) texture s t GL_CLAMP wrapping GL_REPEAT wrapping Budditha Hettige
  • 21. 21 Texture Functions • Controls how texture is applied • glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param ) • GL_TEXTURE_ENV_MODE modes – GL_MODULATE – GL_BLEND – GL_REPLACE • Set blend color with GL_TEXTURE_ENV_COLOR Budditha Hettige
  • 22. 22 Perspective Correction Hint • Texture coordinate and color interpolation – either linearly in screen space – or using depth/perspective values (slower) • Noticeable for polygons “on edge” • glHint( GL_PERSPECTIVE_CORRECTION_HINT, hint ) where hint is one of • GL_DONT_CARE • GL_NICEST • GL_FASTEST Budditha Hettige
  • 23. 23 Is There Room for a Texture? • Query largest dimension of texture image – typically largest square texture – doesn’t consider internal format size • glGetIntegerv( GL_MAX_TEXTURE_SIZE, &size ) • Texture proxy – will memory accommodate requested texture size? – no image specified; placeholder – if texture won’t fit, texture state variables set to 0 • doesn’t know about other textures • only considers whether this one texture will fit all of memory Budditha Hettige
  • 24. 24 Texture Residency • Working set of textures – high-performance, usually hardware accelerated – textures must be in texture objects – a texture in the working set is resident – for residency of current texture, check GL_TEXTURE_RESIDENT state • If too many textures, not all are resident – can set priority to have some kicked out first – establish 0.0 to 1.0 priorities for texture objects Budditha Hettige