SlideShare a Scribd company logo
1 of 24
OpenGL Texture Mapping
Objectives
• Introduce the OpenGL texture functions and options
2
Basic Stragegy
Three steps to applying a texture
1. specify the texture
• read or generate image
• assign to texture
• enable texturing
1. assign texture coordinates to vertices
• Proper mapping function is left to application
1. specify texture parameters
• wrapping, filtering
3
Texture Mapping
4
s
t
x
y
z
image
geometry display
Texture Example
• The texture (below) is a 256 x 256 image
that has been mapped to a rectangular
polygon which is viewed in perspective
5
Texture Mapping and the OpenGL
Pipeline
6
• Images and geometry flow through separate pipelines that join
during fragment processing
• “complex” textures do not affect geometric complexity
geometry pipelinevertices
pixel pipelineimage
fragment
processor
Specifying a Texture Image
•Define a texture image from an array of
texels (texture elements) in CPU memory
Glubyte my_texels[512][512];
•Define as any other pixel map
• Scanned image
• Generate by application code
•Enable texture mapping
• glEnable(GL_TEXTURE_2D)
• OpenGL supports 1-4 dimensional texture maps
7
Define Image as a Texture
glTexImage2D( target, level, components,
w, h, border, format, type, texels );
target: type of texture, e.g. GL_TEXTURE_2D
level: used for mipmapping (discussed later)
components: elements per texel
w, h: width and height of texels in pixels
border: used for smoothing (discussed later)
format and type: describe texels
texels: pointer to texel array
glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0,
GL_RGB, GL_UNSIGNED_BYTE, my_texels);
8
Converting A Texture Image
•OpenGL requires texture dimensions to be powers of
2
•If dimensions of image are not powers of 2
• gluScaleImage( format, w_in, h_in,
type_in, *data_in, w_out, h_out,
type_out, *data_out );
• data_in is source image
• data_out is for destination image
•Image interpolated and filtered during scaling
9
Mapping a Texture
•Based on parametric texture coordinates
• glTexCoord*() specified at each vertex
10
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
Typical Code
glBegin(GL_POLYGON);
glColor3f(r0, g0, b0); //if no shading used
glNormal3f(u0, v0, w0); // if shading used
glTexCoord2f(s0, t0);
glVertex3f(x0, y0, z0);
glColor3f(r1, g1, b1);
glNormal3f(u1, v1, w1);
glTexCoord2f(s1, t1);
glVertex3f(x1, y1, z1);
.
.
glEnd();
11
Note that we can use vertex arrays to increase efficiency
Interpolation
OpenGL uses interpolation to find proper texels from
specified texture coordinates
Can be distortions
12
good selection
of tex coordinates
poor selection
of tex coordinates
texture stretched
over trapezoid
showing effects of
bilinear interpolation
Texture Parameters
• OpenGL has a variety of parameters that determine how texture is
applied
• Wrapping parameters determine what happens if s and t are outside the
(0,1) range
• Filter modes allow us to use area averaging instead of point samples
• Mipmapping allows us to use textures at multiple resolutions
• Environment parameters determine how texture mapping interacts with
shading
13
Wrapping Mode
Clamping: if s,t > 1 use 1, if s,t <0 use 0
Wrapping: use s,t modulo 1
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_S, GL_CLAMP )
glTexParameteri( GL_TEXTURE_2D,
GL_TEXTURE_WRAP_T, GL_REPEAT )
14
texture
s
t
GL_CLAMP
wrapping
GL_REPEAT
wrapping
Magnification and Minification
15
Texture Polygon
Magnification Minification
PolygonTexture
More than one texel can cover a pixel (minification) or
more than one pixel can cover a texel (magnification)
Can use point sampling (nearest texel) or linear filtering
( 2 x 2 filter) to obtain texture values
Filter Modes
Modes determined by
• glTexParameteri( target, type, mode )
16
glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER,
GL_LINEAR);
Note that linear filtering requires a border of an
extra texel for filtering at edges (border = 1)
Mipmapped Textures
• Mipmapping allows for prefiltered texture maps of
decreasing resolutions
• Lessens interpolation errors for smaller textured
objects
• Declare mipmap level during texture definition
glTexImage2D( GL_TEXTURE_*D, level, … )
• GLU mipmap builder routines will build all the
textures from a given image
gluBuild*DMipmaps( … )
17
Example
point
sampling
18
mipmapped
point
sampling
mipmapped
linear
filtering
linear
filtering
Texture Functions
• Controls how texture is applied
• glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop,
param )
• GL_TEXTURE_ENV_MODE modes
• GL_MODULATE: modulates with computed shade
• GL_BLEND: blends with an environmental color
• GL_REPLACE: use only texture color
• GL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
GL_MODULATE);
• Set blend color with GL_TEXTURE_ENV_COLOR
19
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
20
Generating Texture Coordinates
•OpenGL can generate texture coordinates
automatically
glTexGen{ifd}[v]()
•specify a plane
• generate texture coordinates based upon distance from the
plane
•generation modes
• GL_OBJECT_LINEAR
• GL_EYE_LINEAR
• GL_SPHERE_MAP (used for environmental maps)
21
Texture Objects
•Texture is part of the OpenGL state
• If we have different textures for different objects,
OpenGL will be moving large amounts data from
processor memory to texture memory
•Recent versions of OpenGL have texture objects
• one image per texture object
• Texture memory can hold multiple texture objects
22
Applying Textures II
1. specify textures in texture objects
2. set texture filter
3. set texture function
4. set texture wrap mode
5. set optional perspective correction hint
6. bind texture object
7. enable texturing
8. supply texture coordinates for vertex
• coordinates can also be generated
23
Other Texture Features
• Environment Maps
• Start with image of environment through a wide angle lens
• Can be either a real scanned image or an image created in OpenGL
• Use this texture to generate a spherical map
• Use automatic texture coordinate generation
• Multitexturing
• Apply a sequence of textures through cascaded texture units
24

More Related Content

What's hot

Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGLGary Yeh
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmrajivagarwal23dei
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalPunyajoy Saha
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removalAnkit Garg
 
Texture mapping
Texture mapping Texture mapping
Texture mapping wahab13
 
Windows to viewport transformation
Windows to viewport transformationWindows to viewport transformation
Windows to viewport transformationPrashant Singh
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics FundamentalsMuhammed Afsal Villan
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9fungfung Chen
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projectionPooja Dixit
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsJoseph Charles
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and QtICS
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphicssabbirantor
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer GraphicsSanu Philip
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityMark Kilgard
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Sharath Raj
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer GraphicsUniversity of Potsdam
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)RohitK71
 

What's hot (20)

Introduction of openGL
Introduction  of openGLIntroduction  of openGL
Introduction of openGL
 
hidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithmhidden surface elimination using z buffer algorithm
hidden surface elimination using z buffer algorithm
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Hidden surface removal
Hidden surface removalHidden surface removal
Hidden surface removal
 
Texture mapping
Texture mapping Texture mapping
Texture mapping
 
Windows to viewport transformation
Windows to viewport transformationWindows to viewport transformation
Windows to viewport transformation
 
3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals3D Graphics : Computer Graphics Fundamentals
3D Graphics : Computer Graphics Fundamentals
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9
 
3 d viewing projection
3 d viewing  projection3 d viewing  projection
3 d viewing projection
 
Computer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methodsComputer Graphics: Visible surface detection methods
Computer Graphics: Visible surface detection methods
 
OpenGL Introduction
OpenGL IntroductionOpenGL Introduction
OpenGL Introduction
 
State of the Art OpenGL and Qt
State of the Art OpenGL and QtState of the Art OpenGL and Qt
State of the Art OpenGL and Qt
 
3D Transformation in Computer Graphics
3D Transformation in Computer Graphics3D Transformation in Computer Graphics
3D Transformation in Computer Graphics
 
OpenGL basics
OpenGL basicsOpenGL basics
OpenGL basics
 
Projection In Computer Graphics
Projection In Computer GraphicsProjection In Computer Graphics
Projection In Computer Graphics
 
NVIDIA's OpenGL Functionality
NVIDIA's OpenGL FunctionalityNVIDIA's OpenGL Functionality
NVIDIA's OpenGL Functionality
 
Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL Computer Graphics Project Report on Sinking Ship using OpenGL
Computer Graphics Project Report on Sinking Ship using OpenGL
 
Polygon mesh
Polygon  meshPolygon  mesh
Polygon mesh
 
Halftoning in Computer Graphics
Halftoning  in Computer GraphicsHalftoning  in Computer Graphics
Halftoning in Computer Graphics
 
Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)Computer graphics curves and surfaces (1)
Computer graphics curves and surfaces (1)
 

Similar to OpenGL Texture Mapping in 40 Characters

Opengl texturing
Opengl texturingOpengl texturing
Opengl texturingSardar Alam
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-TexturingMohammad Shaker
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel UpdatingMark Kilgard
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3DMark Kilgard
 
CGChapter 3.pptx
CGChapter 3.pptxCGChapter 3.pptx
CGChapter 3.pptxYazanAlbilleh
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksJinTaek Seo
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programmingMohammed Romi
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2Sardar Alam
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).pptHIMANKMISHRA2
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.pptHIMANKMISHRA2
 
OpenGL Transformations
OpenGL TransformationsOpenGL Transformations
OpenGL TransformationsSyed Zaid Irshad
 
Mask R-CNN
Mask R-CNNMask R-CNN
Mask R-CNNChanuk Lim
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3elnaqah
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGLSyed Zaid Irshad
 
ModuleII.ppt
ModuleII.pptModuleII.ppt
ModuleII.pptSKILL2021
 

Similar to OpenGL Texture Mapping in 40 Characters (20)

Opengl texturing
Opengl texturingOpengl texturing
Opengl texturing
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
 
CS 354 Pixel Updating
CS 354 Pixel UpdatingCS 354 Pixel Updating
CS 354 Pixel Updating
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3D
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
 
CGChapter 3.pptx
CGChapter 3.pptxCGChapter 3.pptx
CGChapter 3.pptx
 
GLSL
GLSLGLSL
GLSL
 
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeksBeginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
Beginning direct3d gameprogramming09_shaderprogramming_20160505_jintaeks
 
Chapter02 graphics-programming
Chapter02 graphics-programmingChapter02 graphics-programming
Chapter02 graphics-programming
 
Open gl tips
Open gl tipsOpen gl tips
Open gl tips
 
Shading in OpenGL
Shading in OpenGLShading in OpenGL
Shading in OpenGL
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 
openGL basics for sample program (1).ppt
openGL basics for sample program (1).pptopenGL basics for sample program (1).ppt
openGL basics for sample program (1).ppt
 
openGL basics for sample program.ppt
openGL basics for sample program.pptopenGL basics for sample program.ppt
openGL basics for sample program.ppt
 
OpenGL Transformations
OpenGL TransformationsOpenGL Transformations
OpenGL Transformations
 
Mask R-CNN
Mask R-CNNMask R-CNN
Mask R-CNN
 
Opengl lec 3
Opengl lec 3Opengl lec 3
Opengl lec 3
 
Programming with OpenGL
Programming with OpenGLProgramming with OpenGL
Programming with OpenGL
 
ModuleII.ppt
ModuleII.pptModuleII.ppt
ModuleII.ppt
 
ModuleII.ppt
ModuleII.pptModuleII.ppt
ModuleII.ppt
 

More from Syed Zaid Irshad

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdfSyed Zaid Irshad
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionSyed Zaid Irshad
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxSyed Zaid Irshad
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in ComputingSyed Zaid Irshad
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xiSyed Zaid Irshad
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xiiSyed Zaid Irshad
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to DatabaseSyed Zaid Irshad
 
Computer Programming
Computer ProgrammingComputer Programming
Computer ProgrammingSyed Zaid Irshad
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionSyed Zaid Irshad
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the LawSyed Zaid Irshad
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer ArchitectureSyed Zaid Irshad
 
Information Networks
Information NetworksInformation Networks
Information NetworksSyed Zaid Irshad
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information TechnologySyed Zaid Irshad
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year BookSyed Zaid Irshad
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operatorsSyed Zaid Irshad
 

More from Syed Zaid Irshad (20)

Operating System.pdf
Operating System.pdfOperating System.pdf
Operating System.pdf
 
DBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_SolutionDBMS_Lab_Manual_&_Solution
DBMS_Lab_Manual_&_Solution
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Design and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptxDesign and Analysis of Algorithms.pptx
Design and Analysis of Algorithms.pptx
 
Professional Issues in Computing
Professional Issues in ComputingProfessional Issues in Computing
Professional Issues in Computing
 
Reduce course notes class xi
Reduce course notes class xiReduce course notes class xi
Reduce course notes class xi
 
Reduce course notes class xii
Reduce course notes class xiiReduce course notes class xii
Reduce course notes class xii
 
Introduction to Database
Introduction to DatabaseIntroduction to Database
Introduction to Database
 
C Language
C LanguageC Language
C Language
 
Flowchart
FlowchartFlowchart
Flowchart
 
Algorithm Pseudo
Algorithm PseudoAlgorithm Pseudo
Algorithm Pseudo
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
ICS 2nd Year Book Introduction
ICS 2nd Year Book IntroductionICS 2nd Year Book Introduction
ICS 2nd Year Book Introduction
 
Security, Copyright and the Law
Security, Copyright and the LawSecurity, Copyright and the Law
Security, Copyright and the Law
 
Computer Architecture
Computer ArchitectureComputer Architecture
Computer Architecture
 
Data Communication
Data CommunicationData Communication
Data Communication
 
Information Networks
Information NetworksInformation Networks
Information Networks
 
Basic Concept of Information Technology
Basic Concept of Information TechnologyBasic Concept of Information Technology
Basic Concept of Information Technology
 
Introduction to ICS 1st Year Book
Introduction to ICS 1st Year BookIntroduction to ICS 1st Year Book
Introduction to ICS 1st Year Book
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 

Recently uploaded

Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 

Recently uploaded (20)

Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

OpenGL Texture Mapping in 40 Characters

  • 2. Objectives • Introduce the OpenGL texture functions and options 2
  • 3. Basic Stragegy Three steps to applying a texture 1. specify the texture • read or generate image • assign to texture • enable texturing 1. assign texture coordinates to vertices • Proper mapping function is left to application 1. specify texture parameters • wrapping, filtering 3
  • 5. Texture Example • The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective 5
  • 6. Texture Mapping and the OpenGL Pipeline 6 • Images and geometry flow through separate pipelines that join during fragment processing • “complex” textures do not affect geometric complexity geometry pipelinevertices pixel pipelineimage fragment processor
  • 7. Specifying a Texture Image •Define a texture image from an array of texels (texture elements) in CPU memory Glubyte my_texels[512][512]; •Define as any other pixel map • Scanned image • Generate by application code •Enable texture mapping • glEnable(GL_TEXTURE_2D) • OpenGL supports 1-4 dimensional texture maps 7
  • 8. Define Image as a Texture glTexImage2D( target, level, components, w, h, border, format, type, texels ); target: type of texture, e.g. GL_TEXTURE_2D level: used for mipmapping (discussed later) components: elements per texel w, h: width and height of texels in pixels border: used for smoothing (discussed later) format and type: describe texels texels: pointer to texel array glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels); 8
  • 9. Converting A Texture Image •OpenGL requires texture dimensions to be powers of 2 •If dimensions of image are not powers of 2 • gluScaleImage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out ); • data_in is source image • data_out is for destination image •Image interpolated and filtered during scaling 9
  • 10. Mapping a Texture •Based on parametric texture coordinates • glTexCoord*() specified at each vertex 10 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
  • 11. Typical Code glBegin(GL_POLYGON); glColor3f(r0, g0, b0); //if no shading used glNormal3f(u0, v0, w0); // if shading used glTexCoord2f(s0, t0); glVertex3f(x0, y0, z0); glColor3f(r1, g1, b1); glNormal3f(u1, v1, w1); glTexCoord2f(s1, t1); glVertex3f(x1, y1, z1); . . glEnd(); 11 Note that we can use vertex arrays to increase efficiency
  • 12. Interpolation OpenGL uses interpolation to find proper texels from specified texture coordinates Can be distortions 12 good selection of tex coordinates poor selection of tex coordinates texture stretched over trapezoid showing effects of bilinear interpolation
  • 13. Texture Parameters • OpenGL has a variety of parameters that determine how texture is applied • Wrapping parameters determine what happens if s and t are outside the (0,1) range • Filter modes allow us to use area averaging instead of point samples • Mipmapping allows us to use textures at multiple resolutions • Environment parameters determine how texture mapping interacts with shading 13
  • 14. Wrapping Mode Clamping: if s,t > 1 use 1, if s,t <0 use 0 Wrapping: use s,t modulo 1 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) 14 texture s t GL_CLAMP wrapping GL_REPEAT wrapping
  • 15. Magnification and Minification 15 Texture Polygon Magnification Minification PolygonTexture More than one texel can cover a pixel (minification) or more than one pixel can cover a texel (magnification) Can use point sampling (nearest texel) or linear filtering ( 2 x 2 filter) to obtain texture values
  • 16. Filter Modes Modes determined by • glTexParameteri( target, type, mode ) 16 glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER, GL_LINEAR); Note that linear filtering requires a border of an extra texel for filtering at edges (border = 1)
  • 17. Mipmapped Textures • Mipmapping allows for prefiltered texture maps of decreasing resolutions • Lessens interpolation errors for smaller textured objects • Declare mipmap level during texture definition glTexImage2D( GL_TEXTURE_*D, level, … ) • GLU mipmap builder routines will build all the textures from a given image gluBuild*DMipmaps( … ) 17
  • 19. Texture Functions • Controls how texture is applied • glTexEnv{fi}[v]( GL_TEXTURE_ENV, prop, param ) • GL_TEXTURE_ENV_MODE modes • GL_MODULATE: modulates with computed shade • GL_BLEND: blends with an environmental color • GL_REPLACE: use only texture color • GL(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); • Set blend color with GL_TEXTURE_ENV_COLOR 19
  • 20. 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 20
  • 21. Generating Texture Coordinates •OpenGL can generate texture coordinates automatically glTexGen{ifd}[v]() •specify a plane • generate texture coordinates based upon distance from the plane •generation modes • GL_OBJECT_LINEAR • GL_EYE_LINEAR • GL_SPHERE_MAP (used for environmental maps) 21
  • 22. Texture Objects •Texture is part of the OpenGL state • If we have different textures for different objects, OpenGL will be moving large amounts data from processor memory to texture memory •Recent versions of OpenGL have texture objects • one image per texture object • Texture memory can hold multiple texture objects 22
  • 23. Applying Textures II 1. specify textures in texture objects 2. set texture filter 3. set texture function 4. set texture wrap mode 5. set optional perspective correction hint 6. bind texture object 7. enable texturing 8. supply texture coordinates for vertex • coordinates can also be generated 23
  • 24. Other Texture Features • Environment Maps • Start with image of environment through a wide angle lens • Can be either a real scanned image or an image created in OpenGL • Use this texture to generate a spherical map • Use automatic texture coordinate generation • Multitexturing • Apply a sequence of textures through cascaded texture units 24

Editor's Notes

  1. If