Download presentation
Presentation is loading. Please wait.
Published byTamsyn Lamb Modified over 8 years ago
1
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 or3D modeldetailbitmapraster imagecolorcomputer-generated graphic3D model
2
Texture Mapping We have to use two headers and cpp files. 1.lodepng.h / lodepng.cpp 2.texture.h / texture.cpp
3
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.
4
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 unsigned char *loadTGA(const char* filepath, int &width, int &height); void initTGA(GLuint *tex, const char *name, int &width, int &height); void initPNG(GLuint *tex, const char *name, int &width, int &height); void initTex(); #endif
5
Texture Mapping void initPNG(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)
6
Texture Mapping Usage of initpng function GLuint tex_example; GLuint w; GLuint h; initPNG(&tex_example, “example.png”, w, h); -> convert “example.png” into a binary file which will be in “tex_example”
7
Texture Mapping Then, What’s in initpng file? void initPNG(GLuint *tex, const char *name, int &width, int &height) { … glDeleteTextures(1, tex); glGenTextures(1, tex); … width = decoder.infoPng.width; height = decoder.infoPng.height; //printf("width: %d height: %d\n", width, height); free(buffer); free(image); } The number 1 is the length of the square where png file will be mapped
8
Texture Mapping Example, I will use the picture above and its pixel size is 50 times 50.
9
Texture Mapping After using initpng, what do we have to do? Using same examples as before, glBindTexture(GL_TEXTURE_2D, tex_example); glBegin(GL_QUADS); glTexCoord2i(0.0, 1.0); glVertex2d(Xmin, Ymin); glTexCoord2i(1.0, 1.0); glVertex2d(Xmax, Ymin); glTexCoord2i(1.0, 0.0); glVertex2d(Xmax, Ymax); glTexCoord2i(0.0, 0.0); glVertex2d(Xmin, Ymax); glEnd();
10
Texture Mapping glTexCoord2i(0.0, 1.0); glVertex2d(Xmin, Ymin); glTexCoord2i(1.0, 1.0); glVertex2d(Xmax, Ymin); glTexCoord2i(1.0, 0.0); glVertex2d(Xmax, Ymax); glTexCoord2i(0.0, 0.0); glVertex2d(Xmin, Ymax); (0, 0) (1, 0) (0, 1)(1, 1) (Xmin, Ymin) (Xmax, Ymax)
11
Texture Mapping Drawing order is also important. We have to map the points in clockwise or in counter- clockwise manner. Otherwise, the texture mapping isn’t what you expected.
12
Texture Mapping Assignment 4 -Bezier Surface with Texture mapping -Good Luck
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.