Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Graphics Practical Lesson 6

Similar presentations


Presentation on theme: "Computer Graphics Practical Lesson 6"— Presentation transcript:

1 Computer Graphics Practical Lesson 6
Textures

2 What is texture? Our models are geometric shapes, and we can color them, and give them variety of colors using lights shading. Using these basic tools, we can put repeating patterns or placing images on walls. We use textures to put images on polygons. Each pixel of the polygon receives its color by the color of matching pixel of texture.

3 Setting up textures 1. create a texture handler:
unsigned int h_texture; glGenTextures( 1, &h_texture ); 2. define texture type, we usually want 2D texture. glBindTexture( GL_TEXTURE_2D, texture );

4 Setting texture parameters.
Setting texture color: glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); If we replace GL_MODULATE with GL_DECAL, lighting and shape color won’t effect the texture color.

5 Setting texture parameters(cont’)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); Method that will be used when texture is smaller than target polygon. GL_LINEAR means a standard linear interpolation. Other option is GL_Nearest. glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Method that will be used when texture is larger than target polygon. It can be linear, or use of mipmap.

6 Setting texture parameters(cont’)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) Texture is defined in 2 axis S and T. with these parameters we define weather the pattern of texture will repeat itself(GL_REPEAT) or the texture will be stretched (GL_CLAMP).

7 Setting Texture itself
glTexImage2D(GL_TEXTURE_2D,0,3,bmp.width, bmp.height,0,GL_RGB,GL_UNSIGNED_BYTE, bmp.bytes); These is the call in our example. There are many parameters. The important parameters are the pointer to bytes array and image dimensions. The content is loaded immediately into the video card memory.

8 Mipmaps When using textures on small or far objects, we don’t need large texture. We need to use interpolation of the image of texture. We don’t want to make interpolation on the original image, since it’s a lot of information. Mipmaps are set of decreased sized images of the original image. One of the images will be used according to the size of target polygon.

9 Mipmaps To use mipmaps we must first build them: gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, 64, 64, GL_RGBA, GL_UNSIGNED_BYTE, img); To use mipmaps: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, <value> ): There are 4 values: GL_NEAREST_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR. The first defines which mipmap and the second interpolation method.

10 Attaching coordinate to polygon
To use texture on polygon we need to match between their coordinates: glNormal3fv(…); // set the normal. glTexCoord2f(s,t); // set coordinate offset glVertex3fv(…); set the point With these commands we set a point of polygon along with its coordinate.


Download ppt "Computer Graphics Practical Lesson 6"

Similar presentations


Ads by Google