DOC PREVIEW
CMU CS 15462 - lecture

This preview shows page 1-2-3-4-5-34-35-36-37-68-69-70-71-72 out of 72 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 72 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Announcements•Project 1 due today at midnight.•Homework 1 will be posted later today.2Basics of TexturesBasics of texture mapping in OpenGLBasics of texture mapping in OpenGL4Texture Mapping• A way of adding surface details • Two ways can achieve the goal:– Model the surface with more polygons» Slows down rendering speed» Hard to model fine features5Texture Mapping• A way of adding surface details • Two ways can achieve the goal:– Model the surface with more polygons» Slows down rendering speed» Hard to model fine features– Map a texture to the surface» This lecture» Image complexity does not affect complexity of processing6The texture• Texture is a bitmap image• 2D array: texture[height][width][4]• Pixels of the texture called texels• Texel coordinates (s,t) scaled to [0,1] rangest0,01,01,10,17Map textures to surfacesThe polygon can havearbitrary size and shape!"#"$!%#"$!"#%$ !%#%$!"#"#"$!%"#"#"$!&#%"#"$!%&#%"#" $8• Use GLTexCoord2f(s,t) to specify texture coordinates• Example:• State machine: Texture coordinates remain valid until you changethem or exit texture mode via glDisable (GL_TEXTURE_2D)The drawing itselfglEnable(GL_TEXTURE_2D)glBegin(GL_QUADS);glTexCoord2f(0.0,0.0); glVertex3f(0.0,0.0,0.0);glTexCoord2f(0.0,1.0); glVertex3f(2.0,10.0,0.0);glTexCoord2f(1.0,0.0); glVertex3f(10.0,0.0,0.0);glTexCoord2f(1.0,1.0); glVertex3f(12.0,10.0,0.0);glEnd();glDisable(GL_TEXTURE_2D)9Color blending• Final pixel color = f (texture color, object color)• How to determine the color of the final pixel?– GL_REPLACE – use texture color to replace object color – GL_BLEND – linear combination of texture and object color– GL_MODULATE – multiply texture and object color • Example: – glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);10What happens if texture coordinatesoutside [0,1] ?• Two choices:– Repeat pattern (GL_REPEAT)– Clamp to maximum/minimum value (GL_CLAMP)• Example:– glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)– glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)11What happens if texture coordinatesoutside [0,1] ?repeatclampglTexCoord2f(0.0, 0.0); glVertex3f(0.0, 0.0, 0.0);glTexCoord2f(0.0, 3.0); glVertex3f(0.0, 10.0, 0.0);glTexCoord2f(3.0, 0.0); glVertex3f(10.0, 0.0, 0.0);glTexCoord2f(3.0, 3.0); glVertex3f(10.0, 10.0, 0.0);12Texture Value Lookup• For given texture coordinates (s,t), we can find a unique image value, corresponding to the texture image at that location !"#"$!%&'(#%$!%&(#%$ !%&)(#%$!"#%$!%#%$P(x,y,z)3D geometryTexture (5x5):T(s,t)!%#%$ !"%#%$!%#"%$!"%#"%$13Interpolating colors• Some (s,t) coordinates not directly at pixel in the texture, but in between14Interpolating colors• Solutions:– Nearest neighbor» Use the nearest neighbor to determine color» Faster, but worse quality» glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);– Linear interpolation» Incorporate colors of several neighbors to determine color» Slower, better quality» glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER, GL_LINEAR)Other solutions•Signal processing.•What is wrong with linear interpolation...Antialiasing...15Texture Levels16Texture mapping in OpenGL• In init():– Specify texture» Read image from file into an array in memory or generate the image using the program– Specify texture mapping parameters» Wrapping, filtering, etc.– Define (activate) the texture• In display():– Enable GL texture mapping– Draw objects: Assign texture coordinates to vertices– Disable GL texture mapping17// texture wrapping onglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // repeat pattern in s texture coordinateglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // repeat pattern in t texture coordinate// use nearest neighbor for both minification and magnificationglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);Specifying texture mapping parameters• Use glTexParameteri• Example:18Defining (activating) texture• Do once in init() to set up initial pattern• To use another texture, make further calls in display() to glTexImage2D, specifying another image– But this is slow: use Texture Objects itself• The dimensions of texture images must be powers of 2– if not, rescale image or pad with zeros• glTexImage2D(Glenum target, Glint level, Glint internalFormat, int width, int height, Glint border, Glenum format, Glenum type, Glvoid* img)• Example:– glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pointerToImage)19Enable/disable texture mode• Can do in init() or successively in display()• glEnable(GL_TEXTURE_2D)• glDisable(GL_TEXTURE_2D)• Successively enable/disable texture mode to switch between drawing textured/non-textured polygons• Changing textures: – Only one texture active at any given time– make another call to glTexImage2D to make another pattern active20• Use GLTexCoord2f(s,t) to specify texture coordinates• State machine: Texture coordinates remain valid until you change them or exit texture mode via glDisable (GL_TEXTURE_2D)• Example:The drawing itselfglEnable(GL_TEXTURE_2D)glBegin(GL_QUADS);glTexCoord2f(0.0,0.0); glVertex3f(-2.0,-1.0,0.0);glTexCoord2f(0.0,1.0); glVertex3f(-2.0,1.0,0.0);glTexCoord2f(1.0,0.0); glVertex3f(0.0,1.0,0.0);glTexCoord2f(1.0,1.0); glVertex3f(0.0,-1.0,0.0);…glEnd();glDisable(GL_TEXTURE_2D)21Everything togethervoid init(void):{…put image into 2D memory array; // can use libpicio library// specify texture parametersglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // repeat pattern in sglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // repeat pattern in t// use nearest neighbor for both minification and magnificationglTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);// make the pattern at location pointerToImage the active patternglTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pointerToImage)…}22Everything together (contd.)void display(void):{…// no blending, use texture color directlyglTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE); // turn on texture modeglEnable(GL_TEXTURE_2D);glBegin(GL_QUADS); // draw a quadglTexCoord2f(0.0,0.0); glVertex3f(-2.0,-1.0,0.0);glTexCoord2f(0.0,1.0);


View Full Document

CMU CS 15462 - lecture

Download lecture
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view lecture and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view lecture 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?