ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny [email protected] TA. Abhishek Gattani...
-
Upload
owen-lester -
Category
Documents
-
view
222 -
download
2
Transcript of ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny [email protected] TA. Abhishek Gattani...
![Page 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.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/1.jpg)
ECSE-4750 Computer Graphics Fall 2004
Prof. Michael [email protected]
TA. Abhishek [email protected]
![Page 2: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/2.jpg)
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.
![Page 3: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/3.jpg)
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
![Page 4: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/4.jpg)
Texture Mapping to add realism
![Page 5: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/5.jpg)
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)!
![Page 6: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/6.jpg)
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
![Page 7: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/7.jpg)
Texture Data
RGBA Depth Luminance Intensity
Texel: one texture element
![Page 8: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/8.jpg)
Texture Application Modes (texture functions)
Replace Modulate/Scale Blend
![Page 9: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/9.jpg)
Loading texture data
jpeg, png, tiff, gif ?? Idea: convert to BMP and load.Note: Handle all errors when you write I/O code.
#include <GL/glaux.h> //for reading bitmap image
Function prototype– AUX_RGBImageRec *LoadBMP(char
*Filename) // Loads A Bitmap Image– Read about AUX_RGBImageRec in more detail.
![Page 10: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/10.jpg)
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 bitmapif (File) // Does The File Exist?
{ fclose(File); // Close The Handle
// Load The Bitmap And Return A Pointer
return auxDIBImageLoad(Filename);}
![Page 11: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/11.jpg)
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
![Page 12: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/12.jpg)
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);
![Page 13: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/13.jpg)
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 2n + 2(border) for some integer n. GLsizei height,//Must be 2m + 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
);
![Page 14: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/14.jpg)
Texture Parameters
void glTexParameterf(GLenum target, GLenum pname, GLfloat param );
– glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,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.
![Page 15: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/15.jpg)
Free Up Space
Image Dataif (TextureImage[0])// If Texture Exists
{if (TextureImage[0]->data)// If Texture Image Exists{
// Free The Texture Image Memoryfree(TextureImage[0]->data);
}free(TextureImage[0]);// Free The Image Structure
} Texture Data
– void glDeleteTextures( GLsizei n, const GLuint *textures);– Deletes named textures
![Page 16: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/16.jpg)
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 ShadingglClearColor(0.0f, 0.0f, 0.0f, 0.5f);// Black BackgroundglClearDepth(1.0f);// Depth Buffer SetupglEnable(GL_DEPTH_TEST);// Enables Depth TestingglDepthFunc(GL_LEQUAL);// The Type Of Depth Testing To DoglHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);// Really Nice Perspective Calculationsreturn TRUE;// Initialization Went OK
} Mode prescedence: Gl_TEXTURE_ID < GL_TEXTURE_2D <
GL_TEXTURE_3D < GL_TEXTURE_CUBE_MAP.
![Page 17: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/17.jpg)
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.
![Page 18: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/18.jpg)
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.
![Page 19: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/19.jpg)
Texture rendering
Texture mapping is image resampling Some common problems
![Page 20: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/20.jpg)
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
![Page 21: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/21.jpg)
Why we need Mipmaps?
Without With
![Page 22: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/22.jpg)
Mipmaps
![Page 23: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/23.jpg)
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
![Page 24: ECSE-4750 Computer Graphics Fall 2004 Prof. Michael Wozny wozny@cat.rpi.edu TA. Abhishek Gattani gattani@rpi.edu TA. Stephen meists@rpi.edu.](https://reader033.fdocuments.us/reader033/viewer/2022051416/56649eb05503460f94bb5d4e/html5/thumbnails/24.jpg)
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)