SlideShare a Scribd company logo
Mohammad Shaker
mohammadshaker.com
@ZGTRShaker
2015
OpenGL Graphics
L05-Texturing
Texturing
that appears in a video game needs to be textured; this includes everything from plants
to people. If things aren’t textured well, your game just won’t look right.
OpenGL Architecture
Display
List
Polynomial
Evaluator
Per Vertex
Operations &
Primitive
Assembly
Rasterization
Per Fragment
Operations
Frame
Buffer
Texture
Memory
CPU
Pixel
Operations
OpenGL Architecture
Display
List
Polynomial
Evaluator
Per Vertex
Operations &
Primitive
Assembly
Rasterization
Per Fragment
Operations
Frame
Buffer
Texture
Memory
CPU
Pixel
Operations
How to use a Texture?
• How to use a Texture?
1. Load the texture
2. Map it into a polygon
3. Draw the polygon
How to use a Texture?
• How to use a Texture?
1. Load the texture
2. Map it into a polygon
3. Draw the polygon
• How to use a Texture? (OpenGL)
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
• How OpenGL store images?
– One image per texture object
– May be shared by several graphics contexts
Textures Coordinates
Textures Coordinates
Texture Mapping
s
t
x
y
z
image
geometry
screen
Textures Coordinates
Textures Coordinates
Textures Coordinates
s
t
1, 10, 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
Texturing Example
Texturing Code
GLvoid DrawGLScene()
//Set camera and projection
GLvoid init()
Global scope:
Texturing Code
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imageTexId);
glScalef(5,5,1);
glBegin(GL_QUADS);
glTexCoord2f(1,0) ; glVertex3f(1,-1,1);
glTexCoord2f(1,1) ; glVertex3f(1,1,1);
glTexCoord2f(0,1) ; glVertex3f(-1,1,1);
glTexCoord2f(0,0) ; glVertex3f(-1,-1,1);
glEnd();
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
imageTexId = LoadTexture("images//tile.bmp");
GLvoid init()
#include "texture.h”
int imageTexId;
Global scope:
Texturing Code
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imageTexId);
glScalef(5,5,1);
glBegin(GL_QUADS);
glTexCoord2f(1,0) ; glVertex3f(1,-1,1);
glTexCoord2f(1,1) ; glVertex3f(1,1,1);
glTexCoord2f(0,1) ; glVertex3f(-1,1,1);
glTexCoord2f(0,0) ; glVertex3f(-1,-1,1);
glEnd();
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
imageTexId = LoadTexture("images//tile.bmp");
GLvoid init()
#include "texture.h”
int imageTexId;
Global scope:
Texturing Code
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imageTexId);
glScalef(5,5,1);
glBegin(GL_QUADS);
glTexCoord2f(1,0) ; glVertex3f(1,-1,1);
glTexCoord2f(1,1) ; glVertex3f(1,1,1);
glTexCoord2f(0,1) ; glVertex3f(-1,1,1);
glTexCoord2f(0,0) ; glVertex3f(-1,-1,1);
glEnd();
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
imageTexId = LoadTexture("images//tile.bmp");
GLvoid init()
#include "texture.h”
int imageTexId;
Global scope:
Texturing Code
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imageTexId);
glScalef(5,5,1);
glBegin(GL_QUADS);
glTexCoord2f(1,0) ; glVertex3f(1,-1,1);
glTexCoord2f(1,1) ; glVertex3f(1,1,1);
glTexCoord2f(0,1) ; glVertex3f(-1,1,1);
glTexCoord2f(0,0) ; glVertex3f(-1,-1,1);
glEnd();
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
imageTexId = LoadTexture("images//tile.bmp");
GLvoid init()
#include "texture.h”
int imageTexId;
Global scope:
Texturing Functions
Texturing Functions
• Generate texture names
glGenTextures(n, *texIds);
• Create texture objects with texture data and state
glBindTexture(target, id);
• Bind textures before using
glBindTexture(target, id);
• Define a texture image from an array of texels in CPU memory
glTexImage2D(target, level, components, w, h, border, format, type,
*texels);
• Texel colors are processed by pixel pipeline
– pixel scales, biases and lookups can be done
Filter Modes
• Filter modes control how pixels are minified or magnified. Generally a color is
computed using the nearest texel or by a linear average of several texels.
• The filter type, above is one of GL_TEXTURE_MIN_FILTER or GL_TEXTURE_MAG_FILTER.
• The mode is one of GL_NEAREST, GL_LINEAR, or special modes for mipmapping.
Mipmapping modes are used for minification only, and have values of:
– GL_NEAREST_MIPMAP_NEAREST
– GL_NEAREST_MIPMAP_LINEAR
– GL_LINEAR_MIPMAP_NEAREST
– GL_LINEAR_MIPMAP_LINEAR
Filter Modes
• Example: glTexParameteri(target, type, mode);
Texture Polygon
Magnification Minification
PolygonTexture
Wrapping Mode
• Wrap mode determines what should happen if a texture coordinate lies outside of the [0,1] range.
• If the GL_REPEAT wrap mode is used, for texture coordinate values less than zero or greater than
one, the integer is ignored and only the fractional value is used.
• If the GL_CLAMP wrap mode is used, the texture value at the extreme (either 0 or 1) is used.
• Example:
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
texture
GL_REPEAT
wrapping
GL_CLAMP
wrapping
s
t
Texture Parameters
Read more: https://open.gl/textures
Body Color When Textured
• glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
– resultColor = Body Color + Texture Color [By default]
• glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
– resultColor = Texture Color
• glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
– resultColor = Texture Color + Blending
• GLfloat fColor[4] = { 0.0f, 0.0f, 0.0f, 1f };
• glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fColor);
Texturing
Something to pay attention for
Something to pay attention for
• The image must be 24 bit (RGB)
• The image extension should be .bmp
• The image dimensions must be a power of 2 (2, 4, 8, 16, 32, 64, ..etc.)
– If dimensions of image are not power of 2 then scale:
• 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
• White color should be assigned before drawing a textured object by setting:
glColor3f(1,1,1);
• You should call: glBindTexture(GL_TEXTURE_2D, textureID) between glBegin() and
glEnd()
gluQuadricTexture
Textures Coordinates
gluQuadricTexture
+
gluQuadricTexture
+ =
gluQuadricTexture
Blending
Blending
• You can blend objects using:
– glBlendFunc(GLenum sfactor, GLenum dfactor);
• sfactor: is the source blend factor
• dfactor: is the destination blend factor
• Transparency is implemented using:
– “GL_SRC_ALPHA” for the source
– “GL_ONE_MINUS_SRC_ALPHA” for the destination
Blending
• You can blend objects using:
– glBlendFunc(GLenum sfactor, GLenum dfactor);
• sfactor: is the source blend factor
• dfactor: is the destination blend factor
• Transparency is implemented using:
– “GL_SRC_ALPHA” for the source
– “GL_ONE_MINUS_SRC_ALPHA” for the destination
OpenGL Architecture
Display
List
Polynomial
Evaluator
Per Vertex
Operations &
Primitive
Assembly
Rasterization
Per Fragment
Operations
Frame
Buffer
Texture
Memory
CPU
Pixel
Operations
OpenGL Architecture
Display
List
Polynomial
Evaluator
Per Vertex
Operations &
Primitive
Assembly
Rasterization
Per Fragment
Operations
Frame
Buffer
Texture
Memory
CPU
Pixel
Operations
Blending
• Combine pixels with what’s in already in the framebuffer
glBlendFunc(src, dst )
Framebuffer
Pixel (dst)
Blending
Equation
Fragment
(src)
Blended
Pixel
pfr CdstCsrcC


Transparency with .tga (32 bit)
Transparency with .tga
+ =
Transparency with .tga
+ =
One .tga File
Transparency with .tga Code
GLvoid DrawGLScene()
//Set camera and projection
GLvoid init()
Global scope:
Transparency with .tga Code
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
GLvoid DrawGLScene()
//Set camera and projection
glEnable(GL_TEXTURE_2D);
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
GLvoid DrawGLScene()
//Set camera and projection
glEnable(GL_TEXTURE_2D);
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
GLvoid DrawGLScene()
//Set camera and projection
glEnable(GL_TEXTURE_2D);
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
GLvoid DrawGLScene()
//Set camera and projection
glEnable(GL_TEXTURE_2D);
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
GLvoid DrawGLScene()
//Set camera and projection
glEnable(GL_TEXTURE_2D);
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code / Fixes
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(5,-5,0);
glTexCoord2f(1,1); glVertex3f(5,5,0);
glTexCoord2f(0,1); glVertex3f(-5,5,0);
glTexCoord2f(0,0); glVertex3f(-5,-5,0);
glEnd();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga Code / Fixes
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D , grassImage.texID);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA);
glPushMatrix();
glLoadIdentity();
glScalef(5, 5, 1);
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(1,-1,0);
glTexCoord2f(1,1); glVertex3f(1,1,0);
glTexCoord2f(0,1); glVertex3f(-1,1,0);
glTexCoord2f(0,0); glVertex3f(-1,-1,0);
glEnd();
glPopMatrix();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
GLvoid DrawGLScene()
//Set camera and projection
grassImage = LoadTGA(“images//grass.tga");
GLvoid init()
#include "tgaLoader.h”
TGAImage grassImage;
Global scope:
Transparency with .tga
Add Transparency with .tga
Transparency with .tga (32 bit)
Something to pay attention for, again
Something to pay attention for, again
• The image must be 24 bit (RGB)
• The image extension should be .bmp
• The image dimensions must be a power of 2 (2, 4, 8, 16, 32, 64, ..etc.) or scale.
• White color should be assigned before drawing a textured object by setting:
glColor3f(1,1,1);
• You should call: glBindTexture(GL_TEXTURE_2D, textureID) between
glBegin() and glEnd()
• Additional stuff when you use transparency with .tga
– The image must be 32 bit (RGB)
– The image extension should be .tga
– In InitGL(), You must load .tga files LAST
– In DrawGLScene(), you must draw the transparent objects LAST
Texture Tilling
Texture Tilling
Tiling is a very simple effect that creates a repeating pattern of
an image on the surface of a primitive object
Texture Tilling
Using a small image to cover a large surface makes tiling a useful way to increase the
performance of your textures and decrease the size of your image files.
Texture Tilling, How to
Simply set the texture coordinates larger than 1
as many time as you want the texture to be tilled
Billboarding
Billboarding
Mipmapping
Mipmapping
multum in parvo (mip): many things in a small place
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()
2D Texture and 3D Texture?
http://gamedev.stackexchange.com/questions/9668/what-are-3d-textures
2D Texture and 3D Texture
• All we have used so far are 2D textures mapped on a 3D coordinates.
• So what’s a 3D texture?!
– 3D texture (or sometimes called “Volume textures”) works like regular 2D texture but it is truly
3D. 2D textures has UV coordinates, 3D has UVW coordinates
Textures Coordinates
• Texture coordinates are named s, t, r, and q
2D Texture and 3D Texture
• 3D textures are used in:
– Textures mapped into a model vertices
– volumetric effects in games (fire, smoke, light rays, realistic fog)
– caching light for realtime global illumination (CryEngine for example)
– scientific (MRI, CT scans are saved into volumes)
2D Texture and 3D Texture
• Watch Nvidia smoke box in a XFX 9600gt
– https://www.youtube.com/watch?v=9AS4xV-CK14
2D Texture and 3D Texture
• Watch Global illumination in CryEngine 3 Tech Trailer (HD)
– https://www.youtube.com/watch?v=Pq39Xb7OdH8

More Related Content

PDF
OpenGL L03-Utilities
PDF
OpenGL L07-Skybox and Terrian
PPT
Geometry Shader-based Bump Mapping Setup
PPT
CS 354 Transformation, Clipping, and Culling
PPT
Computer graphics mini project on bellman-ford algorithm
PPTX
Graphics Programming in C
PPTX
Graphics in C++
OpenGL L03-Utilities
OpenGL L07-Skybox and Terrian
Geometry Shader-based Bump Mapping Setup
CS 354 Transformation, Clipping, and Culling
Computer graphics mini project on bellman-ford algorithm
Graphics Programming in C
Graphics in C++

What's hot (20)

PPTX
Introduction to graphics programming in c
PDF
Games 3 dl4-example
DOCX
C graphics programs file
PPTX
Trident International Graphics Workshop 2014 5/5
PDF
OpenGL L02-Transformations
PPTX
Tomato Classification using Computer Vision
PPTX
Unity programming 1
PDF
Creating Games for Asha - platform
PDF
Computer graphics practical(jainam)
PDF
Advanced Scenegraph Rendering Pipeline
PDF
C Graphics Functions
PDF
Deep dive into deeplearn.js
PPTX
Approaching zero driver overhead
PDF
Opensource gis development - part 4
PDF
The Ring programming language version 1.7 book - Part 63 of 196
PPTX
Trident International Graphics Workshop 2014 1/5
PPT
CS 354 Viewing Stuff
KEY
openFrameworks 007 - GL
PDF
Opensource gis development - part 3
Introduction to graphics programming in c
Games 3 dl4-example
C graphics programs file
Trident International Graphics Workshop 2014 5/5
OpenGL L02-Transformations
Tomato Classification using Computer Vision
Unity programming 1
Creating Games for Asha - platform
Computer graphics practical(jainam)
Advanced Scenegraph Rendering Pipeline
C Graphics Functions
Deep dive into deeplearn.js
Approaching zero driver overhead
Opensource gis development - part 4
The Ring programming language version 1.7 book - Part 63 of 196
Trident International Graphics Workshop 2014 1/5
CS 354 Viewing Stuff
openFrameworks 007 - GL
Opensource gis development - part 3
Ad

Viewers also liked (18)

PDF
OpenGL L04-Lighting
PDF
OpenGL Starter L02
PDF
Open GL Tutorial09
PDF
Open GL Tutorial06
PDF
OpenGL L06-Performance
PPTX
Mesh texturing
PPTX
COMPUTER GRAPHICS DAY1
PDF
OpenGL Starter L01
PPT
lecture3 color representation in computer graphics(Computer graphics tutorials)
PDF
Texturing
PDF
OpenGL L01-Primitives
PPT
3 D Maya Introduction
PDF
3D modelling and animation using Autodesk maya
PPT
3D Modeling and Texturing Walkthrough
PDF
Introduction to 3D Modelling
PDF
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
PDF
Tour of Vue.js
OpenGL L04-Lighting
OpenGL Starter L02
Open GL Tutorial09
Open GL Tutorial06
OpenGL L06-Performance
Mesh texturing
COMPUTER GRAPHICS DAY1
OpenGL Starter L01
lecture3 color representation in computer graphics(Computer graphics tutorials)
Texturing
OpenGL L01-Primitives
3 D Maya Introduction
3D modelling and animation using Autodesk maya
3D Modeling and Texturing Walkthrough
Introduction to 3D Modelling
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Tour of Vue.js
Ad

Similar to OpenGL L05-Texturing (20)

PDF
Texture Mapping
PPT
OpenGL Texture Mapping
PPT
CS 354 Texture Mapping
PPTX
Texture mapping in_opengl
PPTX
Multi graph encoder
PPTX
Opengl texturing
PPTX
Efficacy of deferred rendering in WebGL
KEY
8thlightu3
PDF
Demystifying Neural Style Transfer
PDF
Cj36511514
PDF
Arkanoid Game
PDF
201707 SER332 Lecture 21
PPTX
Render to Texture with Three.js
PPTX
Computer Vision.pptx
PPTX
GFX Part 4 - Introduction to Texturing in OpenGL ES
PDF
Using CNTK's Python Interface for Deep LearningDave DeBarr -
PDF
A0280105
PDF
From Experimentation to Production: The Future of WebGL
PDF
COMPUTER GRAPHICS PROJECT REPORT
PPTX
OpenCV In Mobile Technology | Computer Vision on Mobile
Texture Mapping
OpenGL Texture Mapping
CS 354 Texture Mapping
Texture mapping in_opengl
Multi graph encoder
Opengl texturing
Efficacy of deferred rendering in WebGL
8thlightu3
Demystifying Neural Style Transfer
Cj36511514
Arkanoid Game
201707 SER332 Lecture 21
Render to Texture with Three.js
Computer Vision.pptx
GFX Part 4 - Introduction to Texturing in OpenGL ES
Using CNTK's Python Interface for Deep LearningDave DeBarr -
A0280105
From Experimentation to Production: The Future of WebGL
COMPUTER GRAPHICS PROJECT REPORT
OpenCV In Mobile Technology | Computer Vision on Mobile

More from Mohammad Shaker (20)

PDF
12 Rules You Should to Know as a Syrian Graduate
PDF
Interaction Design L06 - Tricks with Psychology
PDF
Short, Matters, Love - Passioneers Event 2015
PDF
Unity L01 - Game Development
PDF
Android L07 - Touch, Screen and Wearables
PDF
Interaction Design L03 - Color
PDF
Interaction Design L05 - Typography
PDF
Interaction Design L04 - Materialise and Coupling
PDF
Android L05 - Storage
PDF
Android L04 - Notifications and Threading
PDF
Android L09 - Windows Phone and iOS
PDF
Interaction Design L01 - Mobile Constraints
PDF
Interaction Design L02 - Pragnanz and Grids
PDF
Android L10 - Stores and Gaming
PDF
Android L06 - Cloud / Parse
PDF
Android L08 - Google Maps and Utilities
PDF
Android L03 - Styles and Themes
PDF
Android L02 - Activities and Adapters
PDF
Android L01 - Warm Up
PDF
Indie Series 03: Becoming an Indie
12 Rules You Should to Know as a Syrian Graduate
Interaction Design L06 - Tricks with Psychology
Short, Matters, Love - Passioneers Event 2015
Unity L01 - Game Development
Android L07 - Touch, Screen and Wearables
Interaction Design L03 - Color
Interaction Design L05 - Typography
Interaction Design L04 - Materialise and Coupling
Android L05 - Storage
Android L04 - Notifications and Threading
Android L09 - Windows Phone and iOS
Interaction Design L01 - Mobile Constraints
Interaction Design L02 - Pragnanz and Grids
Android L10 - Stores and Gaming
Android L06 - Cloud / Parse
Android L08 - Google Maps and Utilities
Android L03 - Styles and Themes
Android L02 - Activities and Adapters
Android L01 - Warm Up
Indie Series 03: Becoming an Indie

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
top salesforce developer skills in 2025.pdf
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
System and Network Administraation Chapter 3
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
How Creative Agencies Leverage Project Management Software.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PPTX
L1 - Introduction to python Backend.pptx
medical staffing services at VALiNTRY
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms I-SECS-1021-03
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
top salesforce developer skills in 2025.pdf
Understanding Forklifts - TECH EHS Solution
Upgrade and Innovation Strategies for SAP ERP Customers
Wondershare Filmora 15 Crack With Activation Key [2025
How to Choose the Right IT Partner for Your Business in Malaysia
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
System and Network Administraation Chapter 3
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Odoo POS Development Services by CandidRoot Solutions
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
How Creative Agencies Leverage Project Management Software.pdf
CHAPTER 2 - PM Management and IT Context
L1 - Introduction to python Backend.pptx

OpenGL L05-Texturing

  • 3. that appears in a video game needs to be textured; this includes everything from plants to people. If things aren’t textured well, your game just won’t look right.
  • 4. OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture Memory CPU Pixel Operations
  • 5. OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture Memory CPU Pixel Operations
  • 6. How to use a Texture? • How to use a Texture? 1. Load the texture 2. Map it into a polygon 3. Draw the polygon
  • 7. How to use a Texture? • How to use a Texture? 1. Load the texture 2. Map it into a polygon 3. Draw the polygon • How to use a Texture? (OpenGL) 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 • How OpenGL store images? – One image per texture object – May be shared by several graphics contexts
  • 13. Textures Coordinates s t 1, 10, 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
  • 15. Texturing Code GLvoid DrawGLScene() //Set camera and projection GLvoid init() Global scope:
  • 16. Texturing Code glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, imageTexId); glScalef(5,5,1); glBegin(GL_QUADS); glTexCoord2f(1,0) ; glVertex3f(1,-1,1); glTexCoord2f(1,1) ; glVertex3f(1,1,1); glTexCoord2f(0,1) ; glVertex3f(-1,1,1); glTexCoord2f(0,0) ; glVertex3f(-1,-1,1); glEnd(); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection imageTexId = LoadTexture("images//tile.bmp"); GLvoid init() #include "texture.h” int imageTexId; Global scope:
  • 17. Texturing Code glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, imageTexId); glScalef(5,5,1); glBegin(GL_QUADS); glTexCoord2f(1,0) ; glVertex3f(1,-1,1); glTexCoord2f(1,1) ; glVertex3f(1,1,1); glTexCoord2f(0,1) ; glVertex3f(-1,1,1); glTexCoord2f(0,0) ; glVertex3f(-1,-1,1); glEnd(); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection imageTexId = LoadTexture("images//tile.bmp"); GLvoid init() #include "texture.h” int imageTexId; Global scope:
  • 18. Texturing Code glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, imageTexId); glScalef(5,5,1); glBegin(GL_QUADS); glTexCoord2f(1,0) ; glVertex3f(1,-1,1); glTexCoord2f(1,1) ; glVertex3f(1,1,1); glTexCoord2f(0,1) ; glVertex3f(-1,1,1); glTexCoord2f(0,0) ; glVertex3f(-1,-1,1); glEnd(); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection imageTexId = LoadTexture("images//tile.bmp"); GLvoid init() #include "texture.h” int imageTexId; Global scope:
  • 19. Texturing Code glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, imageTexId); glScalef(5,5,1); glBegin(GL_QUADS); glTexCoord2f(1,0) ; glVertex3f(1,-1,1); glTexCoord2f(1,1) ; glVertex3f(1,1,1); glTexCoord2f(0,1) ; glVertex3f(-1,1,1); glTexCoord2f(0,0) ; glVertex3f(-1,-1,1); glEnd(); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection imageTexId = LoadTexture("images//tile.bmp"); GLvoid init() #include "texture.h” int imageTexId; Global scope:
  • 21. Texturing Functions • Generate texture names glGenTextures(n, *texIds); • Create texture objects with texture data and state glBindTexture(target, id); • Bind textures before using glBindTexture(target, id); • Define a texture image from an array of texels in CPU memory glTexImage2D(target, level, components, w, h, border, format, type, *texels); • Texel colors are processed by pixel pipeline – pixel scales, biases and lookups can be done
  • 22. Filter Modes • Filter modes control how pixels are minified or magnified. Generally a color is computed using the nearest texel or by a linear average of several texels. • The filter type, above is one of GL_TEXTURE_MIN_FILTER or GL_TEXTURE_MAG_FILTER. • The mode is one of GL_NEAREST, GL_LINEAR, or special modes for mipmapping. Mipmapping modes are used for minification only, and have values of: – GL_NEAREST_MIPMAP_NEAREST – GL_NEAREST_MIPMAP_LINEAR – GL_LINEAR_MIPMAP_NEAREST – GL_LINEAR_MIPMAP_LINEAR
  • 23. Filter Modes • Example: glTexParameteri(target, type, mode); Texture Polygon Magnification Minification PolygonTexture
  • 24. Wrapping Mode • Wrap mode determines what should happen if a texture coordinate lies outside of the [0,1] range. • If the GL_REPEAT wrap mode is used, for texture coordinate values less than zero or greater than one, the integer is ignored and only the fractional value is used. • If the GL_CLAMP wrap mode is used, the texture value at the extreme (either 0 or 1) is used. • Example: glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) texture GL_REPEAT wrapping GL_CLAMP wrapping s t
  • 25. Texture Parameters Read more: https://open.gl/textures
  • 26. Body Color When Textured • glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); – resultColor = Body Color + Texture Color [By default] • glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); – resultColor = Texture Color • glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); – resultColor = Texture Color + Blending • GLfloat fColor[4] = { 0.0f, 0.0f, 0.0f, 1f }; • glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, fColor);
  • 27. Texturing Something to pay attention for
  • 28. Something to pay attention for • The image must be 24 bit (RGB) • The image extension should be .bmp • The image dimensions must be a power of 2 (2, 4, 8, 16, 32, 64, ..etc.) – If dimensions of image are not power of 2 then scale: • 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 • White color should be assigned before drawing a textured object by setting: glColor3f(1,1,1); • You should call: glBindTexture(GL_TEXTURE_2D, textureID) between glBegin() and glEnd()
  • 35. Blending • You can blend objects using: – glBlendFunc(GLenum sfactor, GLenum dfactor); • sfactor: is the source blend factor • dfactor: is the destination blend factor • Transparency is implemented using: – “GL_SRC_ALPHA” for the source – “GL_ONE_MINUS_SRC_ALPHA” for the destination
  • 36. Blending • You can blend objects using: – glBlendFunc(GLenum sfactor, GLenum dfactor); • sfactor: is the source blend factor • dfactor: is the destination blend factor • Transparency is implemented using: – “GL_SRC_ALPHA” for the source – “GL_ONE_MINUS_SRC_ALPHA” for the destination
  • 37. OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture Memory CPU Pixel Operations
  • 38. OpenGL Architecture Display List Polynomial Evaluator Per Vertex Operations & Primitive Assembly Rasterization Per Fragment Operations Frame Buffer Texture Memory CPU Pixel Operations
  • 39. Blending • Combine pixels with what’s in already in the framebuffer glBlendFunc(src, dst ) Framebuffer Pixel (dst) Blending Equation Fragment (src) Blended Pixel pfr CdstCsrcC  
  • 42. Transparency with .tga + = One .tga File
  • 43. Transparency with .tga Code GLvoid DrawGLScene() //Set camera and projection GLvoid init() Global scope:
  • 44. Transparency with .tga Code glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); GLvoid DrawGLScene() //Set camera and projection glEnable(GL_TEXTURE_2D); grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 45. Transparency with .tga Code glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); GLvoid DrawGLScene() //Set camera and projection glEnable(GL_TEXTURE_2D); grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 46. Transparency with .tga Code glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); GLvoid DrawGLScene() //Set camera and projection glEnable(GL_TEXTURE_2D); grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 47. Transparency with .tga Code glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); GLvoid DrawGLScene() //Set camera and projection glEnable(GL_TEXTURE_2D); grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 48. Transparency with .tga Code glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); GLvoid DrawGLScene() //Set camera and projection glEnable(GL_TEXTURE_2D); grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 49. Transparency with .tga Code / Fixes glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(5,-5,0); glTexCoord2f(1,1); glVertex3f(5,5,0); glTexCoord2f(0,1); glVertex3f(-5,5,0); glTexCoord2f(0,0); glVertex3f(-5,-5,0); glEnd(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 50. Transparency with .tga Code / Fixes glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D , grassImage.texID); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA , GL_ONE_MINUS_SRC_ALPHA); glPushMatrix(); glLoadIdentity(); glScalef(5, 5, 1); glBegin(GL_QUADS); glTexCoord2f(1,0); glVertex3f(1,-1,0); glTexCoord2f(1,1); glVertex3f(1,1,0); glTexCoord2f(0,1); glVertex3f(-1,1,0); glTexCoord2f(0,0); glVertex3f(-1,-1,0); glEnd(); glPopMatrix(); glDisable(GL_BLEND); glDisable(GL_TEXTURE_2D); GLvoid DrawGLScene() //Set camera and projection grassImage = LoadTGA(“images//grass.tga"); GLvoid init() #include "tgaLoader.h” TGAImage grassImage; Global scope:
  • 53. Transparency with .tga (32 bit) Something to pay attention for, again
  • 54. Something to pay attention for, again • The image must be 24 bit (RGB) • The image extension should be .bmp • The image dimensions must be a power of 2 (2, 4, 8, 16, 32, 64, ..etc.) or scale. • White color should be assigned before drawing a textured object by setting: glColor3f(1,1,1); • You should call: glBindTexture(GL_TEXTURE_2D, textureID) between glBegin() and glEnd() • Additional stuff when you use transparency with .tga – The image must be 32 bit (RGB) – The image extension should be .tga – In InitGL(), You must load .tga files LAST – In DrawGLScene(), you must draw the transparent objects LAST
  • 56. Texture Tilling Tiling is a very simple effect that creates a repeating pattern of an image on the surface of a primitive object
  • 57. Texture Tilling Using a small image to cover a large surface makes tiling a useful way to increase the performance of your textures and decrease the size of your image files.
  • 58. Texture Tilling, How to Simply set the texture coordinates larger than 1 as many time as you want the texture to be tilled
  • 62. Mipmapping multum in parvo (mip): many things in a small place
  • 63. 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()
  • 64. 2D Texture and 3D Texture? http://gamedev.stackexchange.com/questions/9668/what-are-3d-textures
  • 65. 2D Texture and 3D Texture • All we have used so far are 2D textures mapped on a 3D coordinates. • So what’s a 3D texture?! – 3D texture (or sometimes called “Volume textures”) works like regular 2D texture but it is truly 3D. 2D textures has UV coordinates, 3D has UVW coordinates
  • 66. Textures Coordinates • Texture coordinates are named s, t, r, and q
  • 67. 2D Texture and 3D Texture • 3D textures are used in: – Textures mapped into a model vertices – volumetric effects in games (fire, smoke, light rays, realistic fog) – caching light for realtime global illumination (CryEngine for example) – scientific (MRI, CT scans are saved into volumes)
  • 68. 2D Texture and 3D Texture • Watch Nvidia smoke box in a XFX 9600gt – https://www.youtube.com/watch?v=9AS4xV-CK14
  • 69. 2D Texture and 3D Texture • Watch Global illumination in CryEngine 3 Tech Trailer (HD) – https://www.youtube.com/watch?v=Pq39Xb7OdH8