DOC PREVIEW
OSU CS 553 - Open GL Texture-Mapping Made Simpler

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 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 10 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 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

mjb – May 9, 2013 1 OpenGL Texture-Mapping Made Simpler Introduction Texture mapping is a computer graphics capability in which a separate image, referred to as the texture, is stretched onto a piece of 3D geometry and follows it however it is transformed. This image is also known as a texture map. This can be most any image, but its pixel dimensions must be a power of two. (This restriction has been lifted on some graphics cards, but just to be safe….) The X and Y dimensions do not need to be the same power of two, just a power of two. So, a 128x512 image would be OK, a 129x511 image would not. Also, to prevent confusion, the texture pixels are not called pixels. A pixel is a dot in the final screen image. A dot in the texture image is called a texture element, or texel. Similarly, to avoid terminology confusion, a texture’s width and height dimensions are not called X and Y. They are called S and T. A texture map is not generally indexed by its actual resolution coordinates. Instead, it is indexed by a coordinate system that is resolution-independent. The left side is always S=0., the right side is S=1., the bottom is T=0., and the top is T=1. Thus, you do not need to be aware of the texture’s resolution when you are specifying coordinates that point into it. Think of S and T as a measure of what fraction of the way you are into the texture. The mapping between the geometry of the 3D object and the S and T of the texture map works like this: T=1. S=0. T=0. S=1. (S0,T0) (S1,T1) (S3,T3) (S4,T4) (S2,T2) Interpolated (S,T) = (.78, .67) (.78,.67) in S and T = (199.68, 171.52) in texels 199 200 171 172 256 x 256 Texture Image 3D Polygon (199.68, 171.52)mjb – May 9, 2013 2 You specify an (s,t) pair at each vertex, along with the vertex coordinate. At the same time that OpenGL is interpolating the coordinates, colors, etc. inside the polygon, it is also interpolating the (s,t) coordinates. Then, when OpenGL goes to draw each pixel, it uses that pixel’s interpolated (s,t) to lookup a color in the texture image. Getting a Texture for Your Program Here are two ways to get a texture image for your program: Create the texture yourself. There are different ways to store this information, depending on whether you are storing 1, 2, 3, or 4 values per texel. To create 3 values (RGB) per texel, for example: unsigned char Texture[][3] = { { R0, G0, B0 }, { R1, G1, B1 }, { R2, G3, B2 }, ••• }; where: R0, G0, B0 the RGB values for the top-row, first-texel in the texture map, each in the range 0-255. R1, G1, B1 the RGB values for the top-row, second texel in the texture map. or, to create 4 values (RGBA) per texel, for example: unsigned char Texture[][4] = { { R0, G0, B0, A0 }, { R1, G1, B1, A1 }, { R2, G3, B2, A2 }, ••• }; where: R0, G0, B0, A0 the RGBA values for the top-row, first-texel in the texture map, each in the range 0-255. R1, G1, B1, A1 the RGBA values for the top-row, second texel in the texture map. Read the texture from an image file: unsigned char *BmpToTexture(); unsigned char *Texture; int width, height;mjb – May 9, 2013 ••• Texture = BmpToTexture( "filename.bmp This routine can be found as the bmpsomething that writes uncompressed format by a tool such as ImageMagick’s 1. Define the texture wrapping parameters. This will control what happens when a texture coordinate greater than 1.0 or less than 0.0 is encountered: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, where wrap is: GL_REPEAT specifies that this pattern will repeat (i.e., wraptexture coordinates less than 0.0 or greater than 1.0 are encountered. GL_CLAMP specifies Clamping 2. Define the texture filter parameters. This will control what happens when a texture is scaled up or down. glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, where filter is: BmpToTexture( "filename.bmp", &width, &height ); bmptotexture.c file. The file filename.bmp needs to be something that writes uncompressed 24-bit color BMP files, or converted to the uncompressed BMPImageMagick’s convert or Adobe Photoshop. Preparing to Draw: Define the texture wrapping parameters. This will control what happens when a texture coordinate greater than 1.0 or less than 0.0 is encountered: ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap ); ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap ); specifies that this pattern will repeat (i.e., wrap-around) if transformed texture coordinates less than 0.0 or greater than 1.0 are encountered.specifies that the pattern will “stick” to the value at 0.0 or 1.0. RepeatingDefine the texture filter parameters. This will control what happens when a texture is scaled up ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter3 needs to be created by the uncompressed BMP Define the texture wrapping parameters. This will control what happens when a texture around) if transformed texture coordinates less than 0.0 or greater than 1.0 are encountered. that the pattern will “stick” to the value at 0.0 or 1.0. Repeating Define the texture filter parameters. This will control what happens when a texture is scaled up filter ); filter );mjb – May 9, 2013 4 GL_NEAREST specifies that point sampling is to be used when the texture map needs to be magnified or minified. GL_LINEAR specifies that bilinear interpolation among the four nearest neighbors is to be used when the texture map needs to be magnified or minified. Nearest Bilinear 3. Define the texture environment properties. glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, mode ); There are several modes that can be used. Two of the most useful are: GL_REPLACE specifies that the 3-component texture will be applied as an opaque image on top of the polygon, replacing the polygon’s specified color. GL_MODULATE specifies that the 3-component texture will be applied as piece of colored plastic on top of the polygon. The polygon’s specified color “shines” through the plastic texture. This is very useful for applying lighting to textures: paint the polygon white with lighting and let it shine up through a texture.mjb – May 9, 2013 Replace


View Full Document

OSU CS 553 - Open GL Texture-Mapping Made Simpler

Download Open GL Texture-Mapping Made Simpler
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 Open GL Texture-Mapping Made Simpler 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 Open GL Texture-Mapping Made Simpler 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?