Chapter 07 Computer Graphics
Chapter 07 Computer Graphics
Texture Mapping
Instructor
LE Thanh Sach, Ph.D
Contact
Buffers
Texture Mapping
Texture Mapping in OpenGL
Compositing and Blending
pixel
Computer Graphics: Chapter 07 – Texture Mapping Slide: 7
OpenGL Frame Buffer
memory
source frame buffer
(destination)
writing into frame buffer
Computer Graphics: Chapter 07 – Texture Mapping Slide: 10
Writing Model
glDrawPixels(width,height,format,type,myimage)
starts at raster position
fscanf(fd, "%c",&c);
while(c == '#')
{
fscanf(fd, "%[^\n] ", b);
printf("%s\n",b);
fscanf(fd, "%c",&c);
}
ungetc(c,fd);
nm = n*m;
image=malloc(3*sizeof(GLuint)*nm);
s=255./k;
scale factor
for(i=0;i<nm;i++)
{
fscanf(fd,"%d %d %d",&red, &green, &blue );
image[3*nm-3*i-3]=red;
image[3*nm-3*i-2]=green;
image[3*nm-3*i-1]=blue;
}
glPixelTransferf(GL_RED_SCALE, s);
glPixelTransferf(GL_GREEN_SCALE, s);
glPixelTransferf(GL_BLUE_SCALE, s);
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glDrawPixels(n,m,GL_RGB,
GL_UNSIGNED_INT, image);
glFlush();
}
Texture Mapping
Uses images to fill inside of polygons
Environment (reflection mapping)
Uses a picture of the environment for
texture maps
Allows simulation of highly specular surfaces
Bump mapping
Emulates altering normal vectors during the
rendering process
2D image
3D surface
Computer Graphics: Chapter 07 – Texture Mapping Slide: 40
Coordinate Systems
Parametric coordinates
May be used to model curves and surfaces
Texture coordinates
Used to identify points in the image to be
mapped
Object or World Coordinates
Conceptually, where the mapping takes place
Window Coordinates
Where the final image is really produced
parametric coordinates
texture coordinates
window coordinates
world coordinates
pixel
preimage
z x
geometry display
t
image
s
Computer Graphics: Chapter 07 – Texture Mapping Slide: 55
Texture Example
fragment
image pixel pipeline processor
c (0.4, 0.2)
b
B C
0, 0 1, 0 s (0.8, 0.4)
glBegin(GL_POLYGON);
glColor3f(r0, g0, b0); //if no shading used
glNormal3f(u0, v0, w0); // if shading used
glTexCoord2f(s0, t0);
glVertex3f(x0, y0, z0);
glColor3f(r1, g1, b1);
glNormal3f(u1, v1, w1);
glTexCoord2f(s1, t1);
glVertex3f(x1, y1, z1);
.
.
glEnd();
s
GL_REPEAT GL_CLAMP
texture wrapping wrapping
Modes determined by
glTexParameteri( target, type, mode )
glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MAG_FILTER,
GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXURE_MIN_FILTER,
GL_LINEAR);
mipmapped mipmapped
point linear
sampling filtering
Environment Maps
Start with image of environment through a
wide angle lens
Can be either a real scanned image or an image
created in OpenGL
Use this texture to generate a spherical map
Use automatic texture coordinate generation
Multitexturing
Apply a sequence of textures through
cascaded texture units
Computer Graphics: Chapter 07 – Texture Mapping Slide: 75
Compositing and Blending
opaque surface =1
destination blending
factor Color Buffer
glEnable(GL_FOG);
glFogf(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, 0.5);
glFOgv(GL_FOG, fcolor);
no overlap overlap
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
Compositing
Image Filtering (convolution)
Whole scene antialiasing
Motion effects