Texture Mapping What is texture mapping a method












- Slides: 12
Texture Mapping What is texture mapping? - a method for adding detail, surface texture (a bitmap or raster image), or color to a computer-generated graphic or 3 D model
Texture Mapping We have to use two headers and cpp files. 1. lodepng. h / lodepng. cpp 2. texture. h / texture. cpp
Texture Mapping 1. lodepng. h / lodepng. cpp - We load png files or tga files and convert those into binary files so that VS can read it just as data files we usually use. - We don’t have to know the details.
Texture Mapping 2. texture. h / texture. cpp - What we really have to use - Inside the header file, #ifndef JH_TEXTURE_H #define JH_TEXTURE_H #include <gl/glut. h> unsigned char *load. TGA(const char* filepath, int &width, int &height); void init. TGA(GLuint *tex, const char *name, int &width, int &height); void init. PNG(GLuint *tex, const char *name, int &width, int &height); void init. Tex(); #endif
Texture Mapping void init. PNG(GLuint *tex, const char *name, int &width, int &height); - tex: the place where we get the converted png file as a binary file - name: the file name (you should write a path to the file) - width: the width of the original png file (in pixel) - height: the height of the original png file (in pixel)
Texture Mapping Usage of initpng function GLuint tex_example; GLuint w; GLuint h; init. PNG(&tex_example, “example. png”, w, h); -> convert “example. png” into a binary file which will be in “tex_example”
Texture Mapping Then, What’s in initpng file? void init. PNG(GLuint *tex, const char *name, int &width, int &height) { … gl. Delete. Textures(1, tex); The number 1 is the length of the square gl. Gen. Textures(1, tex); where png file will be mapped … width = decoder. info. Png. width; height = decoder. info. Png. height; //printf("width: %d height: %dn", width, height); free(buffer); free(image); }
Texture Mapping Example, I will use the picture above and its pixel size is 50 times 50.
Texture Mapping After using initpng, what do we have to do? Using same examples as before, gl. Bind. Texture(GL_TEXTURE_2 D, tex_example); gl. Begin(GL_QUADS); gl. Tex. Coord 2 i(0. 0, 1. 0); gl. Vertex 2 d(Xmin, Ymin); gl. Tex. Coord 2 i(1. 0, 1. 0); gl. Vertex 2 d(Xmax, Ymin); gl. Tex. Coord 2 i(1. 0, 0. 0); gl. Vertex 2 d(Xmax, Ymax); gl. Tex. Coord 2 i(0. 0, 0. 0); gl. Vertex 2 d(Xmin, Ymax); gl. End();
Texture Mapping gl. Tex. Coord 2 i(0. 0, 1. 0); gl. Vertex 2 d(Xmin, Ymin); gl. Tex. Coord 2 i(1. 0, 1. 0); gl. Vertex 2 d(Xmax, Ymin); gl. Tex. Coord 2 i(1. 0, 0. 0); gl. Vertex 2 d(Xmax, Ymax); gl. Tex. Coord 2 i(0. 0, 0. 0); gl. Vertex 2 d(Xmin, Ymax); (0, 0) (1, 0) (0, 1) (1, 1) (Xmax, Ymax) (Xmin, Ymin)
Texture Mapping Drawing order is also important. We have to map the points in clockwise or in counterclockwise manner. Otherwise, the texture mapping isn’t what you expected.
Texture Mapping Assignment 4 - Bezier Surface with Texture mapping - Good Luck