1 / 19

Understanding of OpenGL

Understanding of OpenGL. Texture Mapping. TA: Dong Hyun Jeong Instructor : Dr. Kalpathi Subramanian. Purpose. How to upload textures in OpenGL Understanding of several existing techniques and GPU-based texture mapping. Upload textures. Define a texture glBindTexture glPixelStorei

erno
Download Presentation

Understanding of OpenGL

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. Understanding of OpenGL Texture Mapping TA: Dong Hyun JeongInstructor : Dr. Kalpathi Subramanian

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

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

  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. 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_NEAREST Min / Max Filter : GL_LINEAR

  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_RGB GL_RGB4

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

  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. Texture Drawing (0,1) (1,1) (0,0) (1,0) (1,0) (0,0) (1,1) (0,1) (1,0) (1,1) (0,0) (0,1) Order : (0,0) > (1,0) > (1,1) > (0,1)

  10. Bump mapping • Evaluate the lighting equation per pixel Pixel Map Bump Map http://www.paulsprojects.net/tutorials/simplebump/simplebump.html

  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.html

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

  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.shtml • http://www.alsprogrammingresource.com/lightmapping.html • http://www.daionet.gr.jp/~masa/rthdribl/index.html

  14. Gloss Mapping • Modify the specular highlight • Scale the specular value by the gloss map value + + Before After

  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)]); http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=23

  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. 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; } } http://www.csee.umbc.edu/~ebert/691/Au00/Notes/procedural.html

  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. Q & A

More Related