Computer Graphics, Lee Byung-Gook, Dongseo Univ.

Slides:



Advertisements
Similar presentations
1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
Advertisements

TEXTURE MAPPING JEFF CHASTINE 1. TEXTURE MAPPING Applying an image (or a texture ) to geometry 2D images (rectangular) 3D images (volumetric – such as.
OpenGL Texture Mapping
CH6 Texture. Before coding … 1/2 Prepare all texture images you need. BMP file is a good choice If you want to use TIFF file, maybe try this.
Texture Mapping OpenGl and Implementation Details CS
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping A way of adding surface details Two ways can achieve the goal:  Surface detail polygons: create extra polygons to model object details.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Texture Mapping + Texture Object = Texture Mapped Object.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
2002 by Jim X. Chen: 1 Texture Lab At each rendered pixel, selected texels are used either to substitute for or to scale.
Texture Mapping. Scope Buffers Buffers Various of graphics image Various of graphics image Texture mapping Texture mapping.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
An Interactive Introduction to OpenGL Programming Ed Angel
CS 445 / 645 Introduction to Computer Graphics Lecture 19 Texture Maps Lecture 19 Texture Maps.
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Lecture 27: Texture Mapping Li Zhang Spring 2008
And Some Extra Information From
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
CH6 Texture.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Madhulika (18010), Assistant Professor, LPU.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Assignment 3b Q&A.
Chapters VIII Image Texturing
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Lecture 21: Texture mapping Li Zhang Spring 2010
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

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

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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.

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.

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.

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.

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.

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.

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.

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

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.