Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr
Contents Texels and textures Constructing a texture map Texture coordinates Texture parameters A rotating cube with texture Texture mapping with images Exercise kucg.korea.ac.kr
Texels and Textures Texels – texture elements Texture coordinates (s, t) kucg.korea.ac.kr
Constructing a Texture Map Steps: Read an image for the texture map Define parameters that determine how the texture should be applied Define texture coordinates for the vertices Ex: making the image into a 2D texture map GLubyte myimage[64][64][3]; glEnable(GL_TEXTURE_2D); glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, myimage); kucg.korea.ac.kr
1D, 2D, & 3D Texture Maps void glTexImage1D(GLenum target, GLint level, GLint iformat, GLsizei width, GLint border, GLenum format, GLenum type, Glvoid *texels); void glTexImage2D(GLenum target, GLint level, GLint iformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, Glvoid *texels); void glTexImage3D(GLenum target, GLint level, GLint iformat, GLsizei width, GLsizei height, Glsizei depth, GLint border, GLenum format, GLenum type, Glvoid *texels); kucg.korea.ac.kr
2D Texture Map Texture map as a continuous image in (s, t) space and as a discrete image Texture Map Texture Image kucg.korea.ac.kr
Texture Coordinates (1/2) Mapping between points on geometric objects and texels Ex: mapping the texture to a quadrilateral void glTexCoord{1234}{sifd}(TYPE scoord, ...); void glTexCoord{1234}{sifd}v(TYPE *coord); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3fv(vertex[0]); glTexCoord2f(0.0, 1.0); glVertex3fv(vertex[1]); glTexCoord2f(1.0, 1.0); glVertex3fv(vertex[2]); glTexCoord2f(1.0, 0.0); glVertex3fv(vertex[3]); glEnd(); kucg.korea.ac.kr
Texture Coordinates (2/2) Applying a checkerboard texture to a quadrilateral Texture Map Quadrilateral kucg.korea.ac.kr
Texture Parameters (1/3) Control over how the texture is applied to the surface Ex: deciding what to do if values are out of (0, 1) GL_CLAMP void glTexParameter{if}(GLenum target, GLenum name, TYPE value); void glTexParameter{if}v(GLenum target, GLenum name, TYPE *value); glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, kucg.korea.ac.kr
Texture Parameters (2/3) Preimage of the pixel Texture mapping is not really applied to the surface but rather a pixel in screen coordinates Magnification – each texel covers multiple pixels Minification – each pixel covers multiple texels Magnification Minification kucg.korea.ac.kr
Texture Parameters (3/3) Point sampling OpenGL uses to average a 2X2 array of neighboring texels GL_LINEAR glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameter(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, kucg.korea.ac.kr
A Rotating Cube with Texture kucg.korea.ac.kr
Constructor kucg.korea.ac.kr
DrawQuad( ) kucg.korea.ac.kr
DrawScene( ) kucg.korea.ac.kr
A Color Cube kucg.korea.ac.kr
Texture Image kucg.korea.ac.kr
LoadTexture( ) kucg.korea.ac.kr
DrawQuad( ) kucg.korea.ac.kr
DrawScene( ) kucg.korea.ac.kr
A Color Cube with Texture kucg.korea.ac.kr
Exercise (1) Change the texture coordinates, parameters for texture mapping kucg.korea.ac.kr
Texture Images Load a BMP file for a texture image kucg.korea.ac.kr
OpenGL Auxiliary Library kucg.korea.ac.kr
Project Settings kucg.korea.ac.kr
New Definition kucg.korea.ac.kr
LoadTexture( ) kucg.korea.ac.kr
Result – Texture Mapping (1) kucg.korea.ac.kr
Multiple Texture Images kucg.korea.ac.kr
LoadTexture( ) kucg.korea.ac.kr
DrawScene( ) kucg.korea.ac.kr
Result – Texture Mapping (2) kucg.korea.ac.kr
Exercise (2) Set the background by texture mapping kucg.korea.ac.kr