Presentation is loading. Please wait.

Presentation is loading. Please wait.

ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen

Similar presentations


Presentation on theme: "ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen"— Presentation transcript:

1 ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu

2 We have discussed Polygons – square, cube, etc. Quadric surfaces – disk, cylinder, sphere etc. Bezier Curves, Bezier Surfaces, B-splines, Nurbs surfaces etc. Based on these basic elements, we can build objects with very complex shape -> render.

3 Why we need textures? Thousands of small polygons to give the appearance of a real object. Expensive to compute, render and manage Object too smooth and regular to look real Texture mapping allows real images to be applied to objects and is less expensive computationally

4 Texture Mapping to add realism

5 Steps in Texture Mapping Create and specify a texture object. Specify texture application method Enable texture mapping mode Draw (map texture co-ordinates to object points)!

6 Texture Dimensions 2D (common) 1D = 2D with Height =1 – e.g. texture vary only in one direction 3D = Layers of 2D textures – e.g. MRI/CT data Ref: Rosalee Wolfe’s book

7 Texture Data RGBA Depth Luminance Intensity Texel: one texture element

8 Texture Application Modes (texture functions) Replace Modulate/Scale Blend

9 Loading texture data jpeg, png, tiff, gif ?? Idea: convert to BMP and load. Note: Handle all errors when you write I/O code. #include //for reading bitmap image Function prototype – AUX_RGBImageRec *LoadBMP(char *Filename) // Loads A Bitmap Image – Read about AUX_RGBImageRec in more detail.

10 Loading texture data (contd..) Create a file handle – FILE *File=NULL; // File Handle Try to open the file – File=fopen(Filename,"r"); // Check To See If The File Exists Close the file and load bitmap if (File) // Does The File Exist? { fclose(File); // Close The Handle // Load The Bitmap And Return A Pointer return auxDIBImageLoad (Filename);}

11 Using the texture data Gluint texture[1]; //Storage for one texture Create Storage Space For The Texture – AUX_RGBImageRec *TextureImage[1]; Load the texture – TextureImage[0]=LoadBMP("Data/NeHe.bmp") Naming a texture object – glGenTextures(1, &texture[0]); – Non-zero unsigned integer may be used as a texture names

12 Using the texture data (contd..) Bind the named texture to texture target – glBindTexture(GL_TEXTURE_2D, texture[0]); Defined a 2-D Texture – glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

13 glTexImage2D void glTexImage2D( GLenum target, //The target texture. Must be GL_TEXTURE_2D. GLint level, //The level-of-detail number. GLint internalformat, //The number of color components in the texture GLsizei width, //Must be 2 n + 2(border) for some integer n. GLsizei height, //Must be 2 m + 2(border) for some integer m. GLint border, //The width of the border. Must be either 0 or 1. GLenum format, //The format of the pixel data. GLenum type, //GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP const GLvoid *pixels //pointer to the image data in memory );

14 Texture Parameters void glTexParameterf(GLenum target, GLenum pname, GLfloat param ); – glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_F ILTER,GL_LINEAR); // Linear Filtering – glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_ FILTER,GL_LINEAR); // Linear Filtering – For GL_TEXTURE_WRAP_S, GL_TEXTURE_WRAP_T you can specify GL_CLAMP or GL_REPEAT.

15 Free Up Space Image Data if (TextureImage[0])// If Texture Exists { if (TextureImage[0]->data)// If Texture Image Exists { // Free The Texture Image Memory free(TextureImage[0]->data); } free(TextureImage[0]);// Free The Image Structure } Texture Data – void glDeleteTextures( GLsizei n, const GLuint *textures); – Deletes named textures

16 Changes to Init int InitGL(GLvoid) { if (!LoadGLTextures())// Jump To Texture Loading Routine ( NEW ) { return FALSE;// If Texture Didn't Load Return FALSE ( NEW ) } glEnable(GL_TEXTURE_2D);// Enable Texture Mapping ( NEW ) glShadeModel(GL_SMOOTH);// Enable Smooth Shading glClearColor(0.0f, 0.0f, 0.0f, 0.5f);// Black Background glClearDepth(1.0f);// Depth Buffer Setup glEnable(GL_DEPTH_TEST);// Enables Depth Testing glDepthFunc(GL_LEQUAL);// The Type Of Depth Testing To Do glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculations return TRUE;// Initialization Went OK } Mode prescedence: Gl_TEXTURE_ID < GL_TEXTURE_2D < GL_TEXTURE_3D < GL_TEXTURE_CUBE_MAP.

17 Texture Compression Compress While Loading – GL_COMPRESSED_* in internalformat of glTexImage*D Load a Compressed Texture Image – glCompressedTextImage*D – Compression format should be supported by graphics card.

18 Texture Borders Texture repetition has problems at borders esp. with linear filtering. Each texel has eight neighbors except the borders. So where do edge pixels get their neighbors? From the texture border! Simple approach: Copy the values of the adjacent texture into the border.

19 Texture rendering Texture mapping is image resampling Some common problems

20 Mipmaps Why do we need them? – Shimmering, flashing, scintillations when texture is scaled to fit smaller objects in dynamic scenes. Mipmaps: Pre-filtered texture maps at different resolutions OpenGL figures out which map to use when No Free Lunch! Increased storage and computation

21 Why we need Mipmaps? WithoutWith

22 Mipmaps

23 Texture averaging/interpolation Nearest (Linear) – texel nearest to the pixel under consideration Linear (Bilinear) – weighted average of the 4 nearest texels to the pixel under consideration Trade off between image quality and speed

24 Mipmaps (Contd..) Specifying maps – Manually: glTextImage2D called each time for each map with different parameters – Automatically: build using gluBuild*DMipmaps() gluBuild2DMipmaps(GL_TEXTURE_2D,3,p->sizeX,p- >sizeY,GL_RGB,GL_UNSIGNED_BYTE, p->data)


Download ppt "ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny TA. Abhishek Gattani TA. Stephen"

Similar presentations


Ads by Google