บทที่ 5 texture mapping
DESCRIPTION
บทที่ 5 Texture Mapping. Texture Mapping. ทำได้ 2 วิธี - Surface detail polygons: กำหนด Polygon แต่ละตัวตามสีที่ต้องการ - ถ้าภาพที่ต้องการซับซ้อน Speed down! - รูปบางอย่างสร้างยาก(หาโมเดลไม่ได้) Map a texture to the surface ( ใช้ทั่วไป ). - PowerPoint PPT PresentationTRANSCRIPT
บทท�� บทท�� 5 Texture Mapping5 Texture Mappingบทท�� บทท�� 5 Texture Mapping5 Texture Mapping
Texture MappingTexture Mapping
• ท��ได้ 2 วิ�ธี�- Surface detail polygons: กำ��หนด้ Polygon
แต่�ละต่�วิต่�มสี�ท��ต่องกำ�ร- ถ้�ภ�พท��ต่องกำ�รซั�บซัอน Speed down!- ร ปบ�งอย่��งสีร�งย่�กำ(ห�โมเด้ลไม�ได้)
Map a texture to the surface (ใช้ท��วิไป)
ความซั�บซั�อนของภาพไม�ม�ผลต่�อการจั�ดการทางเรขาคณิ�ต่ (transformation, clipping…)
2
Texture MappingTexture Mapping
– เทคโนโลยี�ท��เอาภาพ(image)ไปแปะบนพ#$นผ�วของว�ต่ถุ&– ไม�ต่�องท'าModelingให้�ซั�บซั�อนแต่�ก*สร�างภาพท��ด,แล�ว
เห้ม#อนจัร�งได�
3
Texture MappingTexture Mapping
S
t
3D geometry
2D image
2D projection of 3D geometry
1. projection
2. texture lookup
3. patch texel
4
Bump MappingBump Mapping
5
MappingMapping
6
Environment MappingEnvironment Mapping
7
8
Texture MappingTexture Mapping
=
+
9
+ =
10
ต่�วิอย่��งต่�วิอย่��ง• เอาภาพมาแปะท��ต่�วคน
s
t
11
Map textures to surfaces Map textures to surfaces
(0,0) (1,0)
(1,0) (1,1)
12
TextureTexture
• Texture = Texture = ข้อม ลข้อง ข้อม ลข้อง pixelpixelท��บ�นท(กำไวิในร ปท��บ�นท(กำไวิในร ปแบบข้อง แบบข้อง arrayarray
• PixelPixelข้องข้อง texturetextureเร�เร�ย่กำวิ��เร�เร�ย่กำวิ�� “ “texteltextel””
• Texture coordinate: Texture coordinate: (s,t)(s,t)
• (s,t):(s,t): s s และ และ t t จะม�ค่�� จะม�ค่�� 0~10~1
13
Texture Representation Texture Representation
Bitmap (pixel map) textures (supported by OpenGL)
Bitmap texture: เป-นภาพ2ม�ต่�แสดงได�ด�วยี 2D array texture[height][width] แต่�ละเซั*ล (texel ) จัะม�ค,�ก�บจั&ด texture coordinate (s, t) s=[0,1], t=[0,1]
s
t
(0,0)
(1,1)
14
Texture MappingTexture MappingTexture MappingTexture Mapping
ss
tt400400
600600
texel[j][k]: texel[j][k]: เกำ+บข้อม ลสี�ข้อง เกำ+บข้อม ลสี�ข้อง texturetexture j:0~599, k:0~399j:0~599, k:0~399
15
Texture MappingTexture MappingTexture MappingTexture Mapping
ss
tt
texture(0,0)texture(0,0)texel[0][0]texel[0][0]texture(0,1)texture(0,1)texel[0][399]texel[0][399]texture(1,0)texture(1,0)texel[599][0]texel[599][0]texture(1,1)texture(1,1)texel[599][399]texel[599][399]
400400
600600
Color3 texture(float Color3 texture(float ss,float ,float tt){){ return texel[(int)return texel[(int)s*Ws*W][(int)][(int)t*Ht*H];];}}
texture(0.261,0.783)texture(0.261,0.783)texel[156][313]texel[156][313]
16
Texture MappingTexture MappingTexture MappingTexture Mapping
• กำ�รเอ�ภ�พกำ�รเอ�ภ�พ(image)(image)ไปแปะบนไปแปะบน polygonpolygon
ss
tt
xx
yy
zzxxss
yyss
17
Texture MappingTexture MappingTexture MappingTexture Mapping
ss
tt
xx
yy
zzxxss
yysstwT wsT
)),((),( tsTTyx twwsss
)),((),( 11sswstw yxTTts
18
Texture MappingTexture MappingTexture MappingTexture Mapping
ss
tt(1,1)(1,1)
yyss
xxss
(1,1)(1,1) s = xs = xss
t = yt = yss
ss
tt(1,1)(1,1)
yyss
xxss
(3/2,1)(3/2,1)
s = 2xs = 2xss /3 /3
t = yt = yss
19
Texture Texture ComponentComponent
Texture Texture ComponentComponent
• 1 component texture: 1 component texture:
จะแสีด้งค่วิ�มสีวิ��งข้องแสีงเท��น�,น เช้�น ไม จะแสีด้งค่วิ�มสีวิ��งข้องแสีงเท��น�,น เช้�น ไม สีน�มหญ้� ห�ด้ทร�ย่ข้�วิสีน�มหญ้� ห�ด้ทร�ย่ข้�วิ
20
Texture Texture ComponentComponent
Texture Texture ComponentComponent
• 22 component texture: component texture:
จะแสีด้งค่วิ�มสีวิ��งข้องแสีงและค่วิ�มโปร�งใสีจะแสีด้งค่วิ�มสีวิ��งข้องแสีงและค่วิ�มโปร�งใสี เช้�น เมฆเช้�น เมฆ
21
Texture Texture ComponentComponent
Texture Texture ComponentComponent
3 3 component texture: component texture:
จะแสีด้งสี�ข้องแสีงจะแสีด้งสี�ข้องแสีง(RGB)(RGB)
22
Texture Texture ComponentComponent
Texture Texture ComponentComponent
44 component texture: component texture:
จะแสีด้งสี�ข้องแสีงและค่��ค่วิ�มจะแสีด้งสี�ข้องแสีงและค่��ค่วิ�มโปร�งใสีโปร�งใสี(RGBA)(RGBA)
23
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้องTextureTexture
Texture SetupTexture Setup กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้องTextureTexture
Texture SetupTexture Setup GLvoid glTexImage2D(Glenum GLvoid glTexImage2D(Glenum targettarget,GLint ,GLint levellevel,GLint components,,GLint components,
GLsizei width,GLsizei height,GLint GLsizei width,GLsizei height,GLint border,GLenum format,border,GLenum format,
GLenum type,const GLvoid *image);GLenum type,const GLvoid *image);
targettarget
เป0นเป0น GL_TEXTURE_2DGL_TEXTURE_2D
level(mipmap level(mipmap level)level)
0: 0: ภ�พท��เป0น ภ�พท��เป0น original original
i: i: ภ�พภ�พ mipmap mipmap ล��ด้�บล��ด้�บท�� ท�� ii
24
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
GLvoid glTexImage2D(Glenum target,GLint level,GLint GLvoid glTexImage2D(Glenum target,GLint level,GLint componentscomponents,, GLsizei GLsizei widthwidth,GLsizei ,GLsizei heightheight,GLint ,GLint
bordeborder,GLenum format,r,GLenum format,
GLenum type,const GLvoid *image);GLenum type,const GLvoid *image);
ComponentComponent(1~4)(1~4) WidthWidth(2^m)(2^m) HeightHeight(2^n)(2^n) BorderBorder(0 or 1)(0 or 1)
25
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
GLvoid glTexImage2D(Glenum target,GLint level,GLint components,GLvoid glTexImage2D(Glenum target,GLint level,GLint components, GLsizei width,GLsizei height,GLint GLsizei width,GLsizei height,GLint
border,GLenum border,GLenum formatformat,,
GLenum GLenum typetype,const GLvoid ,const GLvoid *image*image););
Format Format เช้�น เช้�น GL_RGB,GL_RGBAGL_RGB,GL_RGBA type type ประเภทข้อง ประเภทข้อง texel texel เช้�นเช้�น
GL_BYTEGL_BYTE,,GL_UNSIGNED_BYTEGL_UNSIGNED_BYTE ImageImage
ภ�พท��จะน��ม�ท��เป0นภ�พท��จะน��ม�ท��เป0น texturetexture ม�ข้น�ด้ม�ข้น�ด้ 2^m x 2^m x 2^n2^n 26
Generate TextureGenerate TextureGenerate TextureGenerate Texture#define ImageWidth 8#define ImageWidth 8
#define ImageHeight 8#define ImageHeight 8
static Glubyte textureImage1[ Width][ Height][ static Glubyte textureImage1[ Width][ Height][ 44];];
void generateTexture1() {void generateTexture1() {
int i, j, c;int i, j, c;
for (i= 0; i< ImageWidth; i++)for (i= 0; i< ImageWidth; i++)
for (j= 0; j< ImageHeight; j++) {for (j= 0; j< ImageHeight; j++) {
c = (( i& 0x8)^( j& 0x8)) * 255;c = (( i& 0x8)^( j& 0x8)) * 255;
textureImage1textureImage1[ i][ j][ 0] = (GLubyte) [ i][ j][ 0] = (GLubyte) c;c;
textureImage1textureImage1[ i][ j][ 1] = (GLubyte) [ i][ j][ 1] = (GLubyte) c;c;
textureImage1textureImage1[ i][ j][ 2] = (GLubyte) [ i][ j][ 2] = (GLubyte) c; c;
textureImage1textureImage1[ i][ j][ 3] = 255;}[ i][ j][ 3] = 255;}
}}
}}
}}
27
Generate TextureGenerate TextureGenerate TextureGenerate Texture
R0R0 G0G0 B0B0 A0A0 R1R1 G1G1 B1B1 A1A1 R2R2 G2G2 B2B2 A2A2 R3R3 G3G3 B3B3 A3A3
R0R0 G0G0 B0B0 R1R1 G1G1 B1B1 R2R2 G2G2 B2B2 R3R3 G3G3 B3B3
3 component texture3 component texture
4 component texture4 component texture
28
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
กำ�รกำ��หนด้ค่��ต่��งๆข้องกำ�รกำ��หนด้ค่��ต่��งๆข้อง TextureTexture
glTexImage2D( GL_ TEXTURE_ 2D, 0, 4, Width, Height,0,glTexImage2D( GL_ TEXTURE_ 2D, 0, 4, Width, Height,0,
GL_ RGBA, GL_ UNSIGNED_ GL_ RGBA, GL_ UNSIGNED_ BYTE,BYTE,textureImage1textureImage1
););
29
Texture ObjectTexture ObjectTexture ObjectTexture Object
GLuint textureID;GLuint textureID;
glGenTextures(glGenTextures(11, &textureID);, &textureID);
glBindTexture(GL_TEXTURE_2D, textureID);glBindTexture(GL_TEXTURE_2D, textureID);
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D, ……););
glBindTexture(GL_TEXTURE_2D, textureID);glBindTexture(GL_TEXTURE_2D, textureID); เร�ย่กำใช้เร�ย่กำใช้ texture texture ช้1�อช้1�อ textureIDtextureID
กำ��หนด้ค่��ต่��งๆเช้�น กำ��หนด้ค่��ต่��งๆเช้�น format format ……
สีร�ง สีร�ง texture objecttexture object
จ��นวิน จ��นวิน texture object texture object ม� ม� 11 อ�น ม� อ�น ม� ID ID ค่1อค่1อ??
30
Texture ParameterTexture ParameterTexture ParameterTexture Parameter
void glTexParameteri( GLenum target,GLenum pname,TYPE void glTexParameteri( GLenum target,GLenum pname,TYPE param );param );
target :target :
GL_ TEXTURE_ WRAP_ SGL_ TEXTURE_ WRAP_ S
GL_ TEXTURE_ WRAP_ TGL_ TEXTURE_ WRAP_ T
GL_ TEXTURE_ MAG_ FILTERGL_ TEXTURE_ MAG_ FILTER
GL_ TEXTURE_ MIN_ FILTERGL_ TEXTURE_ MIN_ FILTER
GL_ TEXTURE_ BORDER_ COLORGL_ TEXTURE_ BORDER_ COLOR
GL_ TEXTURE_ PRIORITYGL_ TEXTURE_ PRIORITY31
Texture ParameterTexture ParameterTexture ParameterTexture Parameter
MagnificationMagnification MinificationMinification
texturetexturetexturetexturePolygonPolygon
PolygonPolygon
texeltexel
pixelpixel
32
MagnificationMagnificationMagnificationMagnification
ParameterParameter GL_NEARESTGL_NEAREST: : เล1อกำ เล1อกำ texeltexelท��ใกำลท��สี2ด้ท��ใกำลท��สี2ด้ GL_LINEARGL_LINEAR: : ห�ค่��เฉล��ย่ข้องห�ค่��เฉล��ย่ข้อง texel texel รอบๆรอบๆ 4 4 texeltexel
33
MinificationMinificationMinificationMinification
34
MipmapMipmapMipmapMipmap
กำ�รข้ย่�ย่หร1อย่�อข้น�ด้ข้อง กำ�รข้ย่�ย่หร1อย่�อข้น�ด้ข้อง texture texture ท��ใหเกำ�ด้กำ�รกำระพร�บท��ใหเกำ�ด้กำ�รกำระพร�บเวิล� เวิล� reshape reshape
สีร�งสีร�ง texture texture ท��ม�ข้น�ด้หล�ย่ๆข้น�ด้เต่ร�ย่มเอ�ไวิท��ม�ข้น�ด้หล�ย่ๆข้น�ด้เต่ร�ย่มเอ�ไวิ OpenGLOpenGL จะเล�กำใช้จะเล�กำใช้ mipmap mipmap ท��เหม�ะสีมโด้ย่อ�ต่โนม�ต่�ท��เหม�ะสีมโด้ย่อ�ต่โนม�ต่�
35
MipmapMipmapMipmapMipmapGLubyte mipmapImage32[ 32][ 32][ 4];GLubyte mipmapImage32[ 32][ 32][ 4];
GLubyte mipmapImage16[ 16][ 16][ 4];GLubyte mipmapImage16[ 16][ 16][ 4];
GLubyte mipmapImage8[ 8][ 8][ 4];GLubyte mipmapImage8[ 8][ 8][ 4];
GLubyte mipmapImage4[ 4][ 4][ 4];GLubyte mipmapImage4[ 4][ 4][ 4];
GLubyte mipmapImage2[ 2][ 2][ 4];GLubyte mipmapImage2[ 2][ 2][ 4];
GLubyte mipmapImage1[ 1][ 1][ 4];GLubyte mipmapImage1[ 1][ 1][ 4];
void createMipMaps() {void createMipMaps() {
........
}}
36
MipmapMipmapMipmapMipmapvoid createMipMaps() {void createMipMaps() {
........
glTexImage2D( GL_ TEXTURE_ 2D, 0, GL_ RGBA, glTexImage2D( GL_ TEXTURE_ 2D, 0, GL_ RGBA, 3232, , 3232, 0,, 0,
GL_ RGBA, GL_ UNSIGNED_ BYTE,GL_ RGBA, GL_ UNSIGNED_ BYTE,mipmapImmipmapImage32age32););
glTexImage2D( GL_ TEXTURE_ 2D, 1, GL_ RGBA, glTexImage2D( GL_ TEXTURE_ 2D, 1, GL_ RGBA, 1616, , 1616, 0,, 0,
GL_ RGBA, GL_ UNSIGNED_ BYTE,GL_ RGBA, GL_ UNSIGNED_ BYTE,mipmapImagmipmapImage16e16););
glTexImage2D( GL_ TEXTURE_ 2D, 2, GL_ RGBA,glTexImage2D( GL_ TEXTURE_ 2D, 2, GL_ RGBA, 8 8, , 88, 0,, 0,
GL_ RGBA, GL_ UNSIGNED_ BYTE,GL_ RGBA, GL_ UNSIGNED_ BYTE,mipmapImipmapImage8mage8););
........
}}
37
Texture ParameterTexture ParameterTexture ParameterTexture Parameter
(0,0)
(1,1)
texture GL_Repeat
(0,0)
(2,2)
(0,0)
(2,2)
GL_Clamp
If (s >1) s = 1 If (t >1) t = 1
38
Texture ParameterTexture ParameterTexture ParameterTexture Parameter
glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ S,glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ S,GL_ REPEATGL_ REPEAT););
glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ T,glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ T,GL_ REPEATGL_ REPEAT););
glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ S,glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ S,GL_ CLAMPGL_ CLAMP););
glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ T,glTexParameteri( GL_ TEXTURE_ 2D, GL_ TEXTURE_ WRAP_ T,GL_ CLAMPGL_ CLAMP););
39
Texture ParameterTexture ParameterTexture ParameterTexture Parameter
40
กำ�รกำ��หนด้ต่��แหน�งข้องกำ�รกำ��หนด้ต่��แหน�งข้องtexture texture บนบน polygonpolygon
กำ�รกำ��หนด้ต่��แหน�งข้องกำ�รกำ��หนด้ต่��แหน�งข้องtexture texture บนบน polygonpolygon
glBegin( GL_QUADS );glBegin( GL_QUADS );glTexCoord2fv( t0 );glTexCoord2fv( t0 );glVertex3fv( v0 );glVertex3fv( v0 );
glTexCoord2fv( t1 );glTexCoord2fv( t1 );glVertex3fv( v1 );glVertex3fv( v1 );
glTexCoord2fv( t2 );glTexCoord2fv( t2 );glVertex3fv( v2 );glVertex3fv( v2 );
glTexCoord2fv( t3 );glTexCoord2fv( t3 );glVertex3fv( v3 );glVertex3fv( v3 );glEnd();glEnd();
glBegin( GL_QUADS );glBegin( GL_QUADS );glTexCoord2fv(glTexCoord2fv(0.0,0.00.0,0.0 ););glVertex3fvglVertex3fv(-(-2.0,0.0,0.0);2.0,0.0,0.0);
glTexCoord2fv(glTexCoord2fv(1.0,0.01.0,0.0));;glVertex3fv(glVertex3fv(0.0,-0.0,-2.0,0.02.0,0.0););
glTexCoord2fv(glTexCoord2fv(1.0,1.01.0,1.0));;glVertex3fv(glVertex3fv(2.0,0.0,0.2.0,0.0,0.0);0);
glTexCoord2fv(glTexCoord2fv(0.0,1.00.0,1.0));;glVertex3fv(glVertex3fv(0.0,2.0,0.0.0,2.0,0.00););glEnd();glEnd();
41
TextureTextureVertexVertexTextureTextureVertexVertex
glBegin( GL_ QUADS);glBegin( GL_ QUADS);
glTexCoord2d( 0. 0, 0.0 ); glTexCoord2d( 0. 0, 0.0 ); glVertex3d( x0, y0, z0 );glVertex3d( x0, y0, z0 );
glTexCoord2d( 1. 0, 0.0 ); glTexCoord2d( 1. 0, 0.0 ); glVertex3d( x1, y1, z1 );glVertex3d( x1, y1, z1 );
glTexCoord2d( 1. 0, 1.0 ); glTexCoord2d( 1. 0, 1.0 ); glVertex3d( x2, y2, z2 );glVertex3d( x2, y2, z2 );
glTexCoord2d( 0. 0, 1.0 ); glTexCoord2d( 0. 0, 1.0 ); glVertex3d( x3, y3, z3 );glVertex3d( x3, y3, z3 );
glEnd();glEnd(); 42
TextureTextureVertexVertexTextureTextureVertexVertex
glBegin( GL_ QUADS);glBegin( GL_ QUADS);
glTexCoord2d( 0. 0, 0. 0 ); glVertex3d( x0, y0, glTexCoord2d( 0. 0, 0. 0 ); glVertex3d( x0, y0, z0 );z0 );
glTexCoord2d( 1. 0, 0. 0 ); glVertex3d( x1, y1, glTexCoord2d( 1. 0, 0. 0 ); glVertex3d( x1, y1, z1 );z1 );
glTexCoord2d( 1. 0, 1. 0 ); glVertex3d( x2, y2, glTexCoord2d( 1. 0, 1. 0 ); glVertex3d( x2, y2, z2 );z2 );
glTexCoord2d( 0. 0, 1. 0 ); glVertex3d( x3, y3, glTexCoord2d( 0. 0, 1. 0 ); glVertex3d( x3, y3, z3 );z3 );
glEnd();glEnd();
glBegin( GL_ QUADS);glBegin( GL_ QUADS);
glTexCoord2d( 0. 0, 0. 0 ); glVertex3d( x0, y0, glTexCoord2d( 0. 0, 0. 0 ); glVertex3d( x0, y0, z0 );z0 );
glTexCoord2d( 4. 0, 0. 0 ); glVertex3d( x1, y1, glTexCoord2d( 4. 0, 0. 0 ); glVertex3d( x1, y1, z1 );z1 );
glTexCoord2d( 4. 0, 4. 5 ); glVertex3d( x2, y2, glTexCoord2d( 4. 0, 4. 5 ); glVertex3d( x2, y2, z2 );z2 );
glTexCoord2d( 0. 0, 4. 5 ); glVertex3d( x3, y3, glTexCoord2d( 0. 0, 4. 5 ); glVertex3d( x3, y3, z3 );z3 );
glEnd();glEnd();
43
Enable (Disable) TexturesEnable (Disable) Textures
• Enable texture – glEnable(GL_TEXTURE_2D)
• Disable texture – glDisable(GL_TEXTURE_2D)
44
Put it all together Put it all together
…
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_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
…
glEnable(GL_TEXTURE_2D);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB,
GL_UNSIGNED_BYTE, mytexture);
Draw_picture1(); // define texture coordinates and vertices in the function
….
45
Display ListDisplay ListDisplay ListDisplay List
• กำอนค่��สี��งท�งกำร�ฟฟ5กำกำอนค่��สี��งท�งกำร�ฟฟ5กำ• เกำ+บเอ�ไวิในเกำ+บเอ�ไวิใน memorymemory• จะเสี�ย่เวิล�น�นน�ด้น(งในกำ�รสีร�งจะเสี�ย่เวิล�น�นน�ด้น(งในกำ�รสีร�ง display listdisplay list• กำ�รเรนเด้อร6ภ�พจะเร+วิข้(,นม�กำกำ�รเรนเด้อร6ภ�พจะเร+วิข้(,นม�กำ
46
Display List ModelDisplay List ModelDisplay List ModelDisplay List Model
glBegin(GL_LINES);glBegin(GL_LINES);glVertex(glVertex(……););……..glEnd();glEnd();
Display ListDisplay ListDisplay ListDisplay List
เร�ย่กำใช้ค่��สี�,งวิ�ด้ภ�พท��เร�ย่กำใช้ค่��สี�,งวิ�ด้ภ�พท��เกำ+บไวิในเกำ+บไวิใน display listdisplay list
47
ค่2ณสีมบ�ต่�ข้องค่2ณสีมบ�ต่�ข้อง display display listlist
ค่2ณสีมบ�ต่�ข้องค่2ณสีมบ�ต่�ข้อง display display listlist
• เร+วิเพร�ะไม�ต่องเสี�ย่เวิล�ค่��นวิณใหม�เร+วิเพร�ะไม�ต่องเสี�ย่เวิล�ค่��นวิณใหม�• สี�บเปล��ย่นสี�บเปล��ย่น texturetexture หล�ย่ๆแบบได้หล�ย่ๆแบบได้• ออกำแบบโมเด้ลท��ม�ค่วิ�มสี�มพ�นธี6แบบ ออกำแบบโมเด้ลท��ม�ค่วิ�มสี�มพ�นธี6แบบ Tree Tree ได้ได้
48
วิ�ธี�กำ�รสีร�ง วิ�ธี�กำ�รสีร�ง Display Display ListList
วิ�ธี�กำ�รสีร�ง วิ�ธี�กำ�รสีร�ง Display Display ListList
Gluint glGenLists(int count);Gluint glGenLists(int count);• สีร�งและกำ��หนด้ช้1�อสีร�งและกำ��หนด้ช้1�อ display listdisplay list• ค่1นค่1น ID(ID(ช้1�อช้1�อ))• count count ค่1อจ��นวินข้องค่1อจ��นวินข้อง display listdisplay list ท��ต่องกำ�รสีร�งท��ต่องกำ�รสีร�ง
Glboolean glIslist(Gluint list);Glboolean glIslist(Gluint list);• ต่รวิจสีอบวิ��ช้1�อต่รวิจสีอบวิ��ช้1�อ listlist ถ้ กำใช้แลวิหร1อย่�งถ้ กำใช้แลวิหร1อย่�ง
49
วิ�ธี�กำ�รใช้ วิ�ธี�กำ�รใช้ Display ListDisplay Listวิ�ธี�กำ�รใช้ วิ�ธี�กำ�รใช้ Display ListDisplay List
glNewList( 1, GL_COMPILE );glNewList( 1, GL_COMPILE );
glColor3fv( colorVector );glColor3fv( colorVector );
glTranslatef( 1.5, 0.0, 0.0 );glTranslatef( 1.5, 0.0, 0.0 );
glBegin( GL_TRIANGLES );glBegin( GL_TRIANGLES );
glVertex2f( 0.0, 0.0 );glVertex2f( 0.0, 0.0 );
glVertex2f( 1.0, 0.0 );glVertex2f( 1.0, 0.0 );
glVertex2f( 0.0, 1.0 );glVertex2f( 0.0, 1.0 );
glEnd();glEnd();
glEndList();glEndList();
Glvoid glNewList(Gluinit Glvoid glNewList(Gluinit ListindeListindex,Glenum x,Glenum ModeMode););…………Glvoid glEndList();Glvoid glEndList();ListindexListindex: : ช้1�อช้1�อ display listdisplay listModeMode: GLCOMPILE, GLCOMPILE_AND_EXECUTE: GLCOMPILE, GLCOMPILE_AND_EXECUTE
50
ลบ ลบ Display ListDisplay Listลบ ลบ Display ListDisplay List
GLvoid glDeleteLists( GLuint rstIndex, GLsizei GLvoid glDeleteLists( GLuint rstIndex, GLsizei count )count )
51
ต่�วอยี�างต่�วอยี�างต่�วอยี�างต่�วอยี�างglNewList( 1, GL_COMPILE ); /*glNewList( 1, GL_COMPILE ); /*สีร�ง สีร�ง [1] */[1] */
drawFin();drawFin();
glEndList();glEndList();
glNewList( 2, GL_COMPILE ); /* glNewList( 2, GL_COMPILE ); /* สีร�ง สีร�ง [2] */[2] */
drawFish();drawFish();
glEndList();glEndList();
glNewList( 3, GL_COMPILE ); /* glNewList( 3, GL_COMPILE ); /* สีร�ง สีร�ง [3][3] (( run run [1][1] 、、 [2]*/[2]*/
glCallList( 1 );glCallList( 1 );
glCallList( 2 );glCallList( 2 );
glEndList();glEndList();
・・ ・・ ・・
glCallList( 3 ); /* glCallList( 3 ); /* drawFin();drawFin(); drawFish();drawFish(); */ */
52
Display ListDisplay ListDisplay ListDisplay List
glNewList( 1, GL_COMPILE ); /* define glNewList( 1, GL_COMPILE ); /* define ใหม� ใหม� [1] */[1] */
drawNewFin();drawNewFin();
glEndList();glEndList();
・ ・ ・ ・ ・ ・
glCallList( 3 ); /* glCallList( 3 ); /* drawNewFin();drawNewFin(); drawFish(); */ drawFish(); */
53
Texture+Display ListTexture+Display ListTexture+Display ListTexture+Display List
glNewList( 1, GL_COMPILE ); /*glNewList( 1, GL_COMPILE ); /*สีร�ง สีร�ง [1] */[1] */
สีร�ง สีร�ง texture 1texture 1
glEndList();glEndList();
glNewList( 2, GL_COMPILE ); /* glNewList( 2, GL_COMPILE ); /* สีร�ง สีร�ง [2] */[2] */
สีร�ง สีร�ง texture 2texture 2
glEndList();glEndList();
……..
glCallList(1);glCallList(1);
glBegin(GL_QUADS);glBegin(GL_QUADS);
กำ��หนด้ กำ��หนด้ vertex vertex ข้อง ข้อง polygonspolygons
glEnd();glEnd();
glCallList(2);glCallList(2);
glBegin(GL_QUADS);glBegin(GL_QUADS);
กำ��หนด้ กำ��หนด้ vertex vertex ข้อง ข้อง polygonspolygons
glEnd();glEnd();
54
• glTexImage2D(GL TEXTURE 2D, 0, GL RGBA, 64, 64, 0, GL RGBA, GL UNSIGNED BYTE, MIPLevels[0]);
55