1 / 14

CD2012 Principles of Interactive Graphics Lecture 07

CD2012 Principles of Interactive Graphics Lecture 07. Texture Mapping Abir Hussain (JPB6.33, a.hussain@livjm.ac.uk). Previous lecture. Perspective projection Lighting Shading Viewpoint gluLookAt function 3D shapes and surfaces

zelig
Télécharger la présentation

CD2012 Principles of Interactive Graphics Lecture 07

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. CD2012Principles of Interactive GraphicsLecture 07 Texture Mapping Abir Hussain (JPB6.33, a.hussain@livjm.ac.uk)

  2. Previous lecture • Perspective projection • Lighting • Shading • Viewpoint • gluLookAt function • 3D shapes and surfaces • specify each vertex as a point in 3D space using the x, y and z values CD2012-07

  3. Today’s Lecture and Lab CD2012-07

  4. What are textures?

  5. Introduction • Textures: an image that can be glued onto a polygon • Reduces the need to draw many polygons to make up a complex image • Texture data: Rectangular areas of data with a width, height and depth • Usually a bitmap • Depth information can represent colour, (or lighting or transparency) • OpenGL also has 1D and 3D textures (see chapter 9 of OpenGL Programming book) CD2012-07

  6. Introduction • Textures on • background • ground • building • bridge • water • Some • individual • tiled CD2012-07

  7. Creating texture • Textures can be created by either • Creating the texture data in the program • Loading the texture data from an texture (image) file • OpenGL supports creating texture objects but has no support loading images. • Programmer has to provide • the image loading functions • Assign the image data to the texture object CD2012-07

  8. Creating textures within program • The first step is to create the required image within the program • refer to ch9txt.cpp program in the lab. • The next steps are then the same for internal or file-based textures • Before the data can be used texture mapping must be enabled in OpenGL and a texture object created int textname; glEnable(GL_TEXTURE_2D); glGenTextures(1, &texname); CD2012-07

  9. Using texture • We need to say what is the current texture to be used • glBindTexture(GL_TEXTURE_2D, texname); • We can then set the drawing context for applying the texture • For example should the texture appear once or be tiled? CD2012-07

  10. Using texture glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); • We can use GL_GLAMP or GL_REPEAT CD2012-07

  11. Using texture • We can also set how the texture affects the colours of the underlying polygon glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); • GL_REPLACE replaces the underlying colours • GL_MODULATE works with the underlying colours • Finally we set the co-ordinates of the texture as we draw the polygons to which it is applied. CD2012-07

  12. Texture co-ordinates • The coordinates of textures are named s along the X axis and t along the Y axis • The values of S and T range between 0.0 and 1.0 • We can use values between 0.0 and 1.0 to select part of the imaged to be mapped, or • We can use values greater than 1.0 to map multiple copies of the single texture across a polygon • Texture coordinates are set for each vertex of the target polygon with glTexCoord2f() CD2012-07

  13. Texture co-ordinates CD2012-07

  14. Summary • Creating texture within program • Using texture • Texture co-ordinates CD2012-07

More Related