Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel.

Similar presentations


Presentation on theme: "CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel."— Presentation transcript:

1 CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel pipeline to the frame buffer.

2 CS425 © 2003 Ray S. Babcock Frame Buffer

3 CS425 © 2003 Ray S. Babcock Depth k ● May have 32 bits for front RGBA value. ● May also have 32 bits for back buffer RGBA value (double buffering). ● May also have 32 bits for depth values. ● There may be other buffers: ● Accumulation buffer ● Stencil buffer ● Extra color buffers ● OpenGL allows us to read or write rectangular blocks of pixels. (bit block transfer operation or bitblt “bit blat”)

4 CS425 © 2003 Ray S. Babcock Architecture of a graphics system

5 CS425 © 2003 Ray S. Babcock Bitmaps Rectangular arrays of bits

6 CS425 © 2003 Ray S. Babcock Displaying a Bitmap GLubyte wb[2] = { 0x00, 0xff }; GLubyte check[512]; int I, j; for (i=0; i<64; i++) for (j=0; j<8; j++) check[i*8+j] = wb[i/8+j % 2]; … glBitmap(64, 64, 0.0, 0.0, 0.0, 0.0, check);

7 CS425 © 2003 Ray S. Babcock glBitmap( … ); GLsizei c : height GLsizei r : width GLfloat xo : x origin of bitmap (offset cur rp ) GLfloat yo : y origin of bitmap (offset cur rp ) GLfloat xi : x increment GLfloat yi : y increment const GLubyte * bitmap Increment added to raster position after the bitmap is rasterized. (cur rp = current raster position)

8 CS425 © 2003 Ray S. Babcock Results of Example Code

9 CS425 © 2003 Ray S. Babcock OpenGL BITBLT Functions (more on this later) ● void glLogicOp(GLenum op) ● GL_COPY ● GL_OR ● GL_XOR e.g. glEnable(GL_COLOR_LOGIC_OP); glLogicOp(GL_XOR); (others) glDrawPixels, glReadPixels, glCopyPixels, glReadBuffer, glDrawBuffer, glPixelStore{if} …

10 CS425 © 2003 Ray S. Babcock Texture Mapping ● Texture mapping combines the best features of geometric objects with blocks of pixels. ● Textures are patterns. (stripes, checkerboard, grass, wood, gravel, etc.) ● Textures can be 1D, 2D, 3D, 4D. (we concentrate on 2D textures)

11 CS425 © 2003 Ray S. Babcock An Example

12 CS425 © 2003 Ray S. Babcock 2D Texture Mapping ● Coordinate systems ● Screen coordinates ● World coordinates ● Texture coordinates ● Parametric coordinates (curved surfaces) ● Textures start out as two-dimensional images. (photographs, program output...) ● The image is brought into the program as an array. ● Elements of the texture array are TEXELS or texture elements.

13 CS425 © 2003 Ray S. Babcock Cont. ● However, it is convenient to think of the texture map array as a continuous, rectangular, two-dimensional texture pattern T(s,t). ● The independent variables s and t are texture coordinates. ● These are normalized to vary over [0,1]. ● A texture map associates a unique point T with each point on a geometric object that is itself mapped to screen coordinates.

14 CS425 © 2003 Ray S. Babcock Cont. ● x = x(s,t), ● y = y(s,t), ● z = z(s,t), ● w = w(s,t). ● Inverse? ● s = s(x,y,z,w) and t = t(x,y,z,w). ● These are often very difficult to generate.

15 CS425 © 2003 Ray S. Babcock The process

16 CS425 © 2003 Ray S. Babcock Difficulties 1. Distortion often occurs with regular patterns. 2. The rendering process works pixel by pixel, so we are more interested in the inverse map from screen coordinates to texture coordinates. (The shade of a pixel is determined by what part of the texture?)

17 CS425 © 2003 Ray S. Babcock Preimage of a pixel

18 CS425 © 2003 Ray S. Babcock Aliasing in texture generation

19 CS425 © 2003 Ray S. Babcock Mapping A point p on a surface is a function of two parameters u and v. For each pair of values, we generate the point x(u,v) p(u,v) = y(u,v) z(u,v) We can often map a point in texture space T(s,t) to a point on the surface p(u,v) by u = as + bt + c and v = ds + et + f

20 CS425 © 2003 Ray S. Babcock Cont. As long as ae not equal to bd, this mapping is invertible. Linear mapping makes it easy to map a texture to a group of parametric surface patches. However, it doesn't take into account the curvature of the surface. Equal-sized texture patches must be stretched to fit over the surface patch.

21 CS425 © 2003 Ray S. Babcock Linear Texture Mapping

22 CS425 © 2003 Ray S. Babcock Two-Part Mapping 1. Map the texture to a simple three- dimensional intermediate surface sphere, cylindar, or cube 2. The intermediate surface is mapped to the surface being rendered.

23 CS425 © 2003 Ray S. Babcock With a Cylinder

24 CS425 © 2003 Ray S. Babcock With a Box

25 CS425 © 2003 Ray S. Babcock Step 2 From intermediate to surface

26 CS425 © 2003 Ray S. Babcock Texture Mapping in OpenGL OpenGL's texture maps rely on its pipeline architecture. The pipelines merge during rendering. Texture mapping is done as primitives are rasterized.

27 CS425 © 2003 Ray S. Babcock Cont. Two-dimensional texture mapping starts with an array of texels. glTexImage2D(GL_TEXTURE_2D, level, components, width, height, border, format, type, tarray); glTexImage2D(GL_TEXTURE_2D, 0, 3, 512, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, my_texels);

28 CS425 © 2003 Ray S. Babcock GlTexImage2D GLenum target Set to either GLTEXTURE_2D or GL_PROXY_TEXTURE_2D. Glint level With only one resolution, set to 0. ( multiple level of details) Glint internalFormat Indicates which of the R,G,B,and A components or luminance or intensity values are selected for use in describing the texels of an image. (1-4 or one of 38 symbolic constants, see man)

29 CS425 © 2003 Ray S. Babcock GlTexImage2D cont. GLsizei width GLsizei height Give the dimensions of the texture image. GLint border Gives the width of the border (0 no border or 1 for a border) Both width and height must be of the form (2^m + 2b) where m is a non-negative integer and b is the value of border. Maximum size depends on implementation of OpenGL (minimum of 64 x 64).

30 CS425 © 2003 Ray S. Babcock GlTexImage2D cont. GLenum format GLenum type Format and Type describe the format and data type of the texture image data. const GLvoid * texels Contain the texture image data.

31 CS425 © 2003 Ray S. Babcock glEnable(GL_TEXTURE_2D) As we do with other options, we must enable texture mapping.

32 CS425 © 2003 Ray S. Babcock Mapping the texture to an object

33 CS425 © 2003 Ray S. Babcock Left to the Application glBegin(GL_QUAD) glTexCoord2f(0.0, 0.0); glVertex2f(x1,y1,z1); glTexCoord2f(1.0, 0.0); glVertex2f(x2,y2,z2); glTexCoord2f(1.0, 1.0); glVertex2f(x3,y3,z3); glTexCoord2f(0.0, 1.0); glVertex2f(x4, y4, z4); glEnd( );

34 CS425 © 2003 Ray S. Babcock Use all or part of texture

35 CS425 © 2003 Ray S. Babcock Bilinear Interpolation

36 CS425 © 2003 Ray S. Babcock What happens when (s,t) (1.0, 1.0) GlTexParameteri( target, pname, *params); Glenum target – target texture (GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D) Glenum pname – symbolic name of the texture parameter. (see man for choices) const GLfloat *params - pointer to an array where the value(s) of pname are found. e.g. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

37 CS425 © 2003 Ray S. Babcock Point Sampling Linear Filtering

38 CS425 © 2003 Ray S. Babcock magnification/minification

39 CS425 © 2003 Ray S. Babcock magnification/minification cont. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

40 CS425 © 2003 Ray S. Babcock Examples

41 CS425 © 2003 Ray S. Babcock Examples cont.

42 CS425 © 2003 Ray S. Babcock Examples cont.

43 CS425 © 2003 Ray S. Babcock Examples cont.

44 CS425 © 2003 Ray S. Babcock Mipmapping OpenGL allows you to have different textures at different resolutions.


Download ppt "CS425 © 2003 Ray S. Babcock Pixels and Bitmaps ● OpenGL allows us to work directly with bits and groups of bits, or pixels, which flow down a parallel."

Similar presentations


Ads by Google