Understanding Texturing and Texture Mapping in OpenGL: Bitmaps, Co-ordinates, Techniques, Slides of Fundamentals of E-Commerce

An in-depth explanation of texturing and texture mapping in opengl, covering the basics of pictures as 2d arrays of color values, texture co-ordinates, texture mapping, and loading bmps using the glaux library. It also demonstrates how to display texture-mapped squares and texture-map parametric surfaces.

Typology: Slides

2012/2013

Uploaded on 07/30/2013

asif.ali
asif.ali 🇮🇳

5

(3)

129 documents

1 / 12

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Texturing
A picture is worth a thousand words
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Understanding Texturing and Texture Mapping in OpenGL: Bitmaps, Co-ordinates, Techniques and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

Texturing A picture is worth a thousand words

Texturing ^ Texturing is the art of doing this with any picture^ to any^

model.

^ (This is Opus the Penguin wrapped around a sphere.)

Texturing ^ A bitmap in memory:^ ^ ...a two-dimensional array of color values

Texture Co-ordinates ^ We use^ texture co-ordinates

to identify locations

in the texture itself.^ ^ (0,0) is the lower left-hand corner of the texture.^ ^ (0.5, 0.5) is the middle of the texture.^ ^ (1,1) is the upper right-hand corner.^ ^ Caveat: OpenGL draws bottom-to-top, not top-to-bottom, so inyour own rendering you may have to invert Y.

(1,1) (0,0)

Texture Mapping ^ Shifting texture co-ordinates^ ^ If the values you map to your texture co-ordinates shift, theimage will appear to shift on the surface.^ ^ The image at right is drawnwith texture co-ordinatesshifted by (0.25, 0.25).^ (0.25,1.25)^ (1.25,0.25)^ (0.25,0.25)

Texture Mapping in OpenGL ^ OpenGL works on the idea that you

bind^ the

current texture before you glBegin(), and thenyou specify texture co-ordinates for eachglVertex() you draw.  Fortunately, the GLAUX library makes file loadingeasy.^ ^ Remember, your image dimensions MUST be multiples of 2.^ ^ To compile an app which uses glaux functions, you’ll need tolink glaux.lib. To link a .lib library, go to Project / Settings... /Link tab, and add ‘glaux.lib’ to the list of Library Modules.

Texture Mapping in OpenGL ^ Displaying a texture-mapped square glBindTexture(GL_TEXTURE_2D,

arrTextures[whichTexture]); glColor3f(1,1,1);glNormal3f(0,0,1);glBegin(GL_QUADS);glTexCoord2f(0,1);

glVertex3f(-5,5,0);glTexCoord2f(0,0); glVertex3f(-5,-5,0);glTexCoord2f(1,0); glVertex3f(5,-5,0);glTexCoord2f(1,1); glVertex3f(5,5,0); glEnd();glBindTexture(GL_TEXTURE_2D,

0);

Texture Mapping in OpenGL ^ Texturing a parametric surface^ ^ Texture-mapping a parametric surface is

very^ easy. If u and v range from0 to 1, then they alsocover the range of thetexture co-ordinates.  You can set the currenttexture co-ordinate as(u,v) to map your imageto any parametricsurface.