SlideShare a Scribd company logo
OpenGL Texturing
When we apply image data to a geometric primitive, 
we call this a texture or texture map. 
shows the dramatic difference that can be achieved 
by texture mapping geometry. 
The cube on the left is a lit and shaded featureless 
surface, whereas the cube on the right shows a 
richness in detail that can be reasonably achieved 
only with texture mapping.
Loading Textures 
Using GLuint we create a variable for the texture, called 
‘texture’, but you can call it. 
In the ‘display’ function we first set the variable ‘texture’ 
to the actual loaded image using: 
texture = LoadTexture( “texture.raw”, 256, 256 ); 
where 256, 256 is the width and the height of the file 
respectively. 
Then we enable the 2D Texturing, this is done with: 
glEnable( GL_TEXTURE_2D ); 
and bind the texture with: 
glBindTexture( GL_TEXTURE_2D, texture ); 
then after drawing everything we need with the texture, 
we clear it to save system resources.
Section 1: The loading of the texture: 
GLuint LoadTexture( const char * filename, int width, int 
height ) 
{ 
GLuint texture; 
unsigned char * data; 
FILE * file; 
The following code will read in our RAW file 
file = fopen( filename, “rb” ); We need to open our file 
if ( file == NULL ) return 0; If our file is empty, set our 
texture to empty 
data = (unsigned char *)malloc( width * height * 3 ); 
assign the nessecary memory for the texture 
fread( data, width * height * 3, 1, file ); read in our file 
fclose( file ); close our file, no point leaving it open
glGenTextures( 1, &texture ); then we need to tell 
OpenGL that we are generating a texture 
glBindTexture( GL_TEXTURE_2D, texture ); now 
we bind the texture that we are working with 
glTexEnvf( GL_TEXTURE_ENV, 
GL_TEXTURE_ENV_MODE, GL_MODULATE ); set 
texture environment parameters 
The parameter GL_MODULATE will blend the 
texture with whatever is underneath, setting it 
to GL_DECAL 
will tell the texture to replace whatever is on the 
object.
here we are setting what textures to use and when. The 
MIN filter is which quality to show when the texture is 
near the view, 
the MAG filter is which quality to show when the texture 
is far from the view. 
The qualities are (in order from worst to best) 
GL_NEAREST 
GL_LINEAR 
GL_LINEAR_MIPMAP_NEAREST 
GL_LINEAR_MIPMAP_LINEAR 
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
GL_LINEAR ); 
glTexParameterf( GL_TEXTURE_2D, 
GL_TEXTURE_MAG_FILTER, GL_LINEAR );
Here we are setting the parameter to repeat the texture 
instead of clamping the texture 
to the edge of our shape. 
glTexParameterf( GL_TEXTURE_2D, 
GL_TEXTURE_WRAP_S, GL_REPEAT ); 
glTexParameterf( GL_TEXTURE_2D, 
GL_TEXTURE_WRAP_T, GL_REPEAT ); 
Generate the texture 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 
0, GL_RGB, GL_UNSIGNED_BYTE, data); 
free( data ); free the texture 
return texture; return the texture data 
}
Section 2: Cleaning Up: 
If we decide not to clean up after our work, you will 
find that the program will inevitably 
slow down your computer, taking more and more 
memory. 
void FreeTexture( GLuint texture ) 
{ 
glDeleteTextures( 1, &texture ); Delete our 
texture, simple enough. 
}
Section 3: Mapping Textures to Geometry 
You provide OpenGL with information about how to map 
the texture to the geometry. 
You do this by specifying a texture coordinate for each 
vertex. 
Texels in a texture map are addressed not as a memory 
location (as you would for pixmaps), but as a more 
abstract (usually floating-point values) texture coordinate. 
Typically, texture coordinates are specified as floating-point 
values that are clamped in the range 0.0 to 1.0. 
Texture coordinates are named s, t, r, and q (similar to 
vertex coordinates x, y, z, and w) supporting from one- to 
three-dimensional texture coordinates, and optionally a 
way to scale the coordinates.
void glTexCoord1f(GLfloat s); 
void glTexCoord2f(Glfloat s, GLfloat t); 
void glTexCoord3f(GLfloat s, GLfloat t, GLfloat r);
OpenGL then stretches or shrinks the texture as 
necessary to apply the texture to the geometry as 
mapped 
An example of a two-dimensional texture being 
mapped to a GL_QUAD. Note the corners of the 
texture correspond to the corners of the quad. As 
you do with other vertex properties (materials, 
normals, and so on), you must specify the texture 
coordinate before the vertex!
This figure also shows a square texture map, but the 
geometry is a triangle. Superimposed on the texture 
map are the texture coordinates of the locations in 
the map being extended to the vertices of the 
triangle.
glBegin(GL_TRIANGLES); 
glTexCoord2f(1.0f, 1.0f); 
glVertex3fv(1.0,1.0,1.0); 
glBegin (GL_QUADS); 
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); 
glTexCoord2d(1.0,0.0); glVertex2d(1.0,-1.0); 
glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); 
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,1.0); 
glEnd();
the windows header file, then we also need to add the 
Stdio header file. 
in the ’display’ function we first set the variable ’texture’ 
to the actual loaded image using: 
texture = LoadTexture( ”texture.raw”, 256, 256 ); 
where 256, 256 is the width and the height of the file 
respectively. 
then we enable the 2D Texturing, this is done with: 
glEnable( GL_TEXTURE_2D ); 
and bind the texture with: 
glBindTexture( GL_TEXTURE_2D, texture ); 
then after drawing everything we need with the texture,w 
e clear it to save system resources.

More Related Content

What's hot

IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & II
Sarang Joshi
 
Numerical analysis m2 l4slides
Numerical analysis  m2 l4slidesNumerical analysis  m2 l4slides
Numerical analysis m2 l4slides
SHAMJITH KM
 
Synthesizing 3d worlds
Synthesizing 3d worldsSynthesizing 3d worlds
Synthesizing 3d worlds
Baskar Rethinasabapathi
 
Structures for FIR systems
Structures for FIR systemsStructures for FIR systems
Structures for FIR systems
Chandan Taluja
 
WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics
PSTechSerbia
 
Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.js
PubNub
 
PA1_template
PA1_templatePA1_template
PA1_template
Grant Oliveira
 
Blur Filter - Hanpo
Blur Filter - HanpoBlur Filter - Hanpo
Blur Filter - Hanpo
Hanpo Cheng
 
Oracle Date Functions
Oracle Date FunctionsOracle Date Functions
Oracle Date Functions
Vigilant Technologies
 
Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++
Darshan Parsana
 

What's hot (10)

IIR filter realization using direct form I & II
IIR filter realization using direct form I & IIIIR filter realization using direct form I & II
IIR filter realization using direct form I & II
 
Numerical analysis m2 l4slides
Numerical analysis  m2 l4slidesNumerical analysis  m2 l4slides
Numerical analysis m2 l4slides
 
Synthesizing 3d worlds
Synthesizing 3d worldsSynthesizing 3d worlds
Synthesizing 3d worlds
 
Structures for FIR systems
Structures for FIR systemsStructures for FIR systems
Structures for FIR systems
 
WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics WebGL and three.js - Web 3D Graphics
WebGL and three.js - Web 3D Graphics
 
Streaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.jsStreaming and Visualizing Data with D3.js
Streaming and Visualizing Data with D3.js
 
PA1_template
PA1_templatePA1_template
PA1_template
 
Blur Filter - Hanpo
Blur Filter - HanpoBlur Filter - Hanpo
Blur Filter - Hanpo
 
Oracle Date Functions
Oracle Date FunctionsOracle Date Functions
Oracle Date Functions
 
Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++Gaussian Image Blurring in CUDA C++
Gaussian Image Blurring in CUDA C++
 

Viewers also liked

Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
Ghaffar Khan
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
Docent Education
 
Texturing
TexturingTexturing
Texturing
KeyShot Spain
 
Stencil printing
Stencil printingStencil printing
Stencil printing
Rojay Chambers
 
Texture
TextureTexture
Texture
13023901-016
 
Drawing and texturising
Drawing and texturising Drawing and texturising
Drawing and texturising
Md. Mazadul Hasan Shishir
 
Painting techniques
Painting techniquesPainting techniques
Painting techniques
Amy Brunt
 
Surface and Materials Analysis Techniques
Surface and Materials Analysis TechniquesSurface and Materials Analysis Techniques
Surface and Materials Analysis Techniques
Robert Cormia
 
Art styles
Art stylesArt styles
Art styles
Joey Richard Dio
 
Textures
TexturesTextures
Textures
Dolors Cubí
 
all about Painting (definition, elements, types, styles, history of Philippi...
all about Painting  (definition, elements, types, styles, history of Philippi...all about Painting  (definition, elements, types, styles, history of Philippi...
all about Painting (definition, elements, types, styles, history of Philippi...
Enjielou
 
The Visual Elements of Art: TEXTURE
The Visual Elements of Art: TEXTUREThe Visual Elements of Art: TEXTURE
The Visual Elements of Art: TEXTURE
Rosa Fernández
 

Viewers also liked (12)

Drawing Figures
Drawing FiguresDrawing Figures
Drawing Figures
 
unit-1-intro
 unit-1-intro unit-1-intro
unit-1-intro
 
Texturing
TexturingTexturing
Texturing
 
Stencil printing
Stencil printingStencil printing
Stencil printing
 
Texture
TextureTexture
Texture
 
Drawing and texturising
Drawing and texturising Drawing and texturising
Drawing and texturising
 
Painting techniques
Painting techniquesPainting techniques
Painting techniques
 
Surface and Materials Analysis Techniques
Surface and Materials Analysis TechniquesSurface and Materials Analysis Techniques
Surface and Materials Analysis Techniques
 
Art styles
Art stylesArt styles
Art styles
 
Textures
TexturesTextures
Textures
 
all about Painting (definition, elements, types, styles, history of Philippi...
all about Painting  (definition, elements, types, styles, history of Philippi...all about Painting  (definition, elements, types, styles, history of Philippi...
all about Painting (definition, elements, types, styles, history of Philippi...
 
The Visual Elements of Art: TEXTURE
The Visual Elements of Art: TEXTUREThe Visual Elements of Art: TEXTURE
The Visual Elements of Art: TEXTURE
 

Similar to Opengl texturing

OpenGL Texture Mapping
OpenGL Texture MappingOpenGL Texture Mapping
OpenGL Texture Mapping
Syed Zaid Irshad
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
Mark Kilgard
 
Texture mapping in_opengl
Texture mapping in_openglTexture mapping in_opengl
Texture mapping in_opengl
Manas Nayak
 
3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_rep
Liu Zhen-Yu
 
GFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ESGFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ES
Prabindh Sundareson
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
Mohammad Shaker
 
ShaderX³: Geometry Manipulation - Morphing between two different objects
ShaderX³: Geometry Manipulation - Morphing between two different objectsShaderX³: Geometry Manipulation - Morphing between two different objects
ShaderX³: Geometry Manipulation - Morphing between two different objects
Ronny Burkersroda
 
GLSL
GLSLGLSL
Fuzzy c means_realestate_application
Fuzzy c means_realestate_applicationFuzzy c means_realestate_application
Fuzzy c means_realestate_application
Cemal Ardil
 
Gdistance vignette
Gdistance vignetteGdistance vignette
Gdistance vignette
Nirvana Metallic
 
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
Sardar Alam
 
Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5
Takao Wada
 
8thlightu3
8thlightu38thlightu3
8thlightu3
Eric Smith
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3D
Mark Kilgard
 
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
JinTaek Seo
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
Budditha Hettige
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
Mark Kilgard
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
Takao Wada
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
Andrea Antonello
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
Etsuji Nakai
 

Similar to Opengl texturing (20)

OpenGL Texture Mapping
OpenGL Texture MappingOpenGL Texture Mapping
OpenGL Texture Mapping
 
CS 354 Texture Mapping
CS 354 Texture MappingCS 354 Texture Mapping
CS 354 Texture Mapping
 
Texture mapping in_opengl
Texture mapping in_openglTexture mapping in_opengl
Texture mapping in_opengl
 
3Dtexture_doc_rep
3Dtexture_doc_rep3Dtexture_doc_rep
3Dtexture_doc_rep
 
GFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ESGFX Part 4 - Introduction to Texturing in OpenGL ES
GFX Part 4 - Introduction to Texturing in OpenGL ES
 
OpenGL L05-Texturing
OpenGL L05-TexturingOpenGL L05-Texturing
OpenGL L05-Texturing
 
ShaderX³: Geometry Manipulation - Morphing between two different objects
ShaderX³: Geometry Manipulation - Morphing between two different objectsShaderX³: Geometry Manipulation - Morphing between two different objects
ShaderX³: Geometry Manipulation - Morphing between two different objects
 
GLSL
GLSLGLSL
GLSL
 
Fuzzy c means_realestate_application
Fuzzy c means_realestate_applicationFuzzy c means_realestate_application
Fuzzy c means_realestate_application
 
Gdistance vignette
Gdistance vignetteGdistance vignette
Gdistance vignette
 
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
 
Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5Trident International Graphics Workshop 2014 5/5
Trident International Graphics Workshop 2014 5/5
 
8thlightu3
8thlightu38thlightu3
8thlightu3
 
Mixing Path Rendering and 3D
Mixing Path Rendering and 3DMixing Path Rendering and 3D
Mixing Path Rendering and 3D
 
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeksBeginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
Beginning direct3d gameprogramming08_usingtextures_20160428_jintaeks
 
Texture Mapping
Texture Mapping Texture Mapping
Texture Mapping
 
Geometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping SetupGeometry Shader-based Bump Mapping Setup
Geometry Shader-based Bump Mapping Setup
 
Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5Trident International Graphics Workshop 2014 1/5
Trident International Graphics Workshop 2014 1/5
 
Opensource gis development - part 4
Opensource gis development - part 4Opensource gis development - part 4
Opensource gis development - part 4
 
Introducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlowIntroducton to Convolutional Nerural Network with TensorFlow
Introducton to Convolutional Nerural Network with TensorFlow
 

More from Sardar Alam

Undoing of mental illness -- seek help
Undoing of mental illness -- seek helpUndoing of mental illness -- seek help
Undoing of mental illness -- seek help
Sardar Alam
 
introduction to python
introduction to pythonintroduction to python
introduction to python
Sardar Alam
 
Operator Overloading
Operator Overloading  Operator Overloading
Operator Overloading
Sardar Alam
 
skin disease classification
skin disease classificationskin disease classification
skin disease classification
Sardar Alam
 
filters for noise in image processing
filters for noise in image processingfilters for noise in image processing
filters for noise in image processing
Sardar Alam
 
Noise Models
Noise ModelsNoise Models
Noise Models
Sardar Alam
 
Noise Models
Noise ModelsNoise Models
Noise Models
Sardar Alam
 
Introduction to machine learningunsupervised learning
Introduction to machine learningunsupervised learningIntroduction to machine learningunsupervised learning
Introduction to machine learningunsupervised learning
Sardar Alam
 
Mathematics fundamentals
Mathematics fundamentalsMathematics fundamentals
Mathematics fundamentals
Sardar Alam
 
3 d graphics with opengl part 1
3 d graphics with opengl part 13 d graphics with opengl part 1
3 d graphics with opengl part 1
Sardar Alam
 
3 d graphics basics
3 d graphics basics3 d graphics basics
3 d graphics basics
Sardar Alam
 
2 d transformations
2 d transformations2 d transformations
2 d transformations
Sardar Alam
 
Gui
GuiGui
Inheritance
InheritanceInheritance
Inheritance
Sardar Alam
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
Sardar Alam
 
Java basics
Java basicsJava basics
Java basics
Sardar Alam
 

More from Sardar Alam (16)

Undoing of mental illness -- seek help
Undoing of mental illness -- seek helpUndoing of mental illness -- seek help
Undoing of mental illness -- seek help
 
introduction to python
introduction to pythonintroduction to python
introduction to python
 
Operator Overloading
Operator Overloading  Operator Overloading
Operator Overloading
 
skin disease classification
skin disease classificationskin disease classification
skin disease classification
 
filters for noise in image processing
filters for noise in image processingfilters for noise in image processing
filters for noise in image processing
 
Noise Models
Noise ModelsNoise Models
Noise Models
 
Noise Models
Noise ModelsNoise Models
Noise Models
 
Introduction to machine learningunsupervised learning
Introduction to machine learningunsupervised learningIntroduction to machine learningunsupervised learning
Introduction to machine learningunsupervised learning
 
Mathematics fundamentals
Mathematics fundamentalsMathematics fundamentals
Mathematics fundamentals
 
3 d graphics with opengl part 1
3 d graphics with opengl part 13 d graphics with opengl part 1
3 d graphics with opengl part 1
 
3 d graphics basics
3 d graphics basics3 d graphics basics
3 d graphics basics
 
2 d transformations
2 d transformations2 d transformations
2 d transformations
 
Gui
GuiGui
Gui
 
Inheritance
InheritanceInheritance
Inheritance
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 
Java basics
Java basicsJava basics
Java basics
 

Recently uploaded

Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
Peter Muessig
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
YousufSait3
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
Quickdice ERP
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
dakas1
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
ShulagnaSarkar2
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
Peter Muessig
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
Karya Keeper
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
Massimo Artizzu
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
Bert Jan Schrijver
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
brainerhub1
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
Peter Muessig
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
Green Software Development
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
Alina Yurenko
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 

Recently uploaded (20)

Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsUI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
UI5con 2024 - Boost Your Development Experience with UI5 Tooling Extensions
 
zOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL DifferenceszOS Mainframe JES2-JES3 JCL-JECL Differences
zOS Mainframe JES2-JES3 JCL-JECL Differences
 
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesE-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian Companies
 
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
一比一原版(UMN毕业证)明尼苏达大学毕业证如何办理
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision14 th Edition of International conference on computer vision
14 th Edition of International conference on computer vision
 
UI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design SystemUI5con 2024 - Bring Your Own Design System
UI5con 2024 - Bring Your Own Design System
 
Project Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdfProject Management: The Role of Project Dashboards.pdf
Project Management: The Role of Project Dashboards.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Liberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptxLiberarsi dai framework con i Web Component.pptx
Liberarsi dai framework con i Web Component.pptx
 
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
J-Spring 2024 - Going serverless with Quarkus, GraalVM native images and AWS ...
 
Unveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdfUnveiling the Advantages of Agile Software Development.pdf
Unveiling the Advantages of Agile Software Development.pdf
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemUI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
UI5con 2024 - Keynote: Latest News about UI5 and it’s Ecosystem
 
Energy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina JonuziEnergy consumption of Database Management - Florina Jonuzi
Energy consumption of Database Management - Florina Jonuzi
 
All you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVMAll you need to know about Spring Boot and GraalVM
All you need to know about Spring Boot and GraalVM
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 

Opengl texturing

  • 2. When we apply image data to a geometric primitive, we call this a texture or texture map. shows the dramatic difference that can be achieved by texture mapping geometry. The cube on the left is a lit and shaded featureless surface, whereas the cube on the right shows a richness in detail that can be reasonably achieved only with texture mapping.
  • 3. Loading Textures Using GLuint we create a variable for the texture, called ‘texture’, but you can call it. In the ‘display’ function we first set the variable ‘texture’ to the actual loaded image using: texture = LoadTexture( “texture.raw”, 256, 256 ); where 256, 256 is the width and the height of the file respectively. Then we enable the 2D Texturing, this is done with: glEnable( GL_TEXTURE_2D ); and bind the texture with: glBindTexture( GL_TEXTURE_2D, texture ); then after drawing everything we need with the texture, we clear it to save system resources.
  • 4. Section 1: The loading of the texture: GLuint LoadTexture( const char * filename, int width, int height ) { GLuint texture; unsigned char * data; FILE * file; The following code will read in our RAW file file = fopen( filename, “rb” ); We need to open our file if ( file == NULL ) return 0; If our file is empty, set our texture to empty data = (unsigned char *)malloc( width * height * 3 ); assign the nessecary memory for the texture fread( data, width * height * 3, 1, file ); read in our file fclose( file ); close our file, no point leaving it open
  • 5. glGenTextures( 1, &texture ); then we need to tell OpenGL that we are generating a texture glBindTexture( GL_TEXTURE_2D, texture ); now we bind the texture that we are working with glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); set texture environment parameters The parameter GL_MODULATE will blend the texture with whatever is underneath, setting it to GL_DECAL will tell the texture to replace whatever is on the object.
  • 6. here we are setting what textures to use and when. The MIN filter is which quality to show when the texture is near the view, the MAG filter is which quality to show when the texture is far from the view. The qualities are (in order from worst to best) GL_NEAREST GL_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
  • 7. Here we are setting the parameter to repeat the texture instead of clamping the texture to the edge of our shape. glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); Generate the texture glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data); free( data ); free the texture return texture; return the texture data }
  • 8. Section 2: Cleaning Up: If we decide not to clean up after our work, you will find that the program will inevitably slow down your computer, taking more and more memory. void FreeTexture( GLuint texture ) { glDeleteTextures( 1, &texture ); Delete our texture, simple enough. }
  • 9. Section 3: Mapping Textures to Geometry You provide OpenGL with information about how to map the texture to the geometry. You do this by specifying a texture coordinate for each vertex. Texels in a texture map are addressed not as a memory location (as you would for pixmaps), but as a more abstract (usually floating-point values) texture coordinate. Typically, texture coordinates are specified as floating-point values that are clamped in the range 0.0 to 1.0. Texture coordinates are named s, t, r, and q (similar to vertex coordinates x, y, z, and w) supporting from one- to three-dimensional texture coordinates, and optionally a way to scale the coordinates.
  • 10. void glTexCoord1f(GLfloat s); void glTexCoord2f(Glfloat s, GLfloat t); void glTexCoord3f(GLfloat s, GLfloat t, GLfloat r);
  • 11. OpenGL then stretches or shrinks the texture as necessary to apply the texture to the geometry as mapped An example of a two-dimensional texture being mapped to a GL_QUAD. Note the corners of the texture correspond to the corners of the quad. As you do with other vertex properties (materials, normals, and so on), you must specify the texture coordinate before the vertex!
  • 12. This figure also shows a square texture map, but the geometry is a triangle. Superimposed on the texture map are the texture coordinates of the locations in the map being extended to the vertices of the triangle.
  • 13. glBegin(GL_TRIANGLES); glTexCoord2f(1.0f, 1.0f); glVertex3fv(1.0,1.0,1.0); glBegin (GL_QUADS); glTexCoord2d(0.0,0.0); glVertex2d(-1.0,-1.0); glTexCoord2d(1.0,0.0); glVertex2d(1.0,-1.0); glTexCoord2d(1.0,1.0); glVertex2d(1.0,1.0); glTexCoord2d(0.0,1.0); glVertex2d(-1.0,1.0); glEnd();
  • 14. the windows header file, then we also need to add the Stdio header file. in the ’display’ function we first set the variable ’texture’ to the actual loaded image using: texture = LoadTexture( ”texture.raw”, 256, 256 ); where 256, 256 is the width and the height of the file respectively. then we enable the 2D Texturing, this is done with: glEnable( GL_TEXTURE_2D ); and bind the texture with: glBindTexture( GL_TEXTURE_2D, texture ); then after drawing everything we need with the texture,w e clear it to save system resources.