1 / 12

Texture Mapping

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 3D model. Texture Mapping. We have to use two headers and cpp files. lodepng.h / lodepng.cpp t exture.h / texture.cpp.

Download Presentation

Texture Mapping

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

  2. Texture Mapping We have to use two headers and cpp files. lodepng.h / lodepng.cpp texture.h / texture.cpp

  3. Texture Mapping • 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 <gl/glut.h> • 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 GLuinttex_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); (Xmax, Ymax) (0, 0) (1, 0) (0, 1) (1, 1) (Xmin, Ymin)

  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

More Related