Lecture 5. Scan Conversion Textures hw2

Similar documents
Most device that are used to produce images are. dots (pixels) to display the image. This includes CRT monitors, LCDs, laser and dot-matrix

CS335 Graphics and Multimedia. Slides adopted from OpenGL Tutorial

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

CS212. OpenGL Texture Mapping and Related

Computer Graphics. Bing-Yu Chen National Taiwan University

Objectives. Texture Mapping and NURBS Week 7. The Limits of Geometric Modeling. Modeling an Orange. Three Types of Mapping. Modeling an Orange (2)

OpenGL Texture Mapping. Objectives Introduce the OpenGL texture functions and options

Graphics. Texture Mapping 고려대학교컴퓨터그래픽스연구실.

Imaging and Raster Primitives

Computer Graphics. Three-Dimensional Graphics VI. Guoying Zhao 1 / 73

Textures. Texture Mapping. Bitmap Textures. Basic Texture Techniques

Overview. Goals. MipMapping. P5 MipMap Texturing. What are MipMaps. MipMapping in OpenGL. Generating MipMaps Filtering.

Lecture 19: OpenGL Texture Mapping. CITS3003 Graphics & Animation

Texture Mapping. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

Texture Mapping and Sampling

Lecture 22 Sections 8.8, 8.9, Wed, Oct 28, 2009

CS Rasterization. Junqiao Zhao 赵君峤

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Spring Quarter 2016

Texture Mapping. Mike Bailey.

Buffers. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

CS 130 Final. Fall 2015

Lecture 5 3D graphics part 3

Lecture 07: Buffers and Textures

INF3320 Computer Graphics and Discrete Geometry

CISC 3620 Lecture 7 Lighting and shading. Topics: Exam results Buffers Texture mapping intro Texture mapping basics WebGL texture mapping

三維繪圖程式設計 3D Graphics Programming Design 第七章基礎材質張貼技術嘉大資工系盧天麒

ก ก ก.

Texture Mapping and Special Effects

CS 432 Interactive Computer Graphics

CS452/552; EE465/505. Texture Mapping in WebGL

Texture Mapping CSCI 4229/5229 Computer Graphics Fall 2016

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

INF3320 Computer Graphics and Discrete Geometry

CSE 167: Lecture 11: Textures 2. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2011

Chapter 9 Texture Mapping An Overview and an Example Steps in Texture Mapping A Sample Program Specifying the Texture Texture Proxy Replacing All or

CMSC 425: Lecture 12 Texture Mapping Thursday, Mar 14, 2013

CSE 167: Introduction to Computer Graphics Lecture #9: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2013

Grafica Computazionale

CSE 167: Introduction to Computer Graphics Lecture #7: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2018

Lighting and Texturing

Texture mapping. Computer Graphics CSE 167 Lecture 9

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics Texture Mapping

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Texturing. Slides done bytomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Texturas. Objectives. ! Introduce Mapping Methods. ! Consider two basic strategies. Computação Gráfica

Cap. 3 Textures. Mestrado em Engenharia Informática (6931) 1º ano, 1º semestre

Rasterization, or What is glbegin(gl_lines) really doing?

Today. Texture mapping in OpenGL. Texture mapping. Basic shaders for texturing. Today. Computergrafik

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

Rasterization: Geometric Primitives

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

From Ver(ces to Fragments: Rasteriza(on

Assignment #5: Scalar Field Visualization 3D: Direct Volume Rendering

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Computational Strategies

CS4621/5621 Fall Basics of OpenGL/GLSL Textures Basics

CSE 167: Introduction to Computer Graphics Lecture #8: Textures. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

CSE 167: Introduction to Computer Graphics Lecture #6: Lights. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2014

Announcements. Written Assignment 2 is out see the web page. Computer Graphics

Computer Graphics. - Rasterization - Philipp Slusallek

+ = Texturing: Glue n-dimensional images onto geometrical objects. Texturing. Texture magnification. Texture coordinates. Bilinear interpolation

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

Computergrafik. Matthias Zwicker Universität Bern Herbst 2016

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Einführung in Visual Computing

COMP371 COMPUTER GRAPHICS

-=Catmull's Texturing=1974. Part I of Texturing

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

CS452/552; EE465/505. Clipping & Scan Conversion

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

Topic #1: Rasterization (Scan Conversion)

Chapter 6 Texture Mapping

TSBK 07! Computer Graphics! Ingemar Ragnemalm, ISY

CS 543: Computer Graphics. Rasterization

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

EF432. Introduction to spagetti and meatballs

Assignment #3: Scalar Field Visualization 3D: Cutting Plane, Wireframe Iso-surfacing, and Direct Volume Rendering

CT5510: Computer Graphics. Texture Mapping

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Line Drawing. Foundations of Computer Graphics Torsten Möller

Clipping and Scan Conversion

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Chapter 8: Implementation- Clipping and Rasterization

9.Texture Mapping. Chapter 9. Chapter Objectives

The Traditional Graphics Pipeline

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

The Traditional Graphics Pipeline

Chapter - 2: Geometry and Line Generations

Texturing. Slides done by Tomas Akenine-Möller and Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

The Traditional Graphics Pipeline

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

Texture Mapping. Texture (images) lecture 16. Texture mapping Aliasing (and anti-aliasing) Adding texture improves realism.

Transcription:

Lecture 5 Scan Conversion Textures hw2

Announcements Homework deadlines Mini Project Proposals due June 26th

E.T. 06 Vector Graphics Algebraic equations describe shapes. Can render type and large areas of color with relatively small file sizes Can be reduced/enlarged with no loss of quality Cannot show continuous tone images (photographs, color blends) Examples: Plotters, Oscilloscopes, Illustrator, Flash

Raster Graphics aka. Pixel-based / Bit-mapped graphics Grid of pixels Size of grid = resolution of image Best for large photographic images Poor scalability : zoom in - loss of quality (jagged look) Modification at pixel level - texture mapping, blending, alpha channels, antialiasing, etc. Examples : E.T. 06 CRT, LCD, Dot-matrix printers Adobe Photoshop

Rasterization = Scan Conversion = Converting a continuous object such as a line or a circle into discrete pixels. E.T. 06

Scan Conversion of Lines

Scan conversion of lines Given two points with integer coordinates p 1 =[x 1, y 1 ], and p 2 =[x 2, y 2 ] the algorithm has to find a sequence of pixels approximating the line. Slope: (y 2 -y 1 )/(x 2 - x 1 ) We can always reorder p 1 and p 2 so that x 2 - x 1 is nonnegative. It is convenient to look at only nonnegative slopes; if the slope is negative, change the sign of y. Bunch of simplifications!

E.T. 06 Result: slope positive, and x2>x1 +y positive slope, x 2<x1 (x1,y1) (x2,y2) +x (x2,y2) negative slope (x1,y1) (x1,y1) y=0 (x2,y2) y=0 (x1,-y1) (x2,-y2)

Slope Slope reduction: it is convenient to have the slope of the line between 0 and 1; then we are able to step along x axis. slope > 1, cannot step along x To handle slope > 1, swap x and y slope < 1, can step along x

DDA Assume that the slope is between 0 and 1 Simplest algorithm (pompously called differential digital analyzer): Step along x, increment y by slope at each step. Round y to nearest pixel. float y = y1; float slope = (y2-y1)/(float)(x2-x1); int x; for(x = x1; x <= x2; x++) { } drawpixel(x, floor(y)); y += slope;

Bresenham Algorithm What is wrong with DDA? It requires floating-point operations. These operations are expensive to implement in hardware. They are not really necessary if the endpoints are integers. Idea: instead of incrementing y and rounding it at each step, decide if we just go to the right, or to the right and up using only integer quantities.

Increment decision pixel corners on different sides of the line increment both x and y pixel corners on the same side of the line increment only x Need: fast way to determine on which side of a line a point is.

Half-plane test Implicit equation can be used to perform the test. ( n (q # p)) " 0 (n (q # p)) $ 0 t he point on the same side with the normal n the point on the other side n q p p q

Implicit line equation The implicit equation of the line through p 1 =[x 1, y 1 ], and p 2 =[x 2, y 2 ] is (n,q-p 1 ) = 0, with n = [y 2, -y 1, x 1, -x 2 ] We need to test on which side of the line is the point q+d 1 = [x,y] +[1/2,1/2] d 1 [x,y] To do this, we need to determine the sign of F = (n,2q+2d 1-2p 1 ) Note that multiplication by two makes everything integer again! Key idea: compute this quantity incrementally.

Incremental computation At each step q = [x,y] changes either to [x+1,y] (step to the right) or to [x+1,y+1] (step to the right and up ); in vector form, the new value of q is either q +D 1 or q+d 2, with D 1 =[1,0] and D 2 =[1,1] Fnext = (n,2q+2d + 2d 1-2p 1 ) = (n,2q+ 2d 1-2p 1 ) + 2(n,D) = F + 2(n,D), where D is D 1 or D 2 At each step, to get new F we have to increment old F either by (n,d 1 ) or (n,d 2 ) (n,d 1 ) = y 2 -y 1 (n,d 2 ) = (y 2 -y 1 ) - (x 2 -x 1 )

Bresenham algorithm Assume the slope to be between 0 and 1. int y = y1; int dy = y2-y1; int dxdy = y2-y1+x1-x2; int F = y2-y1+x1-x2; int x; for( x = x1; x < =x2; x++ ) { drawpixel(x,y); if( F < 0 ) { F += dy; } else { y++; F+= dxdy; } }

Bresenham algorithm In For your an implementation you need to handle all slopes! First, reorder endpoints so that x 1, <= x 2 Then consider 4 cases: y 2, -y 1 >= 0, x 2, -x 1 >= y 2, -y 1 positive slope <= 1 y 2, -y 1 >= 0, x 2, -x 1 < y 2, -y 1 positive slope > 1 y 2, -y 1 < 0, x 2, -x 1 >= y 1, -y 2 negative slope >= -1 y 2, -y 1 < 0, x 2, -x 1 < y 1, -y 2 negative slope < -1 In each case, make appropriate substitutions in the algorithm.

Scan converting polygons

Polygons convex with self-intersections non-convex with holes We focus on the convex case

Scan Conversion of Convex Polygons General idea: decompose polygon into tiles scan convert each tile, moving along one edge

E.T. 06 Scan Convert a Convex Polygon void ScanY(Vertex2D v[],int num_vert,int bot_ind) Array of vertices ccw order V Index of vertex with smallest y Algorithm 1. Find left edge of tile Go around clockwise, starting from v[bot_ind], until an edge that is not contained in a scanline is found... vn-3 v1 vn-2 v0 vn-1

E.T. 06 Scan Convert a Convex Polygon void ScanY(Vertex2D v[],int num_vert,int bot_ind) Array of vertices ccw order Algorithm 1. Find left edge of tile 2. Find right edge of tile V Index of vertex with smallest y This time go ccw! vn-3... v1 vn-2 v0 vn-1

E.T. 06 Scan Convert a Convex Polygon void ScanY(Vertex2D v[],int num_vert,int bot_ind) Array of vertices ccw order V Index of vertex with smallest y Algorithm 1. Find left edge of tile 2. Find right edge of tile 3. Scan convert all scan lines going from left to right... vn-3 v1 vn-2 v0 vn-1

E.T. 06 Scan Convert a Convex Polygon void ScanY(Vertex2D v[],int num_vert,int bot_ind) Array of vertices ccw order V Index of vertex with smallest y Algorithm 1. Find left edge of tile 2. Find right edge of tile 3. Scan convert all scan lines going from left to right... vn-3 v1 vn-2 v0 vn-1

E.T. 06 Scan Convert a Convex Polygon void ScanY(Vertex2D v[],int num_vert,int bot_ind) Array of vertices ccw order V Index of vertex with smallest y Algorithm 1. Find left edge of tile 2. Find right edge of tile 3. Scan convert all scan lines going from left to right Repeat until... either endpt is v1 vn-3 reached vn-2 v0 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Convex Polygons void ScanY( Vertex2D v[], int num_vertices, int bottom_index) { } Initialize variables remaining_vertices = num_vertices; while(remaining_vertices > 0) { } Find the left top row candidate Determine the slope and starting x location for the left tile edge Find the right top row candidate Determine the slope and starting x location for the right tile edge for(row = bottom_row; row < left_top_row && row < right_top_row; row++) { ScanX(ceil(left_pos),ceil(right_pos),row); left_pos += left_step; right_pos += right_step; }... bottom_row = row; vn-3 v1 vn-2 v0 E.T. 06 vn-1

Find a tile Find the left top row candidate while( left_top_row <= bottom_row && remaining_vertices > 0) { Move to next edge: edge_start = left_edge_end; Be careful with C % operator, (N-1) % M will give -1 for N = 0, need to use (N+M-1) % M to get (N-1) mod M = N-1 left_edge_end = (left_edge_end+num_vertices-1)%num_vertices; left_top_row = ceil(v[left_edge_end].y); remaining_vertices--; } We found the first edge that sticks out over bottom_row determine the slope and starting x location for the left tile edge. if(left_top_row > bottom_row ) { left_step = (v[left_edge_end].x - v[edge_start].x)/ (v[left_edge_end].y - v[edge_start].y); left_pos = v[edge_start].x + (bottom_row-v[edge_start].y)*left_step; } vn-3 v1 vn-2 v0

Find a tile Find the right top row candidate; determine the slope and starting x location for the right tile edge. Exactly as for the left edge. Scan convert a single row: void ScanX(int left_col, int right_col, int row, int R, int G, int B) { } if( left_col < right_col) { } for( int x = left_col; x < right_col; x++) { } draw_pixel(x,y);

E.T. 06 Antialiasing

Texture Mapping

Why Textures? Brick wall - each brick separate polygon There may be bumps, rough spots... But a wall is just one large flat rectangle Then model it as one and glue a picture of a brick wall on the polygon. E.T. 06

Texture mapping Texture slides are based on E. Angel s slides y z x geometry screen image

Texture Example The texture (below) is a 256 x 256 image that has been mapped to a rectangular polygon which is viewed in perspective

E.T. 06 Steps in Texture Mapping 1. Specify a texture and create a texture object 2. Indicate how the texture is to be applied to each pixel 3. Enable texture mapping 4. Draw the scene supplying both texture and geometric coordinates

Specifying the Texture Define a texture image from an array of pixels in memory E.T. 06 void glteximage2d( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height GLint border, GLenum format, GLenum type, const GLVoid * texels ) GL_TEXTURE_2D if multiple resolutions, 0 otherwise components and resolutions GL_RGBA 2 M +2b GL_RGBA GL_UNSIGNED_BYTE

Converting A Texture Image If dimensions of image are not power of 2 gluscaleimage( format, w_in, h_in, type_in, *data_in, w_out, h_out, type_out, *data_out );! *_in is for source image! *_out is for destination image Image interpolated and filtered during scaling

Specifying a Texture: Other Methods Specifying a Texture: Other Methods Use frame buffer as source of texture image! uses current buffer as source image glcopyteximage2d(...) glcopyteximage1d(...) Modify part of a defined texture gltexsubimage2d(...) gltexsubimage1d(...) no size restriction Do both with glcopytexsubimage2d(...), etc.

E.T. 06 Texture Objects Stores texture data and makes it readily available. Have many textures and go back and forth using them Much faster than reloading an image using glteximage Sometimes a high-performance subset.

E.T. 06 Texture Objects 1. Generate texture names glgentextures(n, *texnames ); Return n unused names in array texnames creates, uses and stops using texture objects 2. Initially bind texture objects to texture data glbindtextures(target, id); Following calls to glteximage(), gltexsubimage(), gltexparameteri() store data in this texture object 3. If high-performance available - priorities 4. Bind and rebind to make textures available for models 5. Cleaning up gldeletetextures(n, *texnames);

E.T. 06 Steps in Texture Mapping 1. Specify a texture and create a texture object 2. Indicate how the texture is to be applied to each pixel 3. Enable texture mapping 4. Draw the scene supplying both texture and geometric coordinates

Texture Application Methods Filter Modes! minification or magnification! special mipmap minification filters Wrap Modes! clamping or repeating Texture Functions! how to mix primitive s color with texture s color! blend, modulate or replace texels

Filter Modes Example: gltexparameteri( target, type, mode ); Texture Magnification Polygon Texture Minification Polygon target: GL_TEXTURE_*D type : GL_TEXTURE_MAG_FILTER, GL_TEXTURE_MIN_FILTER mode: GL_NEAREST, GL_LINEAR, GL_*_MIPMAP_*(for min only) E.T. 06

E.T. 06 GL_NEAREST texel with coords nearest the center of the pixel is used. may cause aliasing artifacts. less computation GL_LINEAR weighted avg of 2x2 array texels that lie nearest to the center of the pixel. smoother results

Mipmaps multum in parvo -- many things in a small place A texture LOD technique Prespecify a series of prefiltered texture maps of decreasing resolutions Requires more texture storage Eliminates shimmering and flashing as objects move

MIPMAPS Arrange different versions into one block of memory

MIPMAPS With versus without MIPMAP

Mipmapped Textures Mipmap allows for prefiltered texture maps of decreasing resolutions Lessens interpolation errors for smaller textured objects Declare mipmap level during texture definition glteximage*d( GL_TEXTURE_*D, level, ) GLU mipmap builder routines glubuild*dmipmaps( ) (also scales orig. image) OpenGL 1.2 introduces advanced LOD controls

MipMaps OpenGL 1.2 introduces advanced LOD controls before: no on the fly changes (e.g. additional levels) could not pick lowest resolution popping effect GL_TEXTURE_BASE_LEVEL GL_TEXTURE_MAX_LEVEL GL_TEXTURE_MIN_LOD GL_TEXTURE_MAX_LOD glubuild*dmipmaplevels(...) IF YOU FAIL TO LOAD A (NEC.) MIPMAP LEVEL BUT CALL FOR IT, TEXTURES GET DISABLED

Wrapping Mode Example: gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP ) gltexparameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ) t texture s GL_REPEAT wrapping GL_CLAMP wrapping

Texture Functions Controls how texture is applied gltexenv{fi}[v]( GL_TEXTURE_ENV, prop, param ) GL_TEXTURE_ENV_MODE modes! GL_MODULATE! GL_BLEND! GL_REPLACE -use texture with lighting - different blending values per each color -overwrite current color with texture. Set blend color with GL_TEXTURE_ENV_COLOR [ GL_DECAL ] - if texture or model has translucency,it will be preserved

Perspective Correction Hint Texture coordinate and color interpolation! either linearly in screen space! or using depth/perspective values (slower) Noticeable for polygons on edge glhint( GL_PERSPECTIVE_CORRECTION_HINT, hint ) where hint is one of! GL_DONT_CARE! GL_NICEST! GL_FASTEST http://www.daimi.au.dk/~bbc/cg05/major/

E.T. 06 Steps in Texture Mapping 1. Specify a texture and create a texture object 2. Indicate how the texture is to be applied to each pixel 3. Enable texture mapping 4. Draw the scene supplying both texture and geometric coordinates

E.T. 06 glpixelstorei(gl_unpack_alignment, 1);... glenable() / gldisable() GL_TEXTURE_1D,GL_TEXTURE_2D,...

E.T. 06 Steps in Texture Mapping 1. Specify a texture and create a texture object 2. Indicate how the texture is to be applied to each pixel 3. Enable texture mapping 4. Draw the scene supplying both texture and geometric coordinates

Mapping a Texture Based on parametric texture coordinates gltexcoord*() specified at each vertex " &$%# Texture Space 1 #$%# Object Space '!$%"(%)%'&*+$%&*,(. &$%& 2 3 #$%&! '&*-$%&*+( / 0 '&*,$%&*-(

E.T. 06 Automatic Generation of Texture Coordinates gltexgen{ifd}[v] (coord, pname, param); glenable(gl_texture_gen_s/t/r) coord: GL_S, GL_T, GL_R PNAME GL_TEXTURE_GEN_MODE GL_OBJECT_PLANE GL_EYE_PLANE PARAM GL_OBJECT_LINEAR, GL_EYE_LINEAR GL_SPHERE_MAP [v] array of values

E.T. 06 Automatic Generation of Texture Coordinates Specify a plane: Ax+By+Cz+D = 0 Texture coordinates are defined as distances from this plane Example: GLfloat plane[4] = {A, B, C, D}; gltexgeni(gl_s, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR); gltexgenfv(gl_s, GL_EYE_PLANE, plane); glenable(gl_texture_gen_s);

Eye vs. Object Plane http://www.cs.utah.edu/classes/cs5610/lectures/texture%20mapping%202.pdf

Applying Textures II! specify textures in texture objects! set texture filter! set texture function! set texture wrap mode! set optional perspective correction hint! bind texture object! enable texturing! supply texture coordinates for vertex! coordinates can also be generated

Bump Mapping Bump Mapping = + Geometry Bump map Bump mapped geometry

Displacement Mapping Bump mapped normals are inconsistent with surface geometry Shadow problems Displacement mapping affects surface geometry wikipedia.org

TGA image Pixel Hw2 Help i Has 4 entries : BGRA image=>pixels() one big array 4*(i)

Sphere Think of a unit circle first - parametric equation: (cos u, sin u) gives you a point on circle. Function of one variable u [0, π] Sphere has 2 variables: the angles u,v f(u,v) = (cos(v)cos(u), cos(v)sin(u), sin(v)) u [0, π], v [ π/2, π/2] m meridians, n parallels note the poles

Alpha Channels