1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.

Slides:



Advertisements
Similar presentations
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
Advertisements

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.
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
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
Hofstra University1 Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass,
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Informationsteknologi Thursday, November 29, 2007Computer Graphics - Class 131 Today’s class Antialiasing Hidden surface removal Texture mapping.
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.
Texturing in OpenGL Lab #7. Creating Textures glEnable ( GL_TEXTURE_2D ); GLuint myTex; glGenTextures ( 1, (GLuint*) &myTex ); glBindTexture ( GL_TEXTURE_2D,
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.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
Lecture 8: Texture Mapping 1  Principles of Interactive Graphics  CMSCD2012  Dr David England, Room 718,  ex 2271
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.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
An Interactive Introduction to OpenGL Programming Ed Angel
Texture Mapping (cont.) Jian Huang, CS 594, updated in Fall’08.
CS 4363/6353 TEXTURE MAPPING PART II. WHAT WE KNOW We can open image files for reading We can load them into texture buffers We can link that texture.
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
Imaging and Raster Primitives Vicki Shreiner. 2 Jobs Andrew Giles Andrew Giles Chuck Fultz Chuck Fultz SIGGraph - SIGGraph.
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.
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.
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 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(...); + =
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.
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.
OpenGL Graphics Textures. Quiz You didn't see that coming!
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
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.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Texture Mapping Part II
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
Introduction to Computer Graphics with WebGL
Texture Motivation: to model realistic objects need surface detail: wood grain, stone roughness, scratches that affect shininess, grass, wall paper. Use.
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
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry

2 Main steps Task: we have a raw RGB image data in a buffer and we want to apply it to our geometry in OpenGL First thing you have to do before OpenGL can use this raw texture data is upload it to the video memory. Once a texture is uploaded to the video memory it can be used throughout the time in which your application is running. Before a texture can be uploaded to the video memory there is some setup that must take place so OpenGL knows what to do with the image data that is passed to it.

3 Main Steps Below certain calls are given that need to be made in order to upload your texture. Note that these calls should be made once per texture when the application is started. The order is important.

4 Uploading the texture 1. Call glBindTexture. It tells OpenGL which texture "id" we will be working with. glBindTexture Example: glBindTexture (GL_TEXTURE_2D, 15); A texture "id" is just a number that you will use to access your textures. This call will make texture that is associated with the id of 15 the active texture. Any calls that have to do with OpenGL texture mapping will effect this texture.

5 Uploading the texture 2. Call glPixelStorei. It tells OpenGL how the data that is going to be uploaded is aligned. Recommended parameters are given below. Example: glPixelStorei (GL_UNPACK_ALIGNMENT, 1);

6 Uploading the texture 3. Call glTexParameteri. It sets the various parameters for the current OpenGL texture. (The parameters that are passed and their effects on the texture are an advanced topic.) Follow the example. Example: glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

7 Uploading the texture 4. Call glTexEnvf. It sets environment variables for the current texture, i.e., it tells how the texture will act when it is rendered into a scene. Example: glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); The GL_MODULATE attribute allows you to apply effects such as lighting and coloring to your texture. If you do not want lighting and coloring to effect your texture and you would like to display the texture unchanged when coloring is applied replace GL_MODULATE with GL_DECAL.

8 Uploading the texture 5. Call glTexImage2D. It uploads the texture to the video memory where it will be ready for us to use in our programs. Example: glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); Parameters: 1) target - The target of this call, it will always be GL_TEXTURE_2D. 2) level - The level of detail number, this should be left at 0 for our purposes.

9 Uploading the texture 5. glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); Parameters: 3) internalformat - Internal components parameter. This tells OpenGL how many color components to represent internally from the texture that is uploaded. There are many symbolic constants for this parameter but the one which is most widely used is GL_RGB. 4 & 5) width & height - The width and height of the image data. These must be integers that are equal to 2n+2(border) for some integer n. What this basically means is that the texture width and height must be a power of two (2,4,8,16,32,63,128,256,512, etc).

10 Uploading the texture 5. glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); Parameters: 6) border - Image border, must be 0 or 1. 1 if you want a real border. 7) format - Format of the pixel data that will be uploaded. There are many constants which are accepted but GL_RGB is the value that is widely used.

11 Uploading the texture 5. glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); Parameters: 8) type - Type of data that will be uploaded. Again there are several symbolic constants but the most used is GL_UNSIGNED_BYTE. 9) pixels - Pointer to the image data. This is the image data that will be uploaded to the video memory. Note that after your call to glTexImage2D you can free this memory since the texture is already uploaded into video memory.

12 Uploading the texture After you have done everything above the texture will me uploaded and ready to be applied to your geometry. The next section will discuss the application of the texture to geometry.

13 Applying a texture to geometry The process for applying a texture to geometry greatly depends on what type of data you are dealing with and how you would like things to run.

14 Applying a texture to geometry Remarks: 1 Make sure that you have enabled texturing. You do this with the glEnable (GL_TEXTURE_2D) call. 2 Make sure that you bind to a texture before you do any sort of glBegin/glEnd. You cannot bind to a texture in the middle of a begin/end pair. 3 Make sure that you specify a texture coordinate before each vertex that makes up a face. If you have 3 vertices the pattern for texture mapping the triangle would go like this: TexCoord; VertexCoord; TexCoord; VertexCoord; TexCoord; VertexCoord;

15 Applying a texture to geometry Remarks: 4 Make sure that you store your texture id's in variables, it makes things easier. 5 Make use of glGenTextures. It is an easy way to get a free texture id.

16 Applying a texture to geometry Example: how to texture a quad. This code assumes that texturing has been enabled and that there has been a texture uploaded with the id of 15. glBindTexture (GL_TEXTURE_2D, 15); glBegin (GL_QUADS); glTexCoord2f (0.0, 0.0); glVertex3f (0.0, 0.0, 0.0); glTexCoord2f (1.0, 0.0); glVertex3f (10.0, 0.0, 0.0); glTexCoord2f (1.0, 1.0); glVertex3f (10.0, 10.0, 0.0); glTexCoord2f (0.0, 1.0); glVertex3f (0.0, 10.0, 0.0); glEnd ();

17 Applying a texture to geometry Texture coordinates Remark: if we map a texture to a triangle, we have to specify three vertices of the texture.