Chapter 8 - TextureMapping
Chapter 8 - TextureMapping
COMPUTER GRAPHICS
Texture mapping
Texture coordinates
Object coordinates
Texture coordinates
We need:
- Texture coordinates
- Object Coordinate
Object coordinates
Texture coordinates
positionsBox = [ textureCoordinates = [
// Front face // Front face
-1.0, -1.0, 1.0, 0.0, 0.0,
1.0, -1.0, 1.0, 1.0, 0.0,
1.0, 1.0, 1.0, 1.0, 1.0,
-1.0, 1.0, 1.0, 0.0, 1.0,
]; ];
Object coordinates
Texture coordinates
positionsBox = [ textureCoordinates = [
// Front face // Front face
-1.0, -1.0, 1.0, 0.0, 0.0,
1.0, -1.0, 1.0, 1.0, 0.0,
1.0, 1.0, 1.0, 1.0, 1.0,
-1.0, 1.0, 1.0, 0.0, 1.0,
]; ];
Object coordinates
Object coordinates Texture coordinates
]; ];
Complex object
Pseudo-code for texture mapping
Begin
Define vertex shader
Declare texture coordinates and model view matrix
Define fragment shader
Declare fragment color for the textured object
Call function for vertex shader and fragment shader
Define program information to pass to the shader function
Create model view matrix for the texture object
Translate matrix and coordinate
Call function to load 2D image file
Set coordinate for the object surface
Call buffer function
Call function to draw the textured object by passing values of model view
matrix,object location and buffer
End
How to implement texture mapping in webgl