Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics, Lee Byung-Gook, Dongseo Univ.

Similar presentations


Presentation on theme: "Computer Graphics, Lee Byung-Gook, Dongseo Univ."— Presentation transcript:

1 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

2 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Mapping Definition: A 2-dimensional (2D) texture map is an image that is applied to one side of a 3-dimensional polygon. Problems: The image and the 3D polygon typically do not have the same shape (most polygons are not rectangles). The image and the 3D polygon typically do not have the same size 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

3 Texture Mapping Example polygons Defined in world coordinates
Texture image 200 by 100 pixels 5.3 600.51 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

4 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Mapping The image and the 3D polygon typically do not have the same shape Solution : specify the portion of the image that is to be used to "paint" the polygon. Since we need to specify a subset of the whole image, it is natural to use percentages of the image dimensions. The percentages are specified as values between 0 (0%) and 1.0 (100%). 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

5 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Mapping Texture coordinates 1.0 (0.48, 0.06) (0.39, 0.95) (0.11, 0.6) (0.0, 0.0) 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

6 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Mapping The image and the 3D polygon typically do not have the same size. Solution : the number of pixels used to display a polygon is dependent on the current MODELVIEW and PROJECTION matrices. (If the camera is close to the polygon, it will appear large in the window and require many pixels to represent it; if the camera is far away from the polygon, it will take very few pixels to represent it.) When a polygon is rendered, it is transformed by the MODELVIEW matrix, then projected on the viewing plane by the PROJECTION matrix, and then converted to screen (pixel) coordinates. After all of the polygon's vertices have been mapped to the screen by this "graphics pipeline," the pixels in the interior of the polygon are filled in, typically by a "scan line" algorithm. If the polygon is texture mapped, the color of each pixel is not the interpolated color from the vertices, but rather the correct color values from the texture image. This requires that the pixels be mapped into their correct position within the texture image. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

7 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Texture Mapping If there are more pixels on the screen that require colors than there are pixels in the texture image, then the texture image must be magnified (made larger). If there are fewer pixels on the screen as compared to the texture image, then the texture image must be minified (made smaller). There are two general solutions:After mapping the pixel into the texture image take the color of the closest texture pixel (OpenGL calls this GL_NEAREST, which produces fast, but poor graphics)take a linear average of the colors of the surrounding pixels. (OpenGL calls this GL_LINEAR, which produces better, but slower graphics) This is the identical problem we discussed last week-- that of scaling an image. There are two general solutions:After mapping the pixel into the texture imagetake the color of the closest texture pixel (OpenGL calls this GL_NEAREST, which produces fast, but poor graphics)take a linear average of the colors of the surrounding pixels. (OpenGL calls this GL_LINEAR, which produces better, but slower graphics) 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

8 Texture map compositing
Compositing occurs when a pixel's color value is determined by using a combination of two (or more) color values. When using texture maps we have 2 colors to deal with - the color of the face and the color from the texture map Ct - the color defined by the texture map Cf - the color of the polygon face Cc - the color defined by the global texture color C - the color to be placed in the color buffer The "global texture color" is defined using the parameter GL_TEXTURE_ENV_COLOR Compositing occurs when a pixel's color value is determined by using a combination of two (or more) color values. When using texture maps we have 2 colors to deal with -- the color of the face and the color from the texture map. Let Ct - the color defined by the texture map, Cf - the color of the polygon (face), C - the color to be placed in the color buffer 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

9 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Compositing methods Replace the current color in the color buffer with the texture map color. (GL_REPLACE) C = Ct Combine the color of the face with the color of the texture map by multiplying their values together. (GL_MODULATE) C = Cf*Ct Combine the color of the face with the color of the texture map by adding a percentage of both (the percentage is controlled by the alpha values of the texture map) (GL_DECAL) C = Cf*(1-At) +Ct*At Combine the color of the face and the color of the texture map using the texture values as percentages of a "global texture color" Cc. (GL_BLEND) C = Cf*(1-Ct) +Cc*Ct OpenGL supports the following texture mapping compositing methods. (The letter A represents the alpha color component). Note: For completeness, be aware that the compositing of face colors with textures colors works slightly different for different internal representations of texture maps. See the Redbook for details. The description above is for RGBA storage mode. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

10 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 17 downloading 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

11 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
makeCheckImage #define checkImageWidth 64 #define checkImageHeight 64 GLubyte checkImage[checkImageHeight][checkImageWidth][4]; void makeCheckImage(void) { int i, j, c; for (i = 0; i < checkImageHeight; i++) { for (j = 0; j < checkImageWidth; j++) { c = ((((i&0x8)==0)^((j&0x8))==0))*255; checkImage[i][j][0] = (GLubyte) c; checkImage[i][j][1] = (GLubyte) c; checkImage[i][j][2] = (GLubyte) c; checkImage[i][j][3] = (GLubyte) i*(255/checkImageHeight); } 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

12 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
myInit makeCheckImage(); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnable(GL_TEXTURE_2D); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

13 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
myDisplay glColor3fv(color[9]); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(0., 0., 1.); glTexCoord2f(1.0, 0.0); glVertex3f(1., 0., 1.); glTexCoord2f(1.0, 1.0); glVertex3f(1., 1., 1.); glTexCoord2f(0.0, 1.0); glVertex3f(0., 1., 1.); glTexCoord2f(0.0, 0.0); glVertex3f(1., 1., 1.); glTexCoord2f(1.0, 1.0); glVertex3f(1., 0., 0.); glTexCoord2f(0.0, 1.0); glVertex3f(1., 1., 0.); glEnd(); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

14 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glTexParameter void glTexParameter{fi}( GLenum target, GLenum pname, GLint param ); These functions set texture parameters. target : The target texture, which must be either GL_TEXTURE_1D or GL_TEXTURE_2D. pname : The symbolic name of a single-valued texture parameter. The following symbols are accepted in pname: GL_TEXTURE_MIN_FILTER, GL_TEXTURE_MAG_FILTER, GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

15 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glTexParameter GL_TEXTURE_MIN_FILTER GL_NEAREST or GL_LINEAR GL_TEXTURE_MAG_FILTER GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST or GL_LINEAR_MIPMAP_LINEAR GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T GL_CLAMP or GL_REPEAT 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

16 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glTexEnv void glTexEnv{fi}( GLenum target, GLenum pname, GLfloat param ); These functions set texture environment parameters target : A texture environment. Must be GL_TEXTURE_ENV. pname : The symbolic name of a single-valued texture environment parameter. Must be GL_TEXTURE_ENV_MODE. param : A single symbolic constant, one of GL_MODULATE, GL_DECAL, or GL_BLEND. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

17 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glTexImage2D void glTexImage2D( GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); The glTexImage2D function specifies a two-dimensional texture image. target : The target texture. Must be GL_TEXTURE_2D. level : The level-of-detail number. Level 0 is the base image level. Level n is the nth mipmap reduction image. components : The number of color components in the texture. Must be 1, 2, 3, or 4. width : The width of the texture image. Must be 2^n + 2(border) for some integer n. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

18 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glTexImage2D height : The height of the texture image. Must be 2^m + 2(border) for some integer m. border : The width of the border. Must be either 0 or 1. format : The format of the pixel data. It can assume one of nine symbolic values: GL_COLOR_INDEX, GL_RGB, GL_RGBA, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_BGR_EXT, GL_BGRA_EXT, GL_LUMINACE, GL_LUMINACE_ALPHA. type : The data type of the pixel data. The following symbolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, and GL_FLOAT. pixels : A pointer to the image data in memory. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

19 Texture map repetition
Texture maps require a lot of memory! To save memory, some types of textures can be defined as small images and then repeated in both the horizontal and vertical directions v (t) 0.0 1.0 2.0 -1.0 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

20 Texture map repetition
v (t) 0.0 1.0 2.0 -1.0 (1.9,1.35) (0.24,-0.92) (-0.4,1.87) Therefore, texture map coordinates are actually not restricted to the range (0.0, 1.0). They can be any values, but they still represent percentages of distances within texture images. When the values are outside the range (0.0, 1.0), the values refer to duplicate copies of the texture image. For example 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

21 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 18 downloading 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

22 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
myInit ReadBMP("hgeri.bmp", &myImage); glBindTexture(GL_TEXTURE_2D, 1); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, myImage.Width, myImage.Height, 0, GL_RGB, GL_UNSIGNED_BYTE, myImage.Pixels); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

23 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
makeCheckImage(); glBindTexture(GL_TEXTURE_2D, 2); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

24 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
myDisplay glBindTexture(GL_TEXTURE_2D, 1); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(0., 0., 1.); glTexCoord2f(3.0, 0.0); glVertex3f(1., 0., 1.); glTexCoord2f(3.0, 3.0); glVertex3f(1., 1., 1.); glTexCoord2f(0.0, 3.0); glVertex3f(0., 1., 1.); glEnd(); glBegin(GL_POLYGON); glTexCoord2f(3.0, 0.0); glVertex3f(0., 0., 1.); glTexCoord2f(3.0, 3.0); glVertex3f(0., 1., 1.); glTexCoord2f(0.0, 0.0); glVertex3f(0., 0., 0.); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

25 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
myDisplay glBindTexture(GL_TEXTURE_2D, 2); glBegin(GL_QUADS); glTexCoord2f(-1.0, -1.0); glVertex3f(1., 1., 1.); glTexCoord2f(1.0, -1.0); glVertex3f(1., 0., 1.); glTexCoord2f(1.0, 1.0); glVertex3f(1., 0., 0.); glTexCoord2f(-1.0, 1.0); glVertex3f(1., 1., 0.); glEnd(); 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

26 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
glBindTexture void glBindTexture( GLenum target, GLuint texture ); The glBindTexture function enables the creation of a named texture that is bound to a texture target. target : The target to which the texture is bound. Must have the value GL_TEXTURE_1D or GL_TEXTURE_2D. texture : The name of a texture; the texture name cannot currently be in use. The glBindTexture function enables you to create a named texture. Calling glBindTexture with target set to GL_TEXTURE_1D or GL_TEXTURE_2D, and texture set to the name of the new texture you have created binds the texture name to the appropriate texture target. When a texture is bound to a target, the previous binding for that target is no longer in effect. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

27 Wrapping textures around spheres
Wrapping a texture around a sphere, such that there is no distortion, is impossible! (Take the surface of a ball and try to "flatten it out" without stretching it. It cannot be done!) There are several possibilities for mapping a texture to a sphere. These are documented on page 461 in the textbook. The following is a straightforward application of a texture to the parametric equation of a sphere. 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

28 Wrapping textures around spheres
0.0 1 N 2 3 numberSides M numberSlices 2p -p/2 p/2 v u 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

29 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lab 19 downloading 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.

30 Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Homework In two weeks Textute map your house with image 11 November 2018 Computer Graphics, Lee Byung-Gook, Dongseo Univ.


Download ppt "Computer Graphics, Lee Byung-Gook, Dongseo Univ."

Similar presentations


Ads by Google