Computer Graphics 9 - PowerPoint PPT Presentation

About This Presentation
Title:

Computer Graphics 9

Description:

Computer Graphics 9 Lee Byung-Gook – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 31
Provided by: kowonDon3
Category:

less

Transcript and Presenter's Notes

Title: Computer Graphics 9


1
Computer Graphics 9
  • Lee Byung-Gook

2
Texture Mapping
  • Definition A 2-dimensional (2D) texture map is
    an image that is applied to one side of a
    3-dimensional polygon.
  • Problems
  • The image and the 3D polygon typically do not
    have the same shape (most polygons are not
    rectangles).
  • The image and the 3D polygon typically do not
    have the same size

3
Texture Mapping
4
Texture Mapping
  • The image and the 3D polygon typically do not
    have the same shape
  • Solution specify the portion of the image that
    is to be used to "paint" the polygon. Since we
    need to specify a subset of the whole image, it
    is natural to use percentages of the image
    dimensions. The percentages are specified as
    values between 0 (0) and 1.0 (100).

5
Texture Mapping
6
Texture Mapping
  • The image and the 3D polygon typically do not
    have the same size.
  • Solution the number of pixels used to display a
    polygon is dependent on the current MODELVIEW and
    PROJECTION matrices. (If the camera is close to
    the polygon, it will appear large in the window
    and require many pixels to represent it if the
    camera is far away from the polygon, it will take
    very few pixels to represent it.)

7
Texture Mapping
  • If there are more pixels on the screen that
    require colors than there are pixels in the
    texture image, then the texture image must be
    magnified (made larger).
  • If there are fewer pixels on the screen as
    compared to the texture image, then the texture
    image must be minified (made smaller).
  • There are two general solutionsAfter mapping the
    pixel into the texture image take the color of
    the closest texture pixel (OpenGL calls this
    GL_NEAREST, which produces fast, but poor
    graphics)take a linear average of the colors of
    the surrounding pixels. (OpenGL calls this
    GL_LINEAR, which produces better, but slower
    graphics)

8
Texture map compositing
  • Compositing occurs when a pixel's color value is
    determined by using a combination of two (or
    more) color values.
  • When using texture maps we have 2 colors to deal
    with - the color of the face and the color from
    the texture map
  • Ct - the color defined by the texture map
  • Cf - the color of the polygon face
  • Cc - the color defined by the global texture
    color
  • C - the color to be placed in the color buffer
  • The "global texture color" is defined using the
    parameter GL_TEXTURE_ENV_COLOR

9
Compositing methods
  • Replace the current color in the color buffer
    with the texture map color. (GL_REPLACE) C Ct
  • Combine the color of the face with the color of
    the texture map by multiplying their values
    together. (GL_MODULATE) C CfCt
  • Combine the color of the face with the color of
    the texture map by adding a percentage of both
    (the percentage is controlled by the alpha values
    of the texture map)
  • (GL_DECAL) C Cf(1-At) CtAt
  • Combine the color of the face and the color of
    the texture map using the texture values as
    percentages of a "global texture color" Cc.
    (GL_BLEND) C Cf(1-Ct) CcCt

10
Lab 17
  • downloading

11
makeCheckImage
  • define checkImageWidth 64
  • define checkImageHeight 64
  • GLubyte checkImagecheckImageHeightcheckImageWi
    dth4
  • void makeCheckImage(void)
  • int i, j, c
  • for (i 0 i lt checkImageHeight i)
  • for (j 0 j lt checkImageWidth j)
  • c ((((i0x8)0)((j0x8))0))255
  • checkImageij0 (GLubyte) c
  • checkImageij1 (GLubyte) c
  • checkImageij2 (GLubyte) c
  • checkImageij3 (GLubyte)
    i(255/checkImageHeight)

12
myInit
  • makeCheckImage()
  • glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILT
    ER, GL_NEAREST)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  • glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
    checkImageWidth, checkImageHeight, 0, GL_RGBA,
    GL_UNSIGNED_BYTE, checkImage)
  • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
    GL_REPLACE)
  • glEnable(GL_TEXTURE_2D)

13
myDisplay
  • glColor3fv(color9)
  • glBegin(GL_QUADS)
  • glTexCoord2f(0.0, 0.0) glVertex3f(0., 0., 1.)
  • glTexCoord2f(1.0, 0.0) glVertex3f(1., 0., 1.)
  • glTexCoord2f(1.0, 1.0) glVertex3f(1., 1., 1.)
  • glTexCoord2f(0.0, 1.0) glVertex3f(0., 1., 1.)
  • glTexCoord2f(0.0, 0.0) glVertex3f(1., 1., 1.)
  • glTexCoord2f(1.0, 0.0) glVertex3f(1., 0., 1.)
  • glTexCoord2f(1.0, 1.0) glVertex3f(1., 0., 0.)
  • glTexCoord2f(0.0, 1.0) glVertex3f(1., 1., 0.)
  • glEnd()

14
glTexParameter
  • void glTexParameterfi( GLenum target, GLenum
    pname, GLint param )
  • These functions set texture parameters.
  • target The target texture, which must be either
    GL_TEXTURE_1D or GL_TEXTURE_2D.
  • pname The symbolic name of a single-valued
    texture parameter. The following symbols are
    accepted in pname GL_TEXTURE_MIN_FILTER,
    GL_TEXTURE_MAG_FILTER, GL_TEXTURE_WRAP_S,
    GL_TEXTURE_WRAP_T

15
glTexParameter
  • GL_TEXTURE_MIN_FILTER
  • GL_NEAREST or GL_LINEAR
  • GL_TEXTURE_MAG_FILTER
  • GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST,
    GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST
    or GL_LINEAR_MIPMAP_LINEAR
  • GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T
  • GL_CLAMP or GL_REPEAT

16
glTexEnv
  • void glTexEnvfi( GLenum target, GLenum pname,
    GLfloat param )
  • These functions set texture environment
    parameters
  • target A texture environment. Must be
    GL_TEXTURE_ENV.
  • pname The symbolic name of a single-valued
    texture environment parameter. Must be
    GL_TEXTURE_ENV_MODE.
  • param A single symbolic constant, one of
    GL_MODULATE, GL_DECAL, or GL_BLEND.

17
glTexImage2D
  • void glTexImage2D( GLenum target, GLint level,
    GLint components, GLsizei width, GLsizei height,
    GLint border, GLenum format, GLenum type, const
    GLvoid pixels )
  • The glTexImage2D function specifies a
    two-dimensional texture image.
  • target The target texture. Must be
    GL_TEXTURE_2D.
  • level The level-of-detail number. Level 0 is
    the base image level. Level n is the nth mipmap
    reduction image.
  • components The number of color components in
    the texture. Must be 1, 2, 3, or 4.
  • width The width of the texture image. Must be
    2n  2(border) for some integer n.

18
glTexImage2D
  • height The height of the texture image. Must be
    2m  2(border) for some integer m.
  • border The width of the border. Must be either
    0 or 1.
  • format The format of the pixel data. It can
    assume one of nine symbolic values
    GL_COLOR_INDEX, GL_RGB, GL_RGBA, GL_RED,
    GL_GREEN, GL_BLUE, GL_ALPHA, GL_BGR_EXT,
    GL_BGRA_EXT, GL_LUMINACE, GL_LUMINACE_ALPHA.
  • type The data type of the pixel data. The
    following symbolic values are accepted
    GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP,
    GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT,
    GL_INT, and GL_FLOAT.
  • pixels A pointer to the image data in memory.

19
Texture map repetition
  • Texture maps require a lot of memory!
  • To save memory, some types of textures can be
    defined as small images and then repeated in both
    the horizontal and vertical directions

20
Texture map repetition
21
Lab 18
  • downloading

22
myInit
  • ReadBMP("hgeri.bmp", myImage)
  • glBindTexture(GL_TEXTURE_2D, 1)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MAG_FILTER, GL_NEAREST)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MIN_FILTER, GL_NEAREST)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_S, GL_REPEAT)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_T, GL_REPEAT)
  • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
    GL_REPLACE)
  • glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB,
    myImage.Width, myImage.Height, 0, GL_RGB,
    GL_UNSIGNED_BYTE, myImage.Pixels)

23
  • makeCheckImage()
  • glBindTexture(GL_TEXTURE_2D, 2)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_MAG_FILTER, GL_NEAREST)
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILT
    ER, GL_NEAREST)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_S, GL_REPEAT)
  • glTexParameteri(GL_TEXTURE_2D,
    GL_TEXTURE_WRAP_T, GL_REPEAT)
  • glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
    GL_REPLACE)
  • glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
    checkImageWidth, checkImageHeight, 0, GL_RGBA,
    GL_UNSIGNED_BYTE, checkImage)

24
myDisplay
  • glBindTexture(GL_TEXTURE_2D, 1)
  • glBegin(GL_QUADS)
  • glTexCoord2f(0.0, 0.0) glVertex3f(0., 0., 1.)
  • glTexCoord2f(3.0, 0.0) glVertex3f(1., 0., 1.)
  • glTexCoord2f(3.0, 3.0) glVertex3f(1., 1., 1.)
  • glTexCoord2f(0.0, 3.0) glVertex3f(0., 1., 1.)
  • glEnd()
  • glBegin(GL_POLYGON)
  • glTexCoord2f(3.0, 0.0) glVertex3f(0., 0., 1.)
  • glTexCoord2f(3.0, 3.0) glVertex3f(0., 1., 1.)
  • glTexCoord2f(0.0, 0.0) glVertex3f(0., 0., 0.)
  • glEnd()

25
myDisplay
  • glBindTexture(GL_TEXTURE_2D, 2)
  • glBegin(GL_QUADS)
  • glTexCoord2f(-1.0, -1.0) glVertex3f(1., 1.,
    1.)
  • glTexCoord2f(1.0, -1.0) glVertex3f(1., 0., 1.)
  • glTexCoord2f(1.0, 1.0) glVertex3f(1., 0., 0.)
  • glTexCoord2f(-1.0, 1.0) glVertex3f(1., 1., 0.)
  • glEnd()

26
glBindTexture
  • void glBindTexture( GLenum target, GLuint texture
    )
  • The glBindTexture function enables the creation
    of a named texture that is bound to a texture
    target.
  • target The target to which the texture is
    bound. Must have the value GL_TEXTURE_1D or
    GL_TEXTURE_2D.
  • texture The name of a texture the texture name
    cannot currently be in use.
  • The glBindTexture function enables you to create
    a named texture. Calling glBindTexture with
    target set to GL_TEXTURE_1D or GL_TEXTURE_2D, and
    texture set to the name of the new texture you
    have created binds the texture name to the
    appropriate texture target. When a texture is
    bound to a target, the previous binding for that
    target is no longer in effect.

27
Wrapping textures around spheres
  • Wrapping a texture around a sphere, such that
    there is no distortion, is impossible! (Take the
    surface of a ball and try to "flatten it out"
    without stretching it. It cannot be done!)
  • There are several possibilities for mapping a
    texture to a sphere. These are documented on page
    461 in the textbook. The following is a
    straightforward application of a texture to the
    parametric equation of a sphere.

28
Wrapping textures around spheres
29
Lab 19
  • downloading

30
Homework
  • In two weeks
  • Textute map your house with image
Write a Comment
User Comments (0)
About PowerShow.com