OpenGL Texturing. Content Texture target Texture environment Texture coordinate Texture parameter...

download OpenGL Texturing. Content Texture target Texture environment Texture coordinate Texture parameter (filters, wrap) Texture object Texture transformation

of 61

  • date post

    19-Dec-2015
  • Category

    Documents

  • view

    248
  • download

    4

Embed Size (px)

Transcript of OpenGL Texturing. Content Texture target Texture environment Texture coordinate Texture parameter...

  • Slide 1
  • OpenGL Texturing
  • Slide 2
  • Content Texture target Texture environment Texture coordinate Texture parameter (filters, wrap) Texture object Texture transformation TexGen Multitexture Applications Light map 3D textures Projective texture Environment map Specular map 2Fall 2013 Revised
  • Slide 3
  • Steps in OpenGL Texture Mapping Specify (create) the texture Set texture parameters: Indicate how the texture is to be applied to each pixel Enable texture mapping Draw the scene, supplying both texture and geometric coordinates Works only in RGB mode 3Fall 2013 Revised
  • Slide 4
  • Texture Targets glTexImage1D() glTexImage2D() glTexImage3D() 4Fall 2013 Revised
  • Slide 5
  • Two Dimensional Texture glTexImage2D (GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) target GL_TEXTURE_2D level LOD number (0: base image) components number of color components (1|2|3|4) Format pixel data format Border: 0 or 1 Width & height 2 m + 2(border bit) w and h can be different There are new extensions that removes this restriction 5Fall 2013 Revised
  • Slide 6
  • glTexImage*D supplement In GL version 1.1 or greater, pixels may be a null pointer. In this case texture memory is allocated to accommodate a texture of width width and height height. You can then download subtextures to initialize this texture memory. The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive. 6Fall 2013 Revised
  • Slide 7
  • Setting Texture Environment glTexEnv{if}{v}(GLenum target, GLenum pname, TYPEparam); Setting how textures are to be interpreted: Target GL_TEXTURE_ENV Pname: GL_TEXTURE_ENV_MODE Param: modes (DECAL|REPLACE|MODULATE|BLEND|ADD|) 7Fall 2013 Revised
  • Slide 8
  • Texture Environment Modes GL_REPLACE GL_MODULATE (default) GL_DECAL GL_BLEND New environment modes: GL_ADD: C v = C f + C t GL_COMBINE (ARB, see here)here 8Fall 2013 Revised
  • Slide 9
  • GL_MODULATE Color of polygon affects the display of texture Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 9Fall 2013 Revised
  • Slide 10
  • GL_BLEND Use with: glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colorPtr) C c : texture environment color 10Fall 2013 Revised
  • Slide 11
  • GL_REPLACE Appearance solely determined by texture FOR TEXTURE CUT-OUTS Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 11Fall 2013 Revised
  • Slide 12
  • GL_DECAL Cp: replace RGB: DECAL=REPLACE Tree: (r,g,b,a) a cutout = 0 Polygon: (1,0,0) 12Fall 2013 Revised
  • Slide 13
  • Texture + Lighting To show fragment color, use GL_MODULATE Apply specular color AFTER texture mapping: glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR); See FAQ 21.040FAQ 21.040 GL_SINGLE_COLOR GL_SEPARATE_SPECULAR_COLOR 13Fall 2013 Revised
  • Slide 14
  • Texture Coordinates Texture coordinate: Associate texture location (in texture space) with vertices in the polygon glTexCoord2i (s, t);glVertex2i (x, y); Order cannot be reversed! [Think of TexCoord as state assignment] 14Fall 2013 Revised
  • Slide 15
  • Texture Coordinates of Quadrics Most quadric primitives have default setting for texture coordinates To turn on the default setting: gluQuadricTexture (qobj, GL_TRUE) 15Fall 2013 Revised
  • Slide 16
  • Ex: Textures on Quadrics 16Fall 2013 Revised
  • Slide 17
  • Deeper Look into Texturing 17 Each fragment got its texture coordinates from interpolation Then via table lookup, obtain its (interpolated) color values. Fall 2013 Revised
  • Slide 18
  • rasterization Polygon (in screen space) and texture coordinates (1,1) (1,0) (0,.75) (1,1) (1,0) (0,.75) Texture map (4x4) nearest linear Interpolate (s,t) and lookup (r,g,b,a) in the texture map Filters Texture Access and Lookup 18Fall 2013 Revised
  • Slide 19
  • Filters: Magnification & Minification Nature of problem: Mismatch between texels and pixels 19Fall 2013 Revised
  • Slide 20
  • Options Magnification GL_NEAREST GL_LINEAR Minification GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST GL_LINEAR_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_LINEAR Chooses the mipmap that most closely matches the size of the pixel being textured Chooses the two mipmaps that most closely match the size of the pixel being textured Nearest: in Manhattan distance to the center of the pixel 20Fall 2013 Revised
  • Slide 21
  • Magnification Options GL_LINEAR Interpolate the texels More time consuming but more accurate GL_NEAREST Snap to the nearest texel 21Fall 2013 Revised
  • Slide 22
  • Problems of Minification Can use nearest neighbor or bilinear interpolation,but these two may cause severe aliasing problems Nearest NeighborBilinear Interpolation or ?? Texels Pixels No Influence 22Fall 2013 Revised
  • Slide 23
  • Problem with Minification without mipmap with mipmap 23Fall 2013 Revised
  • Slide 24
  • Mipmapping The most popular method of anti-aliasing for textures Mip stands for multum in parvo = many things in a small place The texture is downsampled to a quarter of the original area. Mipmapping was invented by Lance Williams in 1983 and is described in his paper Pyramidal parametrics. 24Fall 2013 Revised
  • Slide 25
  • [Point Sampled Texture Aliasing] Note that the back row is a very poor representation of the true image Texture map Polygon far from the viewer in perspective projection Rasterized and textured 25Fall 2013 Revised
  • Slide 26
  • Minification Options glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_NEAREST); Remarks: Mipmap selection is done per pixel Using not-yet-ready mipmap disables the texture mapping function. Remarks: Mipmap selection is done per pixel Using not-yet-ready mipmap disables the texture mapping function. 26Fall 2013 Revised
  • Slide 27
  • Mipmap Generation gluBuild2DMipmaps Storage overhead 27Fall 2013 Revised
  • Slide 28
  • Texture Wrap When the texture coordinates are outside [0,1] glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,param); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,param); param: GL_CLAMP|GL_REPEAT 28Fall 2013 Revised
  • Slide 29
  • Parameters for Wrapping GL_CLAMP use the border texel Diagonal: corner texel GL_REPEAT repeat the texels in [0,1] 29Fall 2013 Revised
  • Slide 30
  • Texture Object A texture object stores texture data and makes it readily available You can now control many textures and go back to textures that have been previously loaded into your texture resources Using texture objects is usually the fastest way to apply textures, resulting in big performance gains it is almost always much faster to bind (reuse) an existing texture object than it is to reload a texture image using glTexImage*D() 30Fall 2013 Revised
  • Slide 31
  • Texture Object API glGenTextures Allocate n textures (integer identifiers) glBindTexture Bind the current texture to specified identifier glDeleteTextures Free the allocated texture identifiers Reverse of glGenTextures 31Fall 2013 Revised
  • Slide 32
  • checker.c 32Fall 2013 Revised
  • Slide 33
  • texbind.c Once created, a named texture may be re-bound to the target of the matching dimensionality as often as needed. It isusually much faster to use glBindTexture to bind an existing named texture to one of the texture targets than it is to reload the texture image using glTexImage1D, glTexImage2D, or glTexImage3D. 33Fall 2013 Revised
  • Slide 34
  • Texture Objects Texture properties saved in texture objects: Minification and magnification filters, wrapping modes, border color and texture priority When a texture object is bound again, one may edit the contents of the bound texture object. Any commands that change the above properties will change the currently bound texture as well as the current texture state. Texture environment, texgen, etc. are NOT stored in texture objects These settings need to be repeated after texture binding. 34Fall 2013 Revised
  • Slide 35
  • Texture Loader (PNG, glpng.rar) Features Build mipmap Load and bind 2D textures Load image data (image loader) Handle transparent image (cut-out texture) Important API id = pngBind(filename, mipmap, trans, info, wrapst, minfilter, magfilter) pngSetStencil(red, green, blue) pngSetStandardOrientation(1) OpenGL: origin (0,0) is at lower left corner pngLoad(filename, mipmap, trans, info) TEXTURE ID IS RETURNED TO YOU BY PNG LOADER 35Fall 2013 Revised
  • Slide 36
  • Texture Transforms Texture coordinates are multiplied by a 4 by 4 matrix before any texture mapping occurs. Texture animation: using this, you can make the texture slide over the surface, rotate around it, stretch and shrink, All matrix operations apply: Push/Pop/Mult/ 36Fall 2013 Revised
  • Slide 37
  • Texture Suite cloud explode smoke water fire 37Fall 2013 Revised
  • Slide 38
  • Automatic TEX ture C