Texture Mapping CEng 477 Introduction to Computer Graphics.

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
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
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Texture Mapping + Texture Object = Texture Mapped Object.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
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.
Computer Graphics OpenGL - Texture mapping. OpenGL Texture mapping zTexture Mapping allows us to glue an image on polygons. In this method we can produce.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
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.
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
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Software College, Shandong University Instructor: Zhou Yuanfeng
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.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
CG Summary: OpenGL Shading andTextures Angel, Chapters 5, 7; “Red Book” slides from AW, red book, etc. CSCI 6360/4360.
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.
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.
Texture Mapping and NURBS Week 7 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
第三课. Overview of this Section Concept of Texture Mapping ( 纹理映射 ) 2D Texture 3D Texture Environment Mapping Bump Mapping Others OpenGL Implementation.
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.
Madhulika (18010), Assistant Professor, LPU.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
OpenGL Texture Mapping
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
texturing a parametric surface
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
Chapters VIII Image Texturing
Introduction to Texture Mapping
Geb Thomas Adapted from the OpenGL Programming Guide
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
CS 480/680 (Fall 2018) Part 2: Texture Loading
OpenGL Texture Mapping
Presentation transcript:

Texture Mapping CEng 477 Introduction to Computer Graphics

What is texture mapping? ● Application of textures to surfaces of 3d objects to produce photo-realistic images. No texture mappingWith texture mapping

Examples of texture mapped scenes

What is a texture? ● A texture image is a rectangular array of pixel data ● Usually a 2D array, but can be 1D or 3D ● A "texture pixel" is called a "texel" ● Can contain color, luminance and/or alpha information

What information does a texture contain? ● A one component texture contains Luminance, Intensity, or Alpha data. ● Examples: Wood, grass, sand

What information does a texture contain? ● A two component texture contains Luminance and Alpha (transparency) data. ● Examples: Trees, clouds

What information does a texture contain? ● A three component texture contains Red, Green, and Blue values. ● Examples: Fabrics, bricks

What information does a texture contain? ● A four component texture contains Red, Green, Blue, and Alpha values. ● Examples: Objects

Loading texture data ● OpenGL has no built-in mechanism for loading textures. – OpenGL does not provide functions to read an image file into a texture array in memory. You have to fill the components of the texture array by yourself. ● However, there are texture loaders (free source code) that you can use to read PNG, RGB, BMP, etc. image files into a texture array in an OpenGL program. – BMP loader ● – glpng library: ●

Texture Mapping Process ● Applying texture images to polygons. ● The basic texture mapping steps are: ● Specify the texture. – glTexImage – gluScaleImage ● Indicate how the texture is to be applied to each pixel. – glTexEnv – glTexParameter ● Enable texture mapping. – glEnable ● Draw the scene, providing geometric and texture coordinates. – glTexCoord

Specifying a Texture ● void glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels) – pixels - const GLvoid *, pointer to the image data in memory – Width and height must be a power of 2.

What if the texture is the wrong size? ● glTexImage2D() requires a texture whose pixel dimensions are powers of two ● If necessary, use the OpenGL utility routine gluScaleImage() to scale the image ● Pass the scaled image to glTexImage2D()

Scaling texture images ● GLint gluScaleImage( GLenum format, GLsizei widthin, GLsizei heightin, GLenum typein, const void *datain, GLsizei widthout, GLsizei heightout, GLenum typeout, void *dataout ) – format specifies the format of the pixel data ● GL_RGB, GL_RGBA, etc. – typein/typeout specifies the type ● GL_UNSIGNED_INT, GL_INT, GL_FLOAT, etc.

Texture coordinates ● Texture coordinates are part of the data that is associated with each vertex. ● A 2D texture is treated as a 1x1 square whose texture coordinates go from 0.0 to 1.0 in each dimension. ● Texture coordinates are usually specified with (s, t) ● Texture coordinates are assigned to each vertex of a polygon. ● Texture coordinates are interpolated as a polygon is filled. ● Texture filters control how the interpolation is performed

Assigning texture coordinates to 3D object vertices ● void glTexCoord2f (s, t) glBegin( GL_QUADS ); glTexCoord2fv( t0 ); glVertex3fv( v0 ); glTexCoord2fv( t1 ); glVertex3fv( v1 ); glTexCoord2fv( t2 ); glVertex3fv( v2 ); glTexCoord2fv( t3 ); glVertex3fv( v3 ); glEnd();

Which Texel Goes With Which Pixel? ● One texel rarely corresponds to one pixel on the final screen image Texture information must be magnified Texture information must be minified OpenGL provides several filters to magnify or minify a texture to make a trade-off between speed and image quality

Magnification/Minification Filters ● void glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, param ) – param specifies the option ● GL_NEAREST to choose the texel nearest to the texture coordinate computed for the pixel. ● GL_LINEAR to use the weighted average of the four texels nearest to the texture coordinate computed for the pixel.

Multiple Textures ● Most of the time you will want to apply different textures to different objects on the scene. ● OpenGL provide you texture objects to manipulate different textures you have. ● A set of textures and their related states can be treated as a single texture object. ● You bind a name with a texture object when you create it, then define the image data and parameters of the texture

Multiple Textures ● As you render your scene, bind the name of each desired texture object to the appropriate texture target. – The texture names become aliases for the textures currently bound to them ● Since binding (reusing) a texture takes less time than defining (and reloading) one, this is a more efficient way to switch from one texture to another. – So, if you are using more than one texture, always set up the textures as texture objects!

Using Texture Objects ● void glGenTextures(GLsize n, GLuint *texnames) – Generate texture names ● void glBindTexture(GL_TEXTURE_2D, GLuint texname) – Create a new texture object and assign it a name (first time) – Call with texname = 0 to stop using texture objects (unbind) ● void glDeleteTextures ( sizei n, uint *textures )

Example static GLuint texnames[2]; glGenTextures(2, texnames); /* generate unused texture names */ /* bind, then define, each texture */ glBindTexture(GL_TEXTURE_2D, texnames[0]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, redtex); glBindTexture(GL_TEXTURE_2D, texnames[1]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D(GL_TEXTURE_2D, 0, 4, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, greentex);... glBindTexture(GL_TEXTURE_2D, texnames[1]); drawTexturesPolygon(); /* uses greentex */ glBindTexture(GL_TEXTURE_2D, texnames[0]); drawTexturesPolygon(); /* uses redtex */

Enabling Texture Mapping ● glEnable (GL_TEXTURE_2D)

Advanced Topics ● Applying textures to curved surfaces smoothly ● Multiple levels of detail: mipmaps ● Changing the texture environment: Specifying how the texture colors interact with the original polygon colors.

Changing Texture Environment ● glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); ● Tells OpenGL to apply lighting and coloring effects to the texture.

References ● nGL_tutorial/en/10texturemapping_000.html nGL_tutorial/en/10texturemapping_000.html ● article947.asp article947.asp

Texture Mapping Example The geometric model

Texture Mapping Example The texture

Texture Mapping Example Texture mapped object