Presentation is loading. Please wait.

Presentation is loading. Please wait.

texturing a parametric surface

Similar presentations


Presentation on theme: "texturing a parametric surface"— Presentation transcript:

1 texturing a parametric surface
Texture generating textures using textures repeating clamping filtering texturing a parametric surface

2 Examples of texturing

3 loadTextures.cpp

4 where to put the Textures folder
VS: usually in the same folder as the .cpp file. If project is graphics, then in folder graphics/graphics Xcode: XCodeHowTo link. (class 4) Unix: in file with executable

5 Try it now. First try loadTextures.cpp from the 1st edition
If the computer complains about glext, just comment out that include in the code. If you get a white square, call me over. More errors, see the next two slides.

6 fixing getbmp.cpp Get the files getbmp.cpp and getbmp.h from the lecture page in getbmp.cpp, in getbmp.cpp comment out old return and replace with new return: //return bmpRGBA; //mjb return bmpRGB;

7 fixing loadTextures.cpp
in loadTextures.cpp comment out the Bitmap struct comment out the function BitMapFile *getBMPData(string filename) comment out the function call //image[0] = getBMPData("Textures/launch.bmp"); and replace with the function call image[0] = getbmp("Textures/launch.bmp");

8 Format of Texture Big 1-D array: R G B A R G B A R G B A 1st pixel
3rd pixel 2nd pixel

9 This data is in many photos, but has to be properly retrieved

10 Book examples use uncom-pressed 24 bit BMP

11 useful function to read texture data from a .BMP From 1st edition
// Routine to read a bitmap file. // Works only for uncompressed bmp files of 24-bit color. BitMapFile *getBMPData(string filename) Go through the function notice BGR vs RGB

12 If you can't get this version working, there is a new version, with a separate .h and .cpp file, from the 2nd edition. Links are on the webpage, only if you need it.

13 Changes to make to loadTextures.cpp from 2nd edition
//image[0] = getbmp("../../Textures/launch.bmp"); //mjb image[0] = getbmp("Textures/launch.bmp");

14 Changes to make to loadTextures.cpp from 2nd edition
In main, comment out: glutInitContextVersion(4, 3); glutInitContextProfile(GLUT_COMPATIBILITY_PROFILE); glewExperimental = GL_TRUE; glewInit();

15 globals and setup static unsigned int texture[2];
// Array of texture indices. // Create texture index array. glGenTextures(2, texture); // Struct of bitmap file. struct BitMapFile{ int sizeX; int sizeY; unsigned char *data;};

16 loadExternalTextures()
// Local storage for bmp image data. BitMapFile *image[1]; // Load the texture. image[0] = getBMPData("Textures/launch.bmp"); // Activate texture index texture[0]. glBindTexture(GL_TEXTURE_2D, texture[0]); ... // Specify an image as the texture to be bound with the currently active texture index. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image[0]->sizeX, image[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, image[0]->data);

17 loadProceduralTextures()
// Activate texture index texture[1]. glBindTexture(GL_TEXTURE_2D, texture[1]); ... // Specify an image as the texture to be bound with the currently active texture index. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, chessboard);

18 createChessboard(void)
look at function

19 texture space texel : pixel of a texture note: s, t, intervals [0,1]

20 mapping a polygon to texture space
// Map the texture onto a square polygon. glBegin(GL_POLYGON); glTexCoord2f(0.0, 0.0); glVertex3f(-10.0, -10.0, 0.0); glTexCoord2f(1.0, 0.0); glVertex3f(10.0, -10.0, 0.0); glTexCoord2f(1.0, 1.0); glVertex3f(10.0, 10.0, 0.0); glTexCoord2f(0.0, 1.0); glVertex3f(-10.0, 10.0, 0.0); glEnd(); Interpolate

21 other texture maps

22 interpolates through triangles

23 repeating

24 repeating

25 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

26 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_REPEAT);

27 fieldAndSky.cpp run notice shimmer try clamping grass in T direction
do graph paper experiment.

28 Problem with Pixels

29 GL_NEAREST glTexParameteri(GL_TEXTURE_2D,
GL_TEXTURE_MIN_FILTER,GL_NEAREST); GL_TEXTURE_MAG_FILTER,GL_NEAREST);

30 GL_LINEAR Average the surrounding points
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR); GL_TEXTURE_MAG_FILTER,GL_LINEAR); Average the surrounding points

31 mipmap make other versions of texture, various sizes speed vs storage
book has good examples if you try mipmaplevels.cpp change to d+=10.0 (not .2, also for -=) Nothing happens till box gets very small

32 fieldAndSkyFiltered.cpp run and observe differences

33 texturing parametrized surfaces

34 texturedTorus.cpp run note code for parametrization
// Specify how texture values combine with current surface color values. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); run also DoubletexturedTorusMJB.cpp


Download ppt "texturing a parametric surface"

Similar presentations


Ads by Google