1 / 24

Class 27

Class 27. more textures environmental textures Color ramps Reading, writing, and copying pixels Drawing bitmaps Bump Maps. Wrapping Texture on Curved Surfaces. We want to wrap texture onto a curved surface, such as a beer can or a chess piece.

aliciaj
Télécharger la présentation

Class 27

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Class 27 more textures environmental textures Color ramps Reading, writing, and copying pixels Drawing bitmaps Bump Maps

  2. Wrapping Texture on Curved Surfaces • We want to wrap texture onto a curved surface, such as a beer can or a chess piece. • We assume as before that the object is modeled by a mesh, so it consists of a large number of small flat faces. • Each vertex of the mesh has an associated texture coordinate pair (si, ti). • The main question is finding the proper texture coordinate (s, t) for each vertex of the mesh.

  3. OpenGL Reflection Mapping • OpenGL provides a tool to perform approximate environment mapping where the texture is wrapped about a large enclosing sphere: • glTexGenf(GL_S,GL_TEXTURE_GEN_MODE, • GL_SPHERE_MAP); • glTexGenf(GL_T,GL_TEXTURE_GEN_MODE, • GL_SPHERE_MAP); • glEnable(GL_TEXTURE_GEN_S); • glEnable(GL_TEXTURE_GEN_T); • (Can use GL_CUBE_MAP)

  4. shrinkwrapping • Now when a vertex P with its unit normal m is sent down the pipeline, OpenGL calculates a texture coordinate pair (s, t) suitable for indexing into the texture attached to the surrounding sphere. • This is done for each vertex of the face on the object, and the face is drawn as always using interpolated texture coordinates (s, t) for points in between the vertices.

  5. There is GL_CUBE also if you have 6 textures (views in 6 directions) that you want applied.

  6. Example from Guha: sphereMapping.cpp

  7. Another Example fieldAndSkyOnSphereMJB.cpp Note culling trick for one texture on inside and one texture on outside. In general, disble texturing as soon as you draw what you want textured.

  8. For texturing: Use GL_REPLACE for no lighting, no "bleeding through" of color Use GL_MODULATE with a white background if you want lighting

  9. Color Ramps • greyscale : linearly go from (0,0,0) to (1,1,1) • rainbow example, several linear sections – see code. • ColorRamps.c

  10. RedbookImage.c • from Chapter 8 of the Red book http://glprogramming.com/red/chapter08.html • run and discuss RedbookImage.c • copies from part of the framebuffer to another part of the framebuffer • Does NOT call glutPostRedisplay(), except on reset • Does call flush() to show changes.

  11. Reading, Writing, and Copying Pixel data • glReadPixels() - Reads a rectangular array of pixels from the framebuffer and stores the data in processor memory. • glDrawPixels() - Writes a rectangular array of pixels from data kept in processor memory into the framebuffer at the current raster position specified by glRasterPos*(). • glCopyPixels() - Copies a rectangular array of pixels from one part of the framebuffer to another.

  12. Reading, Writing, and Copying Pixel data • glCopyPixels() command behaves similarly to a call to glReadPixels() followed by a call to glDrawPixels(), but the data is never written into processor memory.

  13. void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,GLenum format, GLenum type, GLvoid *pixels); • Reads pixel data from a rectangle in the framebuffer whose lower left coordinate is (x,y) and whose width is width and height is height and stores the data in the array pointed to by pixels.

  14. void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,GLenum format, GLenum type, GLvoid *pixels); • format is the kind of data, for example GL_RGB, but it could also be • GL_BLUE, • GL_LUMINANCE, • GL_DEPTH_COMPONENT, • ...

  15. void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height,GLenum format, GLenum type, GLvoid *pixels); • type is the type of the data, eg. GL_UNSIGNED_BYTE

  16. void glDrawPixels(GLsizei width, GLsizei height, GLenum format,GLenum type, const GLvoid *pixels); • Draws a rectangle of dimension width and height at the current roster position. • format and type as in glReadPixels(). • The array pointed to by pixels has the data to be drawn.

  17. void glCopyPixels(GLint x, GLint y, GLsizei width, GLsizei height,GLenum buffer); • copies a rectangle with lower left corner (x,y) and dimensions height and width from the buffer to the buffer at the current raster position.

  18. Magnifying, Reducing, and Flipping an image • void glPixelZoom(GLfloat zoomx, GLfloat zoomy);

  19. void glPixelZoom(GLfloat zoomx, GLfloat zoomy); • by default zoomx and zoomy are both 1.0 • If they are both 2 then each image pixel gets drawn to 4 screen pixels. • if (xrp,yrp) is the current raster position, image pixel in row n and column m, will go to the rectangle with corners (xrp + zoomx * n, yrp + zoomy * m) and (xrp + zoomx(n+1), yrp + zoomy(m+1)) • draws to the pixel if the center of pixel in box.

  20. Drawing bitmaps • run RedbookDrawF.c

  21. void glBitmap(GLsizei width, GLsizei height, GLfloat xbo, GLfloat ybo, GLfloat xbi, GLfloat ybi, const GLubyte *bitmap); • draws the bitmap pointed to by bitmap. • origin of bitmap at current raster position. xbo and ybo move the origin of the bitmap. • width and height are the dimensions of the bitmap, in pixels. • xbi and ybi are added to the raster position after drawing the bitmap.

  22. Sample bitmap

  23. starts at lower left corner GLubyte rasters[24] = { 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0x00, 0xff, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xc0, 0x00, 0xff, 0xc0, 0xff, 0xc0};

  24. Bump mapping – procedural textures • bumpmapping.cpp • Change the normals, to give an impression of a texture.

More Related