418382...
DESCRIPTION
418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5. ประมุข ขันเงิน [email protected]. TEXTURE MAPPING. Textures. Texture Object An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/1.jpg)
418382 สภาพแวดล้อมการทำ�างานคอมพ�วเตอร�กราฟิ�กส�
การบรรยายคร��งทำ�� 5 ประม!ข ข�นเง�น
![Page 2: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/2.jpg)
![Page 3: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/3.jpg)
![Page 4: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/4.jpg)
![Page 5: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/5.jpg)
![Page 6: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/6.jpg)
![Page 7: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/7.jpg)
![Page 8: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/8.jpg)
![Page 9: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/9.jpg)
![Page 10: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/10.jpg)
![Page 11: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/11.jpg)
![Page 12: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/12.jpg)
![Page 13: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/13.jpg)
![Page 14: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/14.jpg)
![Page 15: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/15.jpg)
![Page 16: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/16.jpg)
![Page 17: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/17.jpg)
![Page 18: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/18.jpg)
![Page 19: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/19.jpg)
![Page 20: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/20.jpg)
![Page 21: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/21.jpg)
![Page 22: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/22.jpg)
![Page 23: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/23.jpg)
![Page 24: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/24.jpg)
![Page 25: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/25.jpg)
![Page 26: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/26.jpg)
![Page 27: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/27.jpg)
![Page 28: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/28.jpg)
![Page 29: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/29.jpg)
![Page 30: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/30.jpg)
![Page 31: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/31.jpg)
![Page 32: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/32.jpg)
![Page 33: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/33.jpg)
TEXTURE MAPPING
![Page 34: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/34.jpg)
![Page 35: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/35.jpg)
![Page 36: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/36.jpg)
![Page 37: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/37.jpg)
![Page 38: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/38.jpg)
![Page 39: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/39.jpg)
![Page 40: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/40.jpg)
![Page 41: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/41.jpg)
![Page 42: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/42.jpg)
![Page 43: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/43.jpg)
![Page 44: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/44.jpg)
![Page 45: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/45.jpg)
Textures
Texture Object
• An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them
• Provides efficiency gains over having to repeatedly load and reload a texture
• You can prioritize textures to keep in memory
• OpenGL uses least recently used (LRU) if no priority is assigned
Texture Object
• An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them
• Provides efficiency gains over having to repeatedly load and reload a texture
• You can prioritize textures to keep in memory
• OpenGL uses least recently used (LRU) if no priority is assigned
![Page 46: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/46.jpg)
Step 1 – create Texture Objects
glGenTextures(1, &texture[texture_num]); • First argument tells GL how many Texture
Objects to create
• Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates
– texture[ ] is of type GLuint
glGenTextures(1, &texture[texture_num]); • First argument tells GL how many Texture
Objects to create
• Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates
– texture[ ] is of type GLuint
![Page 47: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/47.jpg)
Step 2 – Specify which texture object is about to be defined
Tell OpenGL that you are going to define the specifics of the Texture Object it created• glBindTexture(GL_TEXTURE_2D, texture[texture_num]);
–Textures can be 1D and 3D as well
Tell OpenGL that you are going to define the specifics of the Texture Object it created• glBindTexture(GL_TEXTURE_2D, texture[texture_num]);
–Textures can be 1D and 3D as well
![Page 48: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/48.jpg)
Step 3 – Begin defining texture
glTexParameter()
• Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture object
• // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
• // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameter()
• Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture object
• // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
• // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
![Page 49: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/49.jpg)
Step 4 – Assign image data
• glTexImage2D();• glTexImage2D();
GL_TEXTURE_2D (2D Texture)
0 (level of detail 0)
3 (3 components, RGB)
image1->sizeX (size)
image1->sizeY (size)
0 (no border pixel)
GL_RGB (RGB color order)
GL_UNSIGNED_BYTE (unsigned byte data)
image1->data (pointer to the data))
![Page 50: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/50.jpg)
glTexImage2D – Arg 1
GLenum target• GL_TEXTURE_{1|2|3}D
• GL_PROXY_TEXTURE_2D
–Provides queries for texture resources
–Proceed with hypothetical texture use (GL won’t apply the texture)
–After query, call GLGetTexLevelParamter to verify presence of required system components
–Doesn’t check possibility of multiple texture interference
GLenum target• GL_TEXTURE_{1|2|3}D
• GL_PROXY_TEXTURE_2D
–Provides queries for texture resources
–Proceed with hypothetical texture use (GL won’t apply the texture)
–After query, call GLGetTexLevelParamter to verify presence of required system components
–Doesn’t check possibility of multiple texture interference
![Page 51: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/51.jpg)
glTexImage2D – Arg 2
GLint level• Used for Level of Detail (LOD)
• LOD stores multiple versions of texture that can be used at runtime (set of sizes)
• Runtime algorithms select appropriate version of texture
–Pixel size of polygon used to select best texture
–Eliminates need for error-prone filtering algorithms
GLint level• Used for Level of Detail (LOD)
• LOD stores multiple versions of texture that can be used at runtime (set of sizes)
• Runtime algorithms select appropriate version of texture
–Pixel size of polygon used to select best texture
–Eliminates need for error-prone filtering algorithms
![Page 52: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/52.jpg)
glTexImage2D – Arg 3
GLint internalFormat• GL defines 38 symbolic constants that describe
which of R, G, B, and A are used in internal representation of texels
• Provides control over things texture can do
–High bit depth alpha blending
–High bit depth intensity mapping
–General purpose RGB
• GL doesn’t guarantee all options are available on given hardware
GLint internalFormat• GL defines 38 symbolic constants that describe
which of R, G, B, and A are used in internal representation of texels
• Provides control over things texture can do
–High bit depth alpha blending
–High bit depth intensity mapping
–General purpose RGB
• GL doesn’t guarantee all options are available on given hardware
![Page 53: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/53.jpg)
glTexImage2D – Args 4-6
GLsizei width
GLsizei height• Dimensions of texture image
– Must be 2m + 2b (b=0 or 1 depending on border)
– min, 64 x 64
GLint border• Width of border (1 or 0)
– Border allows linear blending between overlapping textures
– Useful when manually tiling textures
GLsizei width
GLsizei height• Dimensions of texture image
– Must be 2m + 2b (b=0 or 1 depending on border)
– min, 64 x 64
GLint border• Width of border (1 or 0)
– Border allows linear blending between overlapping textures
– Useful when manually tiling textures
![Page 54: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/54.jpg)
glTexImage2D – Args 7 & 8
GLenum format• Describe how texture data is stored in input array
–GL_RGB, GL_RGBA, GL_BLUE…
GLenum type • Data size of array components
–GL_SHORT, GL_BYTE, GL_INT…
GLenum format• Describe how texture data is stored in input array
–GL_RGB, GL_RGBA, GL_BLUE…
GLenum type • Data size of array components
–GL_SHORT, GL_BYTE, GL_INT…
![Page 55: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/55.jpg)
glTexImage2D – Arg 9
Const GLvoid *texels• Pointer to data describing texture map
Const GLvoid *texels• Pointer to data describing texture map
![Page 56: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/56.jpg)
Step 5 – Apply texture
Before defining geometry• glEnable(GL_TEXTURE_2D);
• glBindTexture(GL_TEXTURE_2D, texture[0]);
• glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
Before defining geometry• glEnable(GL_TEXTURE_2D);
• glBindTexture(GL_TEXTURE_2D, texture[0]);
• glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
![Page 57: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/57.jpg)
glTexEnv()
GL_TEXTURE_ENV_MODE GL_DECAL (alpha blends texture with poly color)
GL_REPLACE (straight up replacement)
GL_MODULATE (texture application is a function of poly lighting)
GL_BLEND (texture controls blending with another color)
If GL_BLEND selected, second call to glTexEnv() must specify GL_TEXTURE_ENV_COLOR
4-float array for R,G,B,A blend
First argument to function is always GL_TEXTURE_ENV
![Page 58: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/58.jpg)
![Page 59: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/59.jpg)
![Page 60: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/60.jpg)
![Page 61: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/61.jpg)
![Page 62: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/62.jpg)
![Page 63: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/63.jpg)
MIPMAPPING
![Page 64: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/64.jpg)
![Page 65: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/65.jpg)
![Page 66: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/66.jpg)
![Page 67: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/67.jpg)
![Page 68: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/68.jpg)
![Page 69: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/69.jpg)
![Page 70: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/70.jpg)
![Page 71: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/71.jpg)
![Page 72: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/72.jpg)
![Page 73: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/73.jpg)
![Page 74: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/74.jpg)
![Page 75: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/75.jpg)
MIPMAPS
With versus without MIPMAPWith versus without MIPMAP
![Page 76: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/76.jpg)
FilteringOpenGL tries to pick best mipmap level
Question: Which texel corresponds to a particular pixel?
GL_NEAREST (Point Sampling)• Pick the texel with center nearest pixel
GL_LINEAR (Bilinear Sampling)• Weighted average of 2x2 closest texels
GL_NEAREST_MIPMAP_LINEAR• Average nearest texels from two mipmap levels
GL_LINEAR_MIPMAP_LINEAR (Trilinear)• Average two averaged texels from two mipmaps
OpenGL tries to pick best mipmap level
Question: Which texel corresponds to a particular pixel?
GL_NEAREST (Point Sampling)• Pick the texel with center nearest pixel
GL_LINEAR (Bilinear Sampling)• Weighted average of 2x2 closest texels
GL_NEAREST_MIPMAP_LINEAR• Average nearest texels from two mipmap levels
GL_LINEAR_MIPMAP_LINEAR (Trilinear)• Average two averaged texels from two mipmaps
![Page 77: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/77.jpg)
DEVIL
![Page 78: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/78.jpg)
DevIL
• เป#นไล้บราร�ส�าหร�บอ&านแล้ะเข�ยนไฟิล้�ร'ปภาพต&างๆ– นามสก!ล้ .jpg, .png, .tiff, ฯล้ฯ
• ต�ดต&อก�บ OpenGL ไดด�• ดาวน�โหล้ด
– http://openil.sourceforge.net– DevIL 1.7.8 SDK for 32-bit Windows
• Unzip แล้ว– น�าไฟิล้� .dll ไปใส&ไวใน bin ของทำ��ไวไฟิล้�ส�าหร�บ CMake– น�าไฟิล้� .lib ไปใส&ไวใน lib ของทำ��ไวไฟิล้�ส�าหร�บ CMake– น�าไฟิล้� .h ต&างๆ ไปใส&ไวใน include/IL ของทำ��ไวไฟิล้�ส�าหร�บ CMake
![Page 79: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/79.jpg)
ไฟิล้�ทำ��ตอง include
• ส��ง– #include <IL/il.h>– #include <IL/ilu.h>– #include <IL/ilut.h>ไวทำ��ห�วโปรแกรม
![Page 80: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/80.jpg)
ฟิ,งก�ชั�น init ต&างๆ• ม�ไวเพ��อให DevIL ทำ��งค&าเร��มตนของตนเอง• ในฟิ,งก�ชั�น main ส��ง
– ilInit();– iluInit();
ก&อนเร�ยกฟิ,งก�ชั�นอ.�นๆ ทำ��งหมด• แล้วเร�ยก
– ilutInit(); หล้�งเร�ยก glutInit(…);
![Page 81: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/81.jpg)
Image Object
• DevIL “ ” ม�ระบบ ร'ป คล้ายก�บระบบ texture ของOpenGL– สรางดวย ilGenImages– ก�าหนดดวย ilBindImage– อ&านร'ปจากไฟิล้�ดวย ilLoadImage– ล้บดวย ilDeleteImages
![Page 82: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/82.jpg)
ilGenImages
• ILvoid ilGenImages( ILsizei Num, ILuint *ids);– สราง image object หล้ายๆ อ�น– argument แรกค.อจ�านวน image object ทำ��ตองการสราง– argument “ ” ทำ��สองค.ออะไรส�าหร�บใส& ชั.�อ ของ image object– การสราง image object เพ�ยงแค&อ�นเด�ยว
• ILuint id;• ilGenImages(1, &id);
– การสราง image object หล้ายอ�น• ILuint id[3];• ilGenImages(3, id);
![Page 83: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/83.jpg)
ilBindImage
• ILvoid ilBindImage(ILuint id)– ใชัเซต image object ป,จจ!บ�นใหเป#น image object ทำ��
ม�ชั.�อทำ��ก�าหนด– ต�วอย&าง
• ILuint id;• ilGenImages(1, &id);• ilBindImage(id);
![Page 84: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/84.jpg)
ilLoadImage
• ILboolean ilLoadImage(const char *FileName)– ใชัส�าหร�บอ&านร'ปจากไฟิล้�ทำ��ก�าหนดชั.�อใหมาย�ง image object
ป,จจ!บ�นทำ�� bind ไวแล้ว– argument แรกค.อชั.�อไฟิล้�
• DevIL จะร' ว&าเป#นไฟิล้�ชัน�ดใดโดยอ�ตโนม�ต�– “ ” “ ” ค.นค&า จร�ง ถ้าสามารถ้อ&านร'ปไดแล้ะค.นค&า เทำ2จ ถ้าอ&านไม&
ส�าเร2จ– ต�วอย&าง
• ILuint id;• ilGenImages(1, &id);• ilBindImage(id);• ilLoadImage(“test.jpg”);
![Page 85: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/85.jpg)
ilDeleteImages
• ILvoid ilDeleteImages( ILsizei Num, ILuint *ids);– ล้บ image object หล้ายๆ อ�น– argument แรกค.อจ�านวน image object ทำ��ตองการล้บ– argument “ ” ทำ��สองค.ออะไรส�าหร�บใส& ชั.�อ ของ image object– การล้บ image object เพ�ยงแค&อ�นเด�ยว
• ILuint id;• …• ilDeleteImages(1, &id);
– การสราง image object หล้ายอ�น• ILuint id[3];• ilGenImages(3, id);• …• ilDeleteImages(3, id);
![Page 86: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/86.jpg)
ilConvertImage
• ILboolean ilConvertImage( ILenum DestFormat, ILenum DestType )– ใชัส�าหร�บแปล้งขอม'ล้ร'ปภาพทำ��อย'&ในภาพทำ�� bind ไวเป#นร'ปแบบ
อ.�น– DestFormat ค.อร'ปแบบส�ของแต&ล้ะ pixel
• IL_RGB, IL_RGBA, IL_BGR, IL_BGRA, IL_LUMINANCE, IL_COLOUR_INDEX
– DestType ค.อชัน�ดขอม'ล้ทำ��ใชัเก2บส�แต&ล้ะชั&อง• IL_BYTE, IL_UNSIGNED_BYTE, IL_SHORT , IL_UNSIGNED_SHORT,
IL_INT, IL_UNSIGNED_INT, IL_FLOAT, IL_DOUBLE
![Page 87: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/87.jpg)
การส&งขอม'ล้ร'ปภาพเขา OpenGL Texture
• เร�ยก glTexImage2D โดยใหขอม'ล้ต&างๆ จากImage Object– internalFormat ใหป3อน
ilGetInteger(IL_IMAGE_BPP)– width ใหป3อน ilGetInteger(IL_IMAGE_WIDTH)– height ใหป3อน ilGetInteger(IL_IMAGE_HEIGHT)– format ใหป3อน ilGetInteger(IL_IMAGE_FORMAT)– type ใหป3อน ilGetInteger(IL_IMAGE_TYPE)– data ใหป3อน ilGetData()
![Page 88: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/88.jpg)
ilGetData
• ILubyte* ilGetData(ILvoid)– ค.นขอม'ล้ของ image object ทำ�� bind ไวเป#นอะเรย�ของ
unsigned byte
![Page 89: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่ 5](https://reader034.vdocuments.site/reader034/viewer/2022051218/56815757550346895dc50136/html5/thumbnails/89.jpg)
ต�วอย&างการใชังานglGenTextures(1, &tex0);glBindTexture(GL_TEXTURE_2D, tex0);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
ILuint image0;ilGenImages(1, &image0);ilBindImage(image0);char imageName[] = "../../data/yellow-flowers.jpg";ilLoadImage(imageName);ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
gluBuild2DMipmaps(GL_TEXTURE_2D, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT),
ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_TYPE), ilGetData());
ilDeleteImages(1, &image0);