1 Enable Texturing gl EnableGLenum mode mode GLTEXTURE1
지엘의 텍스쳐 매핑 1. Enable Texturing • gl. Enable(GLenum mode); § mode: GL_TEXTURE_1 D, GL_TEXTURE_2 D, GL_TEXTURE_3 D(volumn rendering) 2. Specify Texture Images : gl. Tex. Image 2 D(…) • 배열 형태로 메인 메모리에 있는 텍스쳐를 텍스쳐 메모리로 저장 3. Assign Texture Mapping Method • Manual Texture Generation: gl. Tex. Coord 2 f(…) • Automatic Texture Generation: gl. Tex. Gen{ifd}[v](…) 4. Specify Texture parameters • 주어진 텍스쳐 확장 및 주어진 화소의 텍스쳐 계산 방법 명시 5. Specify Texture Environment • 텍스쳐와 물체면 색 조합 방법 명시 26
Specify Texture Images 텍스쳐 영상은 배열형태로 • GLubyte My. Texture[Width][Height][3]; § s: Width, t: Height, (R, G, B) GLubyte My. Texture [8][8][3]; int s, t; for(s=0; s<8; s++){ for(t=0; t<8; t++){ GLubyte Intensity=((s+t)%2)*255; Mytexture[s][t][0]=Intensity; Mytexture[s][t][1]=Intensity; Mytexture[s][t][2]=Intensity; } } 27
지엘의 텍스쳐 매핑: gl. Tex. Image 2 D( ); 배열에 저장되어 있던 텍스쳐를 텍스쳐 메모리(Texture Memory, Texture Buffer)로 이동시키는 함수 • void gl. Tex. Image 2 D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *texture); § target: texture type(GL_TEXTURE_2 D, . . ), § level: MIP Map level, (0: MIP map사용치 않음) § internalformat: 텍셀을 기술하는데 사용된 요소(GL_RGBA, GL_RGB, . . 38개) § border: 윤곽선 두께(0: 없음) § format: 텍스쳐 데이터 형식( internalformat) § type: 텍스쳐 데이터 타입 § texture: 텍스쳐 영상이 저장된 배열명 § width, height는 텍셀 단위 gl. Tex. Image 2 D(GL_TEXTURE_2 D, 0, GL_RGB, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, My. Texture); 28
지엘의 텍스쳐 매핑: gl. Tex. Image 2 D( ); 청색 화살표로의 흐름 현재 보이는 화면을 텍스쳐로 사용(적색 화살표) • void gl. Copy. Tex. Image 2 D(GLenum target, GLint level, GLint format, GLint x, GLint y, GLsizei width, GLsizei height, GLint border); 현재 텍스쳐 모두 혹은 일부 변경하여 텍스쳐 update • gl. Tex. Sub. Image 2 d(GLenum target, GLint level, GLint format, GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texture); 29
지엘의 텍스쳐 매핑 방법 : 수동 매핑 gl. Begin(GL_POLYGON); gl. Normal 3 f(0. 0, 1. 0); gl. Tex. Coord 2 f(0. 2, 0. 8); 텍스쳐 정점 a를 gl. Vertex 3 f(7. 5, 10. 5, 0. 0); 물체 정점 A에 할당 gl. Normal 3 f(0. 0, 1. 0); gl. Tex. Coord 2 f(0. 4, 0. 2); 텍스쳐 정점 b를 gl. Vertex 3 f(0. 0, 3. 8, 0. 0); 물체 정점 B에 할당 gl. Normal 3 f(0. 0, 1. 0); gl. Tex. Coord 2 f(0. 8, 0. 4); 텍스쳐 정점 c를 gl. Vertex 3 f(12. 0, 0. 0); 물체 정점 C에 할당 gl. End( ); 30
지엘의 텍스쳐 매핑: 자동 매핑 자동 텍스쳐 매핑 예 static GLfloat My. Plane[]={1, 0, 0, 0}; //(A, B, C, D): 법선벡터는 정규화벡터로 gl. Tex. Geni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); gl. Tex. Genfv(GL_S, GL_OBJECT_PLANE, My. Plane); gl. Enable(GL_TEXTURE_GEN_S); // 2차원 텍스처는 T에 관해서도 수행 기준평면과의 물체와의 거리 32
지엘의 텍스쳐 매핑: 자동 매핑 텍스쳐 패턴의 기하변환: 변환행렬은 텍스쳐 좌표 (s, t, r, q)에 곱해짐 gl. Matrix. Mode(GL_TEXTURE); gl. Load. Identity(); gl. Rotatef(45, 0, 0, 1); gl. Translatef(0. 5, 0, 0); gl. Matrix. Mode(GL_MODELVIEW); 주변매핑 • 지엘의 주변매핑 텍스처는 시야각 360도로 촬영된 사진을 전제 gl. Tex. Geni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); gl. Tex. Geni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); gl. Enable(GL_TEXTURE_GEN_S); gl. Enable(GL_TEXTURE_GEN_T); 33
Specify Texture parameters void gl. Tex. Parameter{if} (GLenum target, GLenum pname, TYPE param); • target: GL_TEXTURE_2 D, . . . 주어진 텍스쳐 확장 방법 설정 • pname: GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T § Param: GL_REPEAT, GL_CLAMP gl. Tex. Parameteri(GL_TEXTURE_2 D , GL_TEXTURE_WRAP_S, GL_REPEAT); gl. Tex. Parameteri(GL_TEXTURE_2 D , GL_TEXTURE_WRAP_T, GL_CLAMP); 35
GL_REPEAT, GL_CLAMP 36
Specify Texture parameters 주어진 화소의 텍스쳐 계산방법 설정 • 확장관계: GL_TEXTURE_MAG_FILTER § GL_NEAREST(점샘플링), § GL_LINEAR(양방향 선형보간) • 축소관계: GL_TEXTURE_MIN_FILTER § GL_NEAREST, GL_LINEAR § GL_NEAREST_MIPMAP_NEAREST § GL_LINEAR_MIPMAP_NEAREST § GL_NEAREST_MIPMAP_LINEAR § GL_LINEAR_MIPMAP_LINEAR gl. Tex. Parameterf(GL_TEXTURE_2 D , GL_TEXTURE_MAG_FILTER, GL_LINEAR); gl. Tex. Parameterf(GL_TEXTURE_2 D , GL_TEXTURE_MIN_FILTER, GL_LINEAR); 37
GLint glu. Build 2 DMipmaps( GLenum target, GLint internalformat, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texture); 예) GLint glu. Build 2 DMipmaps(GL_TEXTURE_2 D, 1, GL_RGB, 8, 4, 0, GL_RGB, GL_UNSIGNED_BYTE, My. Texture); gl. Tex. Parameteri(GL_TEXTURE_2 D , GL_TEXTURE_MAG_FILTER, GL_LINER_MIPMAP_LINEAR); gl. Tex. Parameteri(GL_TEXTURE_2 D , GL_TEXTURE_MIN_FILTER, GL_LINER_MIPMAP_LINEAR); 38
Specify Texture Environment 텍스쳐를 물체 색과 조합 void gl. Tex. Env{if} ](GLenum target, GLenum pname, TYPE param); • target: GL_TEXTURE_ENV • pname: GL_TEXTURE_ENV_MODE, GL_TEXTURE_ENV_COLOR • param § GL_REPLACE § GL_MODULATE § GL_DECAL § GL_BLEND GL_REPLACE GL_MODULATE 39
- Slides: 40