2 COEN 290 - Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.

Slides:



Advertisements
Similar presentations
Graphics Pipeline.
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) =
Texture Mapping CPSC /24/03 Abhijeet Ghosh.
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.
Informationsteknologi Thursday, November 29, 2007Computer Graphics - Class 131 Today’s class Antialiasing Hidden surface removal Texture mapping.
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.
11/11/04© University of Wisconsin, CS559 Fall 2004 Last Time Shading Interpolation Texture mapping –Barycentric coordinates for triangles.
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.
Mapping method Texture Mapping Environmental mapping (sphere mapping) (cube mapping)
An Interactive Introduction to OpenGL Programming Ed Angel
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.
Texture Mapping Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
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.
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
Computer Graphics Bing-Yu Chen National Taiwan University.
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.
Texture Mapping. For Further Reading Angel 7 th Ed: ­Chapter 7: 7.3 ~ 7.9 Beginning WebGL: ­Chapter 3 2.
1 Chapter 7 Texture Mapping. 2 The Limits of Geometric Modeling Although graphics cards can render over 10 million polygons per second, that number is.
Viewing and Texture Mapping In OPENGL. VIEWING 1.One or more objects 2.A viewer with a projection surface 3.Projectors that go from the object(s) to.
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.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
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
Angel: Interactive Computer Graphics5E © Addison-Wesley 2009
OpenGL Texture Mapping
Introduction to Computer Graphics with WebGL
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Chapters VIII Image Texturing
Introduction to Texture Mapping
(c) University of Wisconsin, CS 559
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and settings for texture mapping

3 COEN Computer Graphics I Image Primitives n Color information for every pixel primitive lots of information - lots of storage n Passed to OpenGL as an array of color values n OpenGL doesn’t understand image file formats

4 COEN Computer Graphics I Rendering Image Primitives n Position image primitive in world coordinates n Pass image data to OpenGL images come in two forms –bitmaps –color images

5 COEN Computer Graphics I Positioning Images glRasterPos3f( x, y, z ); n Transformed just like a vertex n Raster position is lower left corner of image n Images are clipped based upon whether their raster position in inside the viewport Corner aligned with Raster Position

6 COEN Computer Graphics I Rendering Bitmaps n Bitmaps are 1-bit deep images n Use the current color to update pixel in framebuffer sort of like a pixel mask glBitmap( width, height, xorig, yorig, xmove, ymove, bitmap );

7 COEN Computer Graphics I Rendering Images glDrawPixels( width, height, format, type, pixels ); n Write color information directly into the framebuffer format describes how pixels are laid out in host memory type is storage type of pixels array

8 COEN Computer Graphics I Rendering Image Example GLubyte checkerBoard[2][2][3] = { {0,0,0},{1,1,1},{1,1,1},{0,0,0} }; glRasterPos2f( 100.0, ); glDrawPixels( 2, 2, GL_RGB, GL_UNSIGNED_BYTE, checkerBoard );

9 COEN Computer Graphics I Reading Pixels glReadPixels( x, y, width, height, format, type, pixels ); n Copy pixels from the framebuffer into host memory (x,y) is the window coordinate of lower left corner of block of pixels

10 COEN Computer Graphics I Zooming Images n Images can be zoomed in or out glPixelZoom( xZoom, yZoom );

11 COEN Computer Graphics I Images Have Some Limitations n Always aligned to the window n Can not be rotated easily no concept of world space n Pixel zoom inexact in particular, difficult to match world space dimensions n Some performance limitations

12 COEN Computer Graphics I A Much More Flexible Solution n Imagine combining geometric rendering but using an image for the shading n Principal idea behind texture mapping also known as image mappings

13 COEN Computer Graphics I Benefits of Texture Mapping n Greater realism with less modeling without texture mapping, need to model geometry at pixel resolution n Fairly simple to implement interpolate indices into texture map –similar interpolation to Gouraud shading

14 COEN Computer Graphics I Disadvantages with Texture Mapping n Considerable performance requirements easily implemented in hardware, but filling pixels require much more work than Gouraud shading dedicated texture memory in graphics hardware is usually a limited resource n Aliasing requires texture filtering –more math per pixel

15 COEN Computer Graphics I Texture Mapping n Use image data to determine the color of pixels for rasterizing geometric primitives n Can texture in 1, 2 or 3 dimensions 3D texturing very useful for volume rendering n Two step process: À set up image as a texture map Á render geometry with texture coordinates to reference texture

16 COEN Computer Graphics I Passing Image Data as a Texture glTexImage2D( target, level, components, width, height, border, format, type, pixels ); images must have dimensions –may additionally have a one pixel border around image set target to GL_TEXTURE_2D set level to 0 –we’ll use levels later when we talk about mipmaps

17 COEN Computer Graphics I Other Parameters components represents number of color channels per pixel generally –1 for intensity images –3 for RGB images may include an alpha channel format represents how texels are stored in memory texel is short for texture element

18 COEN Computer Graphics I Texture Space s t (0,0) (1,1)

19 COEN Computer Graphics I Texture Coordinates n Texture coordinates determine which texels are selected from the texture map. s t 1, 1 0, 1 0, 01, 0 (s, t) = (0.2, 0.8) (0.4, 0.2) (0.8, 0.4) A BC a b c Texture SpaceObject Space

20 COEN Computer Graphics I Specifying Texture Coordinates n Methods explicitly specify texture coordinates –more control –more modeling have OpenGL generate them for us –easy –limited applicability

21 COEN Computer Graphics I Explicit Texture Coordinates glTexCoord2f( s, t ); n Vertex attribute like color or lighting normals glBegin( GL_TRIANGLES ); glTexCoord2f( 0, 0 ); glVertex3fv( v1 ); glTexCoord2f( 0, 1 ); glVertex3fv( v2 ); … glEnd();

22 COEN Computer Graphics I Generating Texture Coordinates n OpenGL can generate texture coordinates based on a vertex’s position in space n Compute distance from a user specified plane in space s

23 COEN Computer Graphics I Setting up How to Generate Coordinates glTexGenfv( coord, prop, params ); coord is which texture coordinate we want to generate coords for GL_S, GL_T, GL_R, GL_Q set prop to GL_TEXTURE_GEN_MODE param defines which coordinate space we’re going to generate coords in GL_OBJECT_LINEAR GL_EYE_LINEAR

24 COEN Computer Graphics I Object Linear vs. Eye Linear GL_OBJECT_LINEAR computes texture coordinates in world coordinates relationship between texture plane and object remains the same object looks like its been covered in wallpaper GL_EYE_LINEAR computes texture coordinates in eye coordinates objects looks like its “swimming” through the texture

25 COEN Computer Graphics I Setting up Texture Generation Plane glTexGenfv( coord, prop, params ); coord is which texture coordinate we want to generate coords for GL_S, GL_T, GL_R, GL_Q prop defines which plane we’re setting GL_OBJECT_PLANE GL_EYE_PLANE

26 COEN Computer Graphics I Setting up Texture Generation Plane (cont.) params defines the plane equation plane transformed by current ModelView matrix GLfloat plane[] = {1,0,0,1}; glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR ); glTexGenfv( GL_S, GL_OBJECT_PLANE, plane ); glEnable( GL_TEXTURE_GEN_S );

27 COEN Computer Graphics I Texture Coordinate Modes n Recall that texture coordinates are defined only in [0,1] n Two options if outside that range clamp values to range ignore integer part and only use fractional part Repeat Mode Clamp Mode

28 COEN Computer Graphics I Setting Texture Wrap Modes glTexParameteri( target, prop, param ); target is GL_TEXTURE_2D prop is GL_TEXTURE_WRAP_{S,T} n param GL_CLAMP GL_REPEAT

29 COEN Computer Graphics I Telling OpenGL how to Apply a Texture n Several options in how we should use texture’s colors for our primitive replace primitives color with that of texture combine the texture and primitive color n We need to set texture environment describes how textures should be applied

30 COEN Computer Graphics I Texture Environments glTexEnvf( target, prop, params ); prop is GL_TEXTURE_ENV_MODE param is either GL_DECAL GL_BLEND –recall that a fragment is an OpenGL pixel

31 COEN Computer Graphics I Texture Objects n Its convenient to bundle all this stuff together glBindTexture( target, texId ); n Use twice in your program when defining a texture object when using that texture to render Use glGenTextures() to create unique texture identifiers

32 COEN Computer Graphics I A Complete Example GLuint texId; void init( void ) { GLfloat pixels[w][h][3] = { … }; glGenTextures( 1, &texId ); glBindTexture( GL_TEXTURE_2D, texId ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );

33 COEN Computer Graphics I A Complete Example ( cont. ) glTexImage2D( GL_TEXTURE_2D, 0, 3 w, h, 0, GL_RGB, GL_FLOAT, pixels ); glEnable( GL_TEXTURE_2D ); }

34 COEN Computer Graphics I A Complete Example ( cont. ) void render( void ) { … glBindTexture( GL_TEXTURE_2D, texId ); glBegin( GL_TRIANGLES ); glTexCoord2fv( t0 ); glVertex3fv( v0 ); glTexCoord2fv( t1 ); glVertex3fv( v1 ); glTexCoord2fv( t2 ); glVertex3fv( v2 ); glEnd(); }

35 COEN Computer Graphics I And that would almost work... n OpenGL’s default state makes an assumption which won’t quite get us there n OpenGL defines one more texture feature, called texture filtering

36 COEN Computer Graphics I Texture Filtering n Ideally, texel resolution would match pixel resolution but then, we’d just be drawing images n When they don’t match, we need to compensate minification - when pixels are smaller than texels magnification - when pixels are larger than texels

37 COEN Computer Graphics I Filter Modes TexturePolygon MagnificationMinification PolygonTexture

38 COEN Computer Graphics I Texture Magnification n Not enough information to be able to fill in every pixel “correctly” n Need to set OpenGL’s magnification filter n Two options repeat texels to fill pixels average closest texels to fill pixels

39 COEN Computer Graphics I Texture Magnification ( cont. ) glTexParameteri( target, prop, param ); prop is GL_TEXTURE_MAG_FILTER param is either GL_NEAREST GL_LINEAR

40 COEN Computer Graphics I Texture Minification n Opposite problem of magnification too much information more processing options n Same sampling options as magnification GL_NEAREST GL_LINEAR n Additional technique to reduce aliasing mipmapping

41 COEN Computer Graphics I Mipmaps n Multiple resolution versions of the same image Level 0Level 1Level 2Level 3

42 COEN Computer Graphics I Creating Mipmaps gluBuild2DMipMaps( target, components, width, height, format, type, pixels ); n Automatically builds mipmap levels from source image. n Automatically scales image if not dimensions are not a power of two.

43 COEN Computer Graphics I Texture Minification ( cont. ) glTexParameteri( target, prop, param ); prop is GL_TEXTURE_MIN_FILTER param is either GL_NEAREST GL_LINEAR GL_NEAREST_MIPMAP_NEAREST GL_NEAREST_MIPMAP_LINEAR GL_LINEAR_MIPMAP_NEAREST GL_LINEAR_MIPMAP_LINEAR