Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping.

Similar presentations


Presentation on theme: "1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping."— Presentation transcript:

1 1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping

2 2 Purpose How to upload textures in OpenGL Understanding of several existing techniques and GPU-based texture mapping

3 3 Upload textures Define a texture –glBindTexture –glPixelStorei –glTexParameteri –glTexEnvf –glTexImage2D Calling the defined texture –glBindTexture Without Mipmap With Mipmap

4 4 Binding and setting glBindTexture(GL_TEXTURE_2D, ID); –Texture "id" is just a number that we use it for calling the texture. glPixelStorei(GL_UNPACK_ALIGNMENT, 1); –Defining how the data that is going to be uploaded is aligned. glTexParameteri –Wrap Mode glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);. Wrap S : GL_CLAMP Wrap T : GL_CLAMP Wrap S : GL_CLAMP Wrap T : GL_CLAMP Wrap S : GL_CLAMP Wrap T : GL_CLAMP Wrap S : GL_CLAMP Wrap T : GL_CLAMP

5 5 Binding and setting II glTexParameteri –Scale Mode Magnification is when each texel is larger than each pixel. Minification is when each texel is smaller than each pixel. –glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); –glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); –. Min / Max Filter : GL_NEARESTMin / Max Filter : GL_LINEAR

6 6 Environment settings –glTexEnvf Set the environment variables for the current texture. –glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); –glTexImage2D Upload the texture to the video memory where it will be ready for us to use in our programs –glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, imageWidth, imageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, imageData); –. GL_RGBGL_RGB4

7 7 Specifying a Texture Texture is specified as an array of texels: –GLubyte imageData1[3 * 256 * 256] when GL_RGB is set. One byte for each of red, green and blue. Height is power of 2 Width is power of 2

8 8 Simple example glBindTexture (GL_TEXTURE_2D, id); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexImage2D (GL_TEXTURE_2D, 0, m_texFormat, imageWidth, imageHeight, 0, m_texFormat, GL_UNSIGNED_BYTE, imageData); glBindTexture (GL_TEXTURE_2D, id); glBegin (GL_QUADS); glTexCoord2f (0.0, 0.0); glVertex3f (0.0, 0.0, 0.0); glTexCoord2f (1.0, 0.0); glVertex3f (10.0, 0.0, 0.0); glTexCoord2f (1.0, 1.0); glVertex3f (10.0, 10.0, 0.0); glTexCoord2f (0.0, 1.0); glVertex3f (0.0, 10.0, 0.0); glEnd ();

9 9 Texture Drawing (0,1)(1,1) (1,0)(0,0) (1,0)(0,0) (0,1)(1,1) (1,0)(1,1) (0,1)(0,0) Order : (0,0) > (1,0) > (1,1) > (0,1)

10 10 Bump mapping Evaluate the lighting equation per pixel Pixel Map Bump Map

11 11 Shadow Mapping One of many different ways of producing shadows in graphics applications –No knowledge or processing of the scene geometry is required, since shadow mapping is an image space technique, working automatically with objects created or altered on the GPU. –Only a single texture is required to hold shadowing information for each light; the stencil buffer is not used. –Avoids the high fill requirement of shadow volumes. Method –Create shadow mapping as a depth test –http://www.paulsprojects.net/tutorials/smt/smt.htmlhttp://www.paulsprojects.net/tutorials/smt/smt.html

12 12 Alpha Mapping Use RGBA color channels –glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);

13 13 Light Mapping Contains luminance information –Calculate the lightmap's UV coordinates Project the polygon's coordinates onto a primary axis plane –Convert the new coordinates to 2D texture space –http://www.flipcode.com/articles/article_lightmapping.shtmlhttp://www.flipcode.com/articles/article_lightmapping.shtml –http://www.alsprogrammingresource.com/lightmapping.htmlhttp://www.alsprogrammingresource.com/lightmapping.html –http://www.daionet.gr.jp/~masa/rthdribl/index.htmlhttp://www.daionet.gr.jp/~masa/rthdribl/index.html

14 14 Gloss Mapping Modify the specular highlight –Scale the specular value by the gloss map value ++ BeforeAfter

15 15 Environmental Mapping Set The Texture Generation Mode For S and T To Sphere Mapping –glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glBindTexture(GL_TEXTURE_2D, texture[filter+(filter+1)]); // Shere Map glPushMatrix(); glRotatef(xrot,1.0f,0.0f,0.0f); glRotatef(yrot,0.0f,1.0f,0.0f); glDrawCube(); glPopMatrix(); glDisable(GL_TEXTURE_GEN_S); glDisable(GL_TEXTURE_GEN_T); glBindTexture(GL_TEXTURE_2D, texture[filter*2]); // Environmental Map glPushMatrix(); glTranslatef(0.0f, 0.0f, -24.0f); -Draw Background Object glPopMatrix(); glBindTexture(GL_TEXTURE_2D, texture[filter+(filter+1)]);

16 16 Procedural Techniques I Use of code segments or algorithms to generate object description, attribute, motion, etc. –Simple Noise –Perlin Noise –Cellular Texturing (Voronoi Diagram) –Reaction-Diffusion (Partial Differential)

17 17 Procedural Techniques II Sample_Procedure(x,y,color) { static int first=1; color.r=color.g=color.b=0; if(first) { first=0; for (i=0; i < 20; i++) { center[i].x = drand48()*10; center[i].y = drand48()*10; radius[i] = drand48*.5; radius[i] *=radius[i]; color[i].r = drand48(); color[i].g=drand48(); color[i].b=drand48(); } for (i=0; i < 20; i++) { dist_sq = (center[i].x-x)*(center[i].x-x) + (center[i].y-y)*(center[i].y-y) if (dist_sq < radius[i]) color=color[i]; break; }

18 18 Using Texture coordinates Loading models –Importing Wavefront OBJ file to display –*.obj file includes vertex, texture coordinate, and face numbers Rendered using 3DS MAX without texture Rendered using 3DS MAX with texture

19 19 Q & A


Download ppt "1 Understanding of OpenGL TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian Texture Mapping."

Similar presentations


Ads by Google