100 likes | 235 Vues
Pixels and Textures. Geb Thomas Adapted from the OpenGL Programming Guide. Learning Objectives. Learn how to copy information from the framebuffer Learn what a texture is Learn how to use textures. Copying Framebuffers.
E N D
Pixels and Textures Geb Thomas Adapted from the OpenGL Programming Guide
Learning Objectives • Learn how to copy information from the framebuffer • Learn what a texture is • Learn how to use textures
Copying Framebuffers • 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*().
ReadPixels • void glReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels); • Reads pixel data from the framebuffer rectangle whose lower-left corner is at (x, y) and whose dimensions are width and height and stores it in the array pointed to by pixels. format indicates the kind of pixel data elements that are read, and type indicates the data type of each element.
Format • GL_COLOR_INDEX: A single color index • GL_RGB: A red color component, followed by a green color component, followed by a blue color component • GL_RGBA: A red color component, followed by a green color component, followed by a blue color component, followed by an alpha color component
Data Type • GL_UNSIGNED_BYTE: unsigned 8-bit integer • GL_BYTE: signed 8-bit integer • GL_BITMAP: single bits in unsigned 8-bit integers using the same format as glBitmap()
Texture Mapping • Create the texture • Decide how to apply the texture • Enable texture mapping • Draw the scene, providing texture coordinates
Creating the Texture • Normally you read in an image and create the texture pattern buffer • OpenGL does not provide convenient ways to read in an image, you have to use an external library for this, such as this free library for reading and writing JPEG files.
Decide how to apply the texture • Decal? • Modify the current colors? • Blend with the current colors? • Modify the current normals? • Repeat at edges, or clip?
Learning Objectives • Learn how to copy information from the framebuffer • Learn what a texture is • Learn how to use textures