1 / 23

CS 445 / 645 Introduction to Computer Graphics

CS 445 / 645 Introduction to Computer Graphics. Lecture 19 Texture Maps. Texture Mapping. Limited ability to generate complex surfaces with geometry Images can convey the illusion of geometry Images painted onto polygons is called texture mapping. Texture Maps.

odin
Download Presentation

CS 445 / 645 Introduction to Computer Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 445 / 645Introduction to Computer Graphics Lecture 19 Texture Maps

  2. Texture Mapping • Limited ability to generate complex surfaces with geometry • Images can convey the illusion of geometry • Images painted onto polygons is called texture mapping

  3. Texture Maps • Chapter 9 of Open GL Programming Guide (Red Book) • Images applied to polygons to enhance the visual effect of a scene • Rectangular arrays of data • Color, luminance, alpha • Components of array called texels • Or in 3D, volumetric voxels

  4. T V U S Texture Mapping • Texture map is an image, two-dimensional array of color values (texels) • Texels are specified by texture’s (u,v) space • At each screen pixel, texel can be used to substitute a polygon’s surface property (color) • We must map (u,v) space to polygon’s (s, t) space

  5. Texture Mapping • (u,v) to (s,t) mapping can be explicitly set at vertices by storing texture coordinates with each vertex • How do we compute (u,v) to (s,t) mapping for points in between • Watch for aliasing • Watch for many to one mappings • Watch for perspective foreshortening effects and linear interpolation

  6. Example Texture Map Applied to tilted polygon

  7. Example Texture Map glVertex3d (s, s, s) glTexCoord2d(1,1); glVertex3d (-s, -s, -s) glTexCoord2d(0, 0);

  8. Example Texture Map glVertex3d (s, s, s) glTexCoord2d(5, 5); Repeating textures vs.Clamped textures glVertex3d (s, s, s) glTexCoord2d(1, 1);

  9. Texture Coordinates • Every polygon can have object coordinates and texture coordinates • Object coordinates describe where polygon vertices are on the screen • Texture coordinates describe texel coordinates of each vertex (usually 0 -> 1) • Texture coordinates are interpolated along vertex-vertex edges • glTexCoord{1234}{sifd}(TYPE coords) s, t, r, and q (for homogeneous coordinates, an advanced topic) Why 14 coords?

  10. Textures • Texture Object • An OpenGL data type that keeps textures resident in memory and provides identifiers to easily access them • Provides efficiency gains over having to repeatedly load and reload a texture • You can prioritize textures to keep in memory • OpenGL uses least recently used (LRU) if no priority is assigned

  11. Example use of Texture • Read .bmp from file • Use Image data type • getc() and fseek() to read image x & y size • fread() fills the Imagedata memory with actual red/green/blue values from .bmp • Note • malloc() Image->data to appropriate size • .bmp stores color in bgr order and we convert to rgb order

  12. Step 2 – create Texture Objects • glGenTextures(1, &texture[texture_num]); • First argument tells GL how many Texture Objects to create • Second argument is a pointer to the place where OpenGL will store the names (unsigned integers) of the Texture Objects it creates • texture[ ] is of type GLuint

  13. Step 3 – Specify which texture object is about to be defined • Tell OpenGL that you are going to define the specifics of the Texture Object it created • glBindTexture(GL_TEXTURE_2D, texture[texture_num]); • Textures can be 1D and 3D as well

  14. Step 4 – Begin defining texture • glTexParameter() • Sets various parameters that control how a texture is treated as it’s applied to a fragment or stored in a texture object • // scale linearly when image bigger than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); • // scale linearly when image smaller than texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

  15. Step 5 – Assign image data • glTexImage2D();

  16. glTexImage2D – Arg 1 • GLenum target • GL_TEXTURE_{1|2|3}D • GL_PROXY_TEXTURE_2D • Provides queries for texture resources • Proceed with hypothetical texture use (GL won’t apply the texture) • After query, call GLGetTexLevelParamter to verify presence of required system components • Doesn’t check possibility of multiple texture interference

  17. glTexImage2D – Arg 2 • GLint level • Used for Level of Detail (LOD) • LOD stores multiple versions of texture that can be used at runtime (set of sizes) • Runtime algorithms select appropriate version of texture • Pixel size of polygon used to select best texture • Eliminates need for error-prone filtering algorithms

  18. glTexImage2D – Arg 3 • GLint internalFormat • GL defines 38 symbolic constants that describe which of R, G, B, and A are used in internal representation of texels • Provides control over things texture can do • High bit depth alpha blending • High bit depth intensity mapping • General purpose RGB • GL doesn’t guarantee all options are available on given hardware

  19. glTexImage2D – Args 4-6 • GLsizei width • GLsizei height • Dimensions of texture image • Must be 2m + 2b (b=0 or 1 depending on border) • min, 64 x 64 • GLint border • Width of border (1 or 0) • Border allows linear blending between overlapping textures • Useful when manually tiling textures

  20. glTexImage2D – Args 7 & 8 • GLenum format • Describe how texture data is stored in input array • GL_RGB, GL_RGBA, GL_BLUE… • GLenum type • Data size of array components • GL_SHORT, GL_BYTE, GL_INT…

  21. glTexImage2D – Arg 9 • Const GLvoid *texels • Pointer to data describing texture map

  22. Step 6 – Apply texture • Before defining geometry • glEnable(GL_TEXTURE_2D); • glBindTexture(GL_TEXTURE_2D, texture[0]); • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

  23. glTexEnv() First argument to function is always GL_TEXTURE_ENV

More Related