418382...

89
418382 สสสสสสสสสสสสสส สสสสสสสสสสสสสสสสสสสสสสส สส สสสสสสสสสสสสสสสสส 5 สสสสสส สสสสสสส [email protected]

Upload: aricin

Post on 29-Jan-2016

56 views

Category:

Documents


0 download

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 Presentation

TRANSCRIPT

Page 1: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

418382 สภาพแวดล้อมการทำ�างานคอมพ�วเตอร�กราฟิ�กส�

การบรรยายคร��งทำ�� 5 ประม!ข ข�นเง�น

[email protected]

Page 2: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 3: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 4: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 5: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 6: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 7: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 8: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 9: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 10: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 11: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 12: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 13: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 14: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 15: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 16: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 17: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 18: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 19: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 20: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 21: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 22: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 23: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 24: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 25: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 26: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 27: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 28: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 29: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 30: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 31: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 32: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 33: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

TEXTURE MAPPING

Page 34: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 35: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 36: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 37: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 38: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 39: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 40: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 41: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 42: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 43: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 44: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 45: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

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

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

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

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

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

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

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

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

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

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

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

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

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
Page 59: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 60: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 61: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 62: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 63: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

MIPMAPPING

Page 64: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 65: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 66: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 67: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 68: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 69: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 70: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 71: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 72: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 73: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 74: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5
Page 75: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

MIPMAPS

With versus without MIPMAPWith versus without MIPMAP

Page 76: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

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

DEVIL

Page 78: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

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

ไฟิล้�ทำ��ตอง include

• ส��ง– #include <IL/il.h>– #include <IL/ilu.h>– #include <IL/ilut.h>ไวทำ��ห�วโปรแกรม

Page 80: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

ฟิ,งก�ชั�น init ต&างๆ• ม�ไวเพ��อให DevIL ทำ��งค&าเร��มตนของตนเอง• ในฟิ,งก�ชั�น main ส��ง

– ilInit();– iluInit();

ก&อนเร�ยกฟิ,งก�ชั�นอ.�นๆ ทำ��งหมด• แล้วเร�ยก

– ilutInit(); หล้�งเร�ยก glutInit(…);

Page 81: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

Image Object

• DevIL “ ” ม�ระบบ ร'ป คล้ายก�บระบบ texture ของOpenGL– สรางดวย ilGenImages– ก�าหนดดวย ilBindImage– อ&านร'ปจากไฟิล้�ดวย ilLoadImage– ล้บดวย ilDeleteImages

Page 82: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

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

ilBindImage

• ILvoid ilBindImage(ILuint id)– ใชัเซต image object ป,จจ!บ�นใหเป#น image object ทำ��

ม�ชั.�อทำ��ก�าหนด– ต�วอย&าง

• ILuint id;• ilGenImages(1, &id);• ilBindImage(id);

Page 84: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

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

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

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

การส&งขอม'ล้ร'ปภาพเขา 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

ilGetData

• ILubyte* ilGetData(ILvoid)– ค.นขอม'ล้ของ image object ทำ�� bind ไวเป#นอะเรย�ของ

unsigned byte

Page 89: 418382 สภาพแวดล้อมการทำงานคอมพิวเตอร์กราฟิกส์ การบรรยายครั้งที่  5

ต�วอย&างการใชังาน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);