CH6 Texture.

Slides:



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

OpenGL Texture Mapping
Texture Mapping. Typical application: mapping images on geometry 3D geometry (quads mesh) + RGB texture 2D (color-map) =
CH6 Texture. Before coding … 1/2 Prepare all texture images you need. BMP file is a good choice If you want to use TIFF file, maybe try this.
Texture Mapping OpenGl and Implementation Details CS
CH7 Buffers and Blending. Blending Example 1/6 #include #include "glut.h" GLfloat alpha = 0.0; GLfloat pos[4] = {0, 10, 10, 0}; GLfloat dif_l[4] = {1.0,
CSC345: Advanced Graphics & Virtual Environments
OpenGL Texture Mapping
OpenGL Texture Mapping Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
ADDITIONAL TIPS Multi-texture Slides. Here is a link Workflow: /**************In texture parameter set up******/ call glActiveTextureARB(/*pick texture.
1 Lecture 12 Texture Mapping uploading of the texture to the video memory the application of the texture onto geometry.
OpenGL Texture Mapping April 16, Angel: Interactive Computer Graphics 3E © Addison-Wesley 2002 Basic Stragegy Three steps to applying a texture.
CS 4731: Computer Graphics Lecture 17: Texturing Emmanuel Agu.
Texture Mapping. To add surface details… World of Warcraft, Blizzard Inc. More polygons (slow and hard to handle small details) Less polygons but with.
Computer Graphics Texture Mapping Eriq Muhammad Adams
Texture Mapping + Texture Object = Texture Mapped Object.
2IV60 Computer Graphics set 10: Texture mapping Jack van Wijk TU/e.
2002 by Jim X. Chen: 1 Texture Lab At each rendered pixel, selected texels are used either to substitute for or to scale.
Texture Mapping. Introduction What is Texture Mapping? Types of Texture Mapping –1D, 2D and 3D SDL and OpenGL.
Texture Mapping. Example Mappings Mapping Techniques Consider the problem of rendering a sphere in the examples The geometry is very simple - a sphere.
Computer Graphics OpenGL - Texture mapping. OpenGL Texture mapping zTexture Mapping allows us to glue an image on polygons. In this method we can produce.
Texture Mapping Course: Computer Graphics Presented by Fan Chen
Computer Graphics Ben-Gurion University of the Negev Fall 2012.
An Interactive Introduction to OpenGL Programming Ed Angel
ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen
CS380 LAB IV OpenGL Jonghyeob Lee Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Texture Mapping Fall, Textures Describe color variation in interior of 3D polygon  When scan converting a polygon, vary pixel colors according.
Lecture 27: Texture Mapping Li Zhang Spring 2008
And Some Extra Information From
Texture Mapping. 2 Motivation A typical modern graphics card can handle 10s of millions of polygons a second. How many individual blades of grass are.
OpenGL Texture Mapping. 2 Objectives Introduce the OpenGL texture functions and options.
CG1 Labs Wei Li. Back Face Culling // enable back-face culling glEnable( GL_CULL_FACE ); // orientation of front-facing polygons glFrontFace( GL_CCW );
CS 480/680 Computer Graphics OpenGL Texture Mapping Dr. Frederick C Harris, Jr. Fall 2011.
Texture Mapping Software College, Shandong University Instructor: Zhou Yuanfeng
Texture Mapping in OpenGL. Texture Mapping Imaging we are “pasting” a picture onto a model  Which part of the picture will be pasted onto which part.
Texture Mapping Drawing Pictures on Polygons. Texture Mapping.
TEXTURES & OTHER GOODIES Computer Graphics. glTexCoord2f(...); + =
111/17/ :24 UML Solution Involves Selection of Discrete Representation Values.
2 COEN Computer Graphics I Evening’s Goals n Discuss displaying and reading image primitives n Describe texture mapping n Discuss OpenGL modes and.
October 9, 2002Serguei A. Mokhov, 1 COMP471 – Computer Graphics OpenGL: Texture Mapping.
CH8 Frame Buffer Object 1. Introduction Name OpenGL :Frame Buffer Object DirectX:Render Target Usage Render to Texture 2.
Texture Mapping. 2 3 Loading Textures void glTexImage2D (GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border,
OpenGL Programming Guide : Texture Mapping Yoo jin wook Korea Univ. Computer Graphics Lab.
CH6 Texture. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending Per Fragment.
Texture Mapping. checker.c Texture-Mapped Squares.
CH7 Buffers and Blending. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Texture Mapping and NURBS Week 7 David Breen Department of Computer Science Drexel University Based on material from Ed Angel, University of New Mexico.
Details of Texture Mapping Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, December 1, 2003.
CH6 Texture. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending Per Fragment.
CH6 Texture. Before coding … 1/2 Prepare all texture images you need. BMP file is a good choice If you want to load other format, you can try the FreeImage.
CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.
Texture Mapping CEng 477 Introduction to Computer Graphics.
Madhulika (18010), Assistant Professor, LPU.
Texture Mapping Fall, 2016.
Texture Mapping 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Texture Mapping We can improve the realism of graphics models by mapping a texture pattern (image) onto the modeled object surface. We refer to this technique.
OpenGL Texture Mapping
Advanced Graphics Algorithms Ying Zhu Georgia State University
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL Texture Mapping
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Assignment 3b Q&A.
3D Game Programming Texture Mapping
Computer Graphics Practical Lesson 6
OpenGL Texture Mapping
OpenGL Texture Mapping
Programming Textures Lecture 15 Fri, Sep 28, 2007.
3D Game Programming Texture Mapping
OpenGL Texture Mapping
Presentation transcript:

CH6 Texture

Before coding… 1/2 Prepare all texture images you need. BMP file is a good choice  If you want to use TIFF file, maybe try this. http://gnuwin32.sourceforge.net/packages/tiff.htm Download the developer files. Or…just change TIFF files to BMP files ˋ(′~‵")ˊ

Before coding… 2/2 Add GlAux.Lib into your project.

How to use texture? glTexEnv (…) glTexParameteri (…) Enable glEnable(GL_TEXTURE_2D); Generate Texture glGenTextures(number of textures , texture id array) Bind glBindTexture(GL_TEXTURE_2D, textId); Move date into texture gluBuild2DMipmaps(…) or glTexImage2D (…) Setting the texture glTexEnv (…) glTexParameteri (…) Assign texCoor before vertexCoor in display glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 0.0, 0.0);

Example Program 1/4 #include<gl/glaux.h> #include<gl/glut.h> #define TEX_NUM 1 //the number of textures you use. #define MIPMAP AUX_RGBImageRec * img; //to save image file GLuint texObject[TEX_NUM]; //texture object

Example Program 2/4 void LoadTexture(char* filename){ img = auxDIBImageLoadA(filename); glGenTextures(TEX_NUM, texObject); glBindTexture(GL_TEXTURE_2D, texObject[0]); #ifdef MIPMAP gluBuild2DMipmaps(GL_TEXTURE_2D, 4, img->sizeX, img->sizeY, GL_RGB, GL_UNSIGNED_BYTE, img->data); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); #else glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->sizeX, img->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, img->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); #endif glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); }

Example Program 3/4 void GL_display(){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texObject[0]); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex3f(-50.0, 0.0, 0.0); glTexCoord2f(0.0, 100.0); glVertex3f(-50.0, 0.0, 100.0); glTexCoord2f(100.0, 100.0); glVertex3f(50.0, 0.0, 100.0); glTexCoord2f(100.0, 0.0); glVertex3f(50.0, 0.0, 0.0); glEnd(); glFlush(); }

Example Program 4/4 void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.5, 100.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 0.5, 0.0, 50.0, 0.0, 50.0, 0.0, 1.0, 0.0); } int main(int argc, char** argv) glutInit(&argc, argv); glutInitWindowSize(400, 400); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutCreateWindow("Texture"); LoadTexture("check.bmp"); glutDisplayFunc(GL_display); glutReshapeFunc(GL_reshape); glutMainLoop();

Result Check_old.bmp Width/Height: 256/256

Load BMP file AUX_RGBImageRec* auxDIBImageLoadA(char *); Load a BMP file. typedef struct _AUX_RGBImageRec { GLint sizeX, sizeY; unsigned char *data; }; sizeX, sizeY : image width / height. data : A pointer to the image data in memory.

Generate Texture Object void glGenTextures( GLsizei n, GLuint *textures ); To generate texture names. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc02_3p6b.asp n: the number of texture names to be generated. textures: pointer to the first element of an array in which the texture are stored. GLboolean glIsTexture( GLuint texture ); To determine if a name corresponds to a texture. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_7cv9.asp

Bind texture To bind the texture to the target. void glBindTexture( GLenum target, GLuint texture ); To bind the texture to the target. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc01_3bad.asp target: GL_TEXTURE_1D, GL_TEXTURE_2D void glDeleteTextures( GLsizei n, const GLuint *textures ); Delete named textures. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc01_6vqr.asp

Send texture data: glTexImage2D 1/4 void glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels );

Send texture data: glTexImage2D 2/4 Specifies a 2D texture image http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_16jo.asp target: Must be GL_TEXTURE_2D level: level-of-detail level. It must be 0 if you don’t want to use mip-map. internalformat: GL_RGBA and many others… Width / height : image witdh / height

Send texture data: glTexImage2D 3/4 border: 0 or 1 0 : no border, image width & height must be power of 2. 1 : use border, image width & height must be power of 2 plus 2.

Send texture data: glTexImage2D 4/4 format: format of the image data GL_RGB, GL_RGBA, and many others… type: data type of the image data pixel: A pointer to the image data in memory. (Hint: the BMP file you have loaded…)

Texture Setting: glTexEnv 1/3 void glTexEnv{fi}(GLenum target, GLenum pname, GLfloat param ); to indicate how the texels are combined with the original pixels http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_6xyu.asp target: must be GL_TEXTURE_ENV pname: must be GL_TEXTURE_ENV_MODE param: 5 choices, see next page

Texture Setting: glTexEnv 2/3 Base Internal Format GL_REPLACE GL_MODULATE GL_ADD GL_ALPHA C = Cf, A = At C = Cf, A = AfAt C=Cf, A=AfAt GL_LUMINANCE C = Lt, A = Af C = CfLt, A = Af C=Cf+CT, A=Af GL_LUMINANCE_ALPHA C = Lt, A = At C = CfLt, A = AfAt C=Cf+Ct, A=AfAt GL_INTENSITY C = It, A = It C = CfIt, A = AfIt C=Cf+Ct, A=Af+At GL_RGB C = Ct, A = Af C = CfCt, A = Af C=Cf+Ct, A=Af GL_RGBA C = Ct, A = At C = CfCt, A = AfAt C=Cf+Ct, A=AfAt Base Internal Format GL_DECAL GL_BLEND GL_ALPHA Undefined C = Cf, A = AfAt GL_LUMINANCE Undefined C = Cf(1-Lt)+CcLt, A = Af GL_LUMINANCE_ALPHA Undefined C = Cf(1-Lt)+CcLt, A = AfAt GL_INTENSITY Undefined C = Cf(1-It)+CcIt, A = Af(1-It)+AcIt GL_RGB C = Ct, A = Af C = Cf(1-Ct)+CcCt, A = Af GL_RGBA C = Cf(1-At)+CtAt, A = At C = Cf(1-Ct)+CcCt, A = AfAt Ct = color of texture , At = alpha of texture Cf = color of frame buffer , Af = alpha of frame buffer

Texture Setting: glTexEnv 3/3 glTexEnv{fi}v(GLenum target, GLenum pname, const GLfloat *params ) target: must be GL_TEXTURE_ENV pname: GL_TEXTURE_ENV_COLOR or GL_TEXTURE_ENV_MODE params: if pname is GL_TEXTURE_ENV_MODE : A pointer to an array of parameters.(GL_MODULATE, GL_DECAL, and GL_BLEND) if pname is GL_TEXTURE_ENV_COLOR: a pointer to an array of R, G, B, A

Texture parameter 1/5 glTexParameter{if}(GLenum target, GLenum pname, GLfloat param ) Set texture parameters. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_9upe.asp target: GL_TEXTURE_1D, GL_TEXTURE_2D pname / param: see next page

Texture parameter 2/5 pname param GL_TEXTURE_WRAP_S GL_TEXTURE_WRAP_T GL_REPEAT, GL_CLAMP GL_TEXTURE_MAG_FILTER GL_TEXTURE_MIN_FILTER GL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR_MIPMAP_NEAREST GL_TEXTURE_BORDER_COLOR color value

Texture parameter 3/5 WRAP Clamp both S, T Repeat both S, T Repeat T but Clamp S

Texture parameter 4/5 MAG filter MIN filter When the pixel being textured maps to an area less than or equal to one texture element MIN filter When the pixel being textured maps to an area greater then one texture element

Texture parameter 5/5 GL_LINEAR GL_NEARST pixel Get average color... texel GL_NEAREST_MIPMAP_XXXXXX Find the most closely match mipmap GL_LINEAR_MIPMAP_XXXXXXX Find the most 2 closely match mipmap and get average.

Build mip-maps 1/3 int gluBuild2DMipmaps( GLenum target, GLint components, GLint width, GLint height, GLenum format, GLenum type, const void *data ); http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glufnc01_406r.asp

Build mip-maps 2/3 target : Must be GL_TEXTURE_2D. components :The number of color components in the texture. Must be 1, 2, 3, or 4. width, height :width / height of image. format : GL_RGB, GL_RGBA and many others… type :The data type for data data :A pointer to the image data in memory.

Build mip-maps 3/3 without mip-map with mip-map

Automatic Texture Coordinate Generation No need to use glTexCoord Three types Sphere Object plane Eye plane

Sphere environment.bmp Width/Height: 128/128

Object plane -1 S = 1.0 x + 0.0 y + 0.0 z + 0.0 w T = 0.0 x + 1.0 y + 0.0 z + 0.0 w xyz in world space

Object plane -2 S = 1.0 x + 0.0 y + 0.0 z + 0.0 w T = 0.0 x + 2.0 y + 0.0 z + 0.0 w xyz in world space

Eye plane S = 1.0 x + 0.0 y + 0.0 z + 0.0 w T = 0.0 x + 1.0 y + 0.0 z + 0.0 w xyz in eye space

Sphere Example 1/3 #include<gl/glaux.h> #include<gl/glut.h> AUX_RGBImageRec * img; GLuint texObject; void LoadTexture(char* filename){ img = auxDIBImageLoad(filename); glGenTextures(1, &texObject); glBindTexture(GL_TEXTURE_2D, texObject); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB, GL_UNSIGNED_BYTE, img->data); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); }

Sphere Example 2/3 void GL_display(){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); glColor3f(1.0, 1.0, 1.0); glutSolidTeapot(18); glFlush(); } void GL_reshape(GLsizei w, GLsizei h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 0.5, 100.0); glMatrixMode(GL_MODELVIEW); gluLookAt(0.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

Sphere Example 3/3 int main(int argc, char** argv) { glutInit(&argc, argv); glutInitWindowSize(400, 400); glutInitWindowPosition(0, 0); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH); glutCreateWindow("Texture"); LoadTexture("environment.bmp"); glutDisplayFunc(GL_display); glutReshapeFunc(GL_reshape); glutMainLoop(); }

Object Plane Example void LoadTexture(char* filename) { GLint params1[] = {1.0 , 0.0 , 0.0 ,0.0}; GLint params2[] = {0.0 , 1.0 , 0.0 ,0.0}; img = auxDIBImageLoad(filename); glGenTextures(1, &texObject); glBindTexture(GL_TEXTURE_2D, texObject); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB,GL_UNSIGNED_BYTE, img->data); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR); glTexGeniv(GL_S , GL_OBJECT_PLANE , params1); glTexGeniv(GL_T , GL_OBJECT_PLANE , params2); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); }

Eye Plane Example void LoadTexture(char* filename) { GLint params1[] = {1.0 , 0.0 , 0.0 ,0.0}; GLint params2[] = {0.0 , 1.0 , 0.0 ,0.0}; img = auxDIBImageLoad(filename); glGenTextures(1, &texObject); glBindTexture(GL_TEXTURE_2D, texObject); gluBuild2DMipmaps(GL_TEXTURE_2D, 3, img->sizeX, img->sizeY, GL_RGB,GL_UNSIGNED_BYTE, img->data); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); glTexGeniv(GL_S , GL_EYE_PLANE , params1); glTexGeniv(GL_T , GL_EYE_PLANE , params2); glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); glEnable(GL_TEXTURE_2D); }

Automatic Texture-Coordinate Generation glTexGen{dfi}(GLenum coord, GLenum pname, GLdouble param); control the generation of texture coordinates http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_73u6.asp coord: GL_S, GL_T, GL_R, or GL_Q. pname: must be GL_TEXTURE_GEN_MODE. param: GL_OBJECT_LINEAR, GL_EYE_LINEAR, or GL_SPHERE_MAP

Automatic Texture-Coordinate Generation glTexGen{dfi}v(GLenum coord, GLenum pname, const GLdouble *params ); coord: GL_S, GL_T, GL_R, or GL_Q. pname: GL_TEXTURE_GEN_MODE, GL_OBJECT_PLANE, or GL_EYE_PLANE params: the array of texture generation parameters, if pname is GL_OBJECT_PLANE, or GL_EYE_PLANE. *Generated plane = p1X + p2Y + p3Z + p4W