94
Introduction to OpenGL (Part 3) Ref: OpenGL Programming G uide (The Red Book)

Introduction to OpenGL (Part 3)

Embed Size (px)

DESCRIPTION

Introduction to OpenGL (Part 3). Ref: OpenGL Programming Guide (The Red Book). Part 1 Introduction Geometry Viewing Light & Material. Part 2 Display List Alpha Channel Polygon Offset Part 3 Image Texture Mapping Part 4 FrameBuffers Selection & Feedback. Topics. OpenGL. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to OpenGL (Part 3)

Introduction to OpenGL(Part 3)

Ref: OpenGL Programming Guide (The Red Book)

Page 2: Introduction to OpenGL (Part 3)

Fall 2009 revised 2

Topics

Part 1 Introduction Geometry Viewing Light & Material

Part 2 Display List Alpha Channel Polygon Offset

Part 3 Image Texture Mapping

Part 4 FrameBuffers Selection & Feedback

Page 3: Introduction to OpenGL (Part 3)

OpenGL

Pixels, Bitmaps, and Images

Page 4: Introduction to OpenGL (Part 3)

Fall 2009 revised 4

Bitmaps

A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a rectangular portion of the windowSpecification:

Specified, in hex codes, in one dimensional array, row by row, starting from lower-left corner

Width need not be multiples of 8

Page 5: Introduction to OpenGL (Part 3)

Fall 2009 revised 5

BitmapsglBitmap (w, h, xbo, ybo, xbi, ybi, bitmapPtr) xbo, ybo: origin xbi, ybi: increment CRP after display

glBitmap(10, 12, 0, 0, 11, 0, bitmapPtr)

Fonts: series of

bitmaps as display list

Page 6: Introduction to OpenGL (Part 3)

Fall 2009 revised 6

Bitmap (cont)

Note: You can't rotate bitmap fonts because the bitmap is always drawn aligned to the x and y framebuffer axes.Use glColor* to set GL_CURRENT_RASTER_COLOR

Page 7: Introduction to OpenGL (Part 3)

Fall 2009 revised 7

Current Raster Position (CRP)

OpenGL maintains raster position, a 3D-position in world coordinateModified by:

glRasterPos() specify the object coordinates (as in glVertex); transformed by

MODELVIEW & PROJECTION, passed to the clipping stage. If the position is not culled, raster position is updated; otherwise, it is

not valid. glBitmap()

glGetFloatv(GL_CURRENT_RASTER_POSITION, fptr) to obtain the CRPglGetBooleanv (GL_CURRENT_RASTER_POSITION_VALID, &boolvar) to test validity of CRP

Page 8: Introduction to OpenGL (Part 3)

Fall 2009 revised 8

drawf.c

Page 9: Introduction to OpenGL (Part 3)

Fall 2009 revised 9

Bitmap Editor

This format is called xwindow bitmap, with xbm extensionBitmaps can be created by the GIMP (GNU Image Manipulation Program)Or, seek format converters

Page 10: Introduction to OpenGL (Part 3)

Fall 2009 revised 11

Another XBM Editor (Here)

A simple Tk Program; require Tcl/Tk installed

Get tcltk for Windows from ActiveTcl

Note that xbm and the opengl xbitmap format is slightly different (details)

Page 11: Introduction to OpenGL (Part 3)

Fall 2009 revised 12

Ex: XBM Edit & Display

Page 12: Introduction to OpenGL (Part 3)

Fall 2009 revised 13

APIs for Images (Pixel Rectangles)

glReadPixels() Reading pixel data

from framebuffer to processor memory.

glDrawPixels() Writing pixel data

from processor memory to framebuffer

glCopyPixels() Copying pixel data

within the framebuffer

Page 13: Introduction to OpenGL (Part 3)

Fall 2009 revised 14

Function Arguments

glReadPixels (x, y, w, h, F, T, ptr) x,y: window coordinate F: pixel format T: is data type ptr: pointer to image memory

glDrawPixels (w, h, F, T, ptr) Draw to current raster position

glCopyPixels (x, y, w, h, buffer) Buffer: GL_COLOR | GL_DEPTH | GL_STENCIL Equivalent to: Read then Draw

Page 14: Introduction to OpenGL (Part 3)

Fall 2009 revised 15

More on glCopyPixels

Note that there's no need for a format or data parameter for glCopyPixels(), since the data is never copied into processor memory. The read source buffer and the destination buffer of glCopyPixels() are specified by glReadBuffer() and glDrawBuffer() respectively Default:

single-buffer: GL_FRONT Double-buffered: GL_BACK

Page 15: Introduction to OpenGL (Part 3)

Fall 2009 revised 16

Pixel Format

GREY SCALE

GREY SCALE with alpha

Page 16: Introduction to OpenGL (Part 3)

Fall 2009 revised 17

Data Type

Page 17: Introduction to OpenGL (Part 3)

Fall 2009 revised 18

Example

255: 0xFF

See also image.c for CopyPixels

Page 18: Introduction to OpenGL (Part 3)

Fall 2009 revised 19

Example image.c

Copy the lower left corner to the CRP (where the mouse is)

For single-buffer version, only GL_FRONT is involvedWhile motion is in action, display is not calledDouble-buffer version: [from the API doc]

glutSwapBuffers promotes the contents of the back buffer to become the contents of the front buffer. The contents of the back buffer then become undefined. Reality is… two have same content

Page 19: Introduction to OpenGL (Part 3)

Fall 2009 revised 20

PixelZoom (xfactor,yfactor)

Enlarge/shrink imagesUse negative factors for reflected images

Page 20: Introduction to OpenGL (Part 3)

Fall 2009 revised 21

Image Loader (TGA)simple TGA utility in gluit.raronly load and save uncompressed images in greyscale, RGB or RGBA mode.Info in TGA header: image type [unsigned char]

1 - colour map image 2 - RGB(A) uncompressed 3 - greyscale uncompressed 9 - greyscale RLE (compressed) 10 - RGB(A) RLE (compressed)

pixel depth [unsigned char] 8 – greyscale | 24 – RGB | 32 - RGBA

Page 21: Introduction to OpenGL (Part 3)

Fall 2009 revised 22

Image Loader (PNG)Offline; Local copy at webhd2:game-lib

Page 22: Introduction to OpenGL (Part 3)

Fall 2009 revised 23

DevIL

Page 23: Introduction to OpenGL (Part 3)

Fall 2009 revised 24

int pngLoadRaw (filename,rawinfo)

Must be freed manually

Page 24: Introduction to OpenGL (Part 3)

Fall 2009 revised 25

Remark

Most graphics formats have image origin at upper/left cornerWhile OpenGL has the image origin at lower/left cornerHence, if no correction is done, every image is drawn upside down.Correction in PNG loader: pngSetStandardOrientation (1);

Page 25: Introduction to OpenGL (Part 3)

Fall 2009 revised 26

Imaging Pipeline

Page 26: Introduction to OpenGL (Part 3)

Fall 2009 revised 27

Imaging Pipeline(cont.)

glPixelStore() Controlling Pixel-Storage Modes glPixelStorei(GL_UNPACK_ALIGNMENT

, 1); Packing and unpacking refer to the way

that pixel data is written to and read from processor memory.

tells OpenGL not to skip bytes at the end of a row

Page 27: Introduction to OpenGL (Part 3)

Fall 2009 revised 28

PixelStorei(GL_UNPACK_ALIGNMENT, x)

Specifies the alignment requirements for the start of each pixel row in memory. The allowable values are: 1 (byte-alignment), 2 (rows aligned to even-numbered bytes), 4 (word-alignment [default]), and 8 (rows start on double-word boundaries).

Byte:8-bitWord:16-bitDouble-word:32-bit

Byte:8-bitWord:16-bitDouble-word:32-bit

Page 28: Introduction to OpenGL (Part 3)

Fall 2009 revised 29

Details

Byte aligned (1)

In client memory, the start of each row of pixels is …

w=3,h=2

Assuming the RGB image is of size 3x2:(three bytes per pixel)

1st row 2nd row

Double word aligned (8)

Aligned to even bytes (2); Word aligned (4)

Page 29: Introduction to OpenGL (Part 3)

Fall 2009 revised 30

Settings

For RGBA images, it doesn’t matter (each pixel has 4 bytes: RGBARGBA…)

For RGB and luminance images and images with odd width, it should be set to byte-aligned (data are densely packed)

glPixelStorei(GL_UNPACK_ALIGNMENT, 1)

glPixelStorei(GL_UNPACK_ALIGNMENT, 4)

Page 30: Introduction to OpenGL (Part 3)

Fall 2009 revised 31

Improving Pixel Pipeline Performance

A series of fragment operations is applied to pixels as they are drawn into the framebuffer. For optimum performance, disable all fragment operations (depth test, …)While performing pixel operations, disable other costly states, such as texturing and lightingIt is usually faster to draw a large pixel rectangle than to draw several small ones, since the cost of transferring the pixel data can be amortized (分攤 ) over many pixels

Page 31: Introduction to OpenGL (Part 3)

Fall 2009 revised 32

Example (depthbuffershow)

Get depth buffer content glReadPixels()

Reverse and scale! Near (white) far (black)

Display it as a luminance image glDrawPixels()

Page 32: Introduction to OpenGL (Part 3)

Fall 2009 revised 33

Example (rasterpos3)

Illustrate that CRP is a point in R3Image displayed is always parallel to projection planeFake perspective by zooming with distance to camera

Page 33: Introduction to OpenGL (Part 3)

Fall 2009 revised 34

Example (sprite)

Process sprite image Add alpha layer

Load png imageSprite animation“feel of depth”

Back-to-front rendering

pixelzoom

Page 34: Introduction to OpenGL (Part 3)

OpenGL

Texture Mapping (Introduction)

Page 35: Introduction to OpenGL (Part 3)

Fall 2009 revised 38

Steps in Texture Mapping

Specify (create) the texture Set texture parameters: Indicate how the texture is to be applied to

each pixel

Enable texture mappingDraw the scene, supplying both texture and geometric coordinates

Works only in RGB mode

Page 36: Introduction to OpenGL (Part 3)

Fall 2009 revised 39

Specify the TextureglTexImage1D()glTexImage2D()glTexImage3D()

                                                         

Page 37: Introduction to OpenGL (Part 3)

Fall 2009 revised 40

Two Dimensional Texture

glTexImage2D (GLenum target, GLint level, GLint components, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels) target : GL_TEXTURE_2D level : LOD number (0: base image) components : number of color components

(1|2|3|4) Format : pixel data format Border: 0 or 1 Width & height

2m + 2(border bit) w and h can be different

There are new extensions that removes this restriction

Page 38: Introduction to OpenGL (Part 3)

Fall 2009 revised 41

glTexImage*D supplement

In GL version 1.1 or greater, pixels may be a null pointer. In this case texture memory is allocated to accommodate a texture of width width and height height. You can then download subtextures to initialize this texture memory. The image is undefined if the user tries to apply an uninitialized portion of the texture image to a primitive.

Page 39: Introduction to OpenGL (Part 3)

Fall 2009 revised 42

Setting Texture Environment

glTexEnv{if}{v}(GLenum target, GLenum pname, TYPEparam); Setting how textures are to be interpreted: Target : GL_TEXTURE_ENV Pname: GL_TEXTURE_ENV_MODE Param: modes (DECAL|REPLACE|

MODULATE|BLEND)

Page 40: Introduction to OpenGL (Part 3)

Fall 2009 revised 43

Texture Environment Modes

GL_REPLACEGL_MODULATE (default)GL_DECALGL_BLEND

New environment modes:GL_ADD: Cv = Cf + Ct

GL_COMBINE (ARB, see here)

Page 41: Introduction to OpenGL (Part 3)

Fall 2009 revised 44

GL_MODULATE

Color of polygon affects the display of texture

Tree: (r,g,b,a) acutout = 0Polygon: (1,0,0)

Page 42: Introduction to OpenGL (Part 3)

Fall 2009 revised 45

GL_BLEND

Use with:glTexEnvfv (GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colorPtr)

Cc: texture environment color

Page 43: Introduction to OpenGL (Part 3)

Fall 2009 revised 46

GL_REPLACE

Appearance solely determined by texture

FOR TEXTURE CUT-OUTS

Tree: (r,g,b,a) acutout = 0Polygon: (1,0,0)

Page 44: Introduction to OpenGL (Part 3)

Fall 2009 revised 47

GL_DECAL

Cp: replace

RGB: DECAL=REPLACE

Tree: (r,g,b,a) acutout = 0Polygon: (1,0,0)

Page 45: Introduction to OpenGL (Part 3)

Fall 2009 revised 48

Texture + Lighting

To show fragment color, use GL_MODULATEApply specular color AFTER texture mapping:

glLightModeli (GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);

See FAQ 21.040

GL_SINGLE_COLOR

GL_SEPARATE_SPECULAR_COLOR

Page 46: Introduction to OpenGL (Part 3)

Fall 2009 revised 49

Texture Coordinates

Texture coordinate: Associate texture location (in texture

space) with vertices in the polygonglTexCoord2i (s, t); glVertex2i (x, y);

Order cannot be reversed![Think of TexCoord as state

assignment]

Page 47: Introduction to OpenGL (Part 3)

Fall 2009 revised 50

Texture Coordinates of Quadrics

Most quadric primitives have default setting for texture coordinatesTo turn on the default setting: gluQuadricTexture

(qobj, GL_TRUE)

Page 48: Introduction to OpenGL (Part 3)

Fall 2009 revised 51rasterization

Polygon (in screen space) and texture

coordinates

(1,1)

(1,0)

(0,.75) (1,1)

(1,0)

(0,.75)

Texture map (4x4)

nearestlinear

Interpolate (s,t) and lookup (r,g,b,a) in the texture map

Filters

Texture Access and Lookup

Page 49: Introduction to OpenGL (Part 3)

Fall 2009 revised 52

Magnification & Minification

Nature of problem: Mismatch between texels and pixels

1

Pixels

TexelsPixels

Magnification

Minification

Page 50: Introduction to OpenGL (Part 3)

Fall 2009 revised 53

Options

MagnificationGL_NEARESTGL_LINEAR

MinificationGL_NEAREST, GL_LINEAR, GL_NEAREST_MIPMAP_NEARESTGL_LINEAR_MIPMAP_NEARESTGL_NEAREST_MIPMAP_LINEARGL_LINEAR_MIPMAP_LINEAR

Chooses the mipmap that most closely matches the size of the pixel being textured

Chooses the two mipmaps that most closely match the size of the pixel being textured

Nearest: in Manhattan distance to the center of the pixel

Page 51: Introduction to OpenGL (Part 3)

Fall 2009 revised 54

Magnification OptionsGL_LINEAR Interpolate the

texels More time

consuming but more accurate

GL_NEAREST Snap to the

nearest texel

Page 52: Introduction to OpenGL (Part 3)

Fall 2009 revised 56

Problem with Minification

without mipmap with mipmap

Page 53: Introduction to OpenGL (Part 3)

Fall 2009 revised 57

MipmappingThe most popular method of anti-aliasing for textures‘Mip’ stands for “multum in parvo” = “many things in a

small place”The texture is downsampled to a quarter of the original

area.

2m2n

m, n∈+

2m-12n-1

d = the Level Of Detail (LOD)

Level 0

Level 1

Level 2

Level 3

Level 0 Texture

If a pixel covers2222 texels,go to level 2

and get a texel.2121,level 1

Mipmapping was invented by Lance Williams in 1983 and is described in his paper Pyramidal parametrics.

Page 54: Introduction to OpenGL (Part 3)

Fall 2009 revised 59

Minification OptionsglTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR, GL_NEAREST, GL_LINEAR_MIPMAP_LINEAR,

GL_LINEAR_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST_MIPMAP_NEAREST);

Remarks: Mipmap selection is done per pixel

Using not-yet-ready mipmap disables the texture mapping function.

Remarks: Mipmap selection is done per pixel

Using not-yet-ready mipmap disables the texture mapping function.

Page 55: Introduction to OpenGL (Part 3)

Fall 2009 revised 60

Mipmap Generation

gluBuild2DMipmaps

Storage overhead

3

4

1

11

414

141

2

Page 56: Introduction to OpenGL (Part 3)

Fall 2009 revised 61

Texture Wrap

When the texture coordinates are outside [0,1]glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,param);  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,param); param: GL_CLAMP|GL_REPEAT

Page 57: Introduction to OpenGL (Part 3)

Fall 2009 revised 62

Parameters for Wrapping

GL_CLAMP use the border

texel Diagonal: corner

texel

GL_REPEAT repeat the texels

in [0,1]

Page 58: Introduction to OpenGL (Part 3)

Fall 2009 revised 63

Texture Object

A texture object stores texture data and makes it readily availableYou can now control many textures and go back to textures that have been previously loaded into your texture resourcesUsing texture objects is usually the fastest way to apply textures, resulting in big performance gains

it is almost always much faster to bind (reuse) an existing texture object than it is to reload a texture image using glTexImage*D()

Page 59: Introduction to OpenGL (Part 3)

Fall 2009 revised 64

Texture Object API

glGenTextures Allocate n textures (integer identifiers)

glBindTexture Bind the current texture to specified identifier

glDeleteTextures Free the allocated texture identifiers Reverse of glGenTextures

Page 60: Introduction to OpenGL (Part 3)

Fall 2009 revised 65

checker.c

Page 61: Introduction to OpenGL (Part 3)

Fall 2009 revised 66

texbind.c

Once created, a named texture may be re-bound to the target of the matching dimensionality as often as needed. It is usually much faster to use glBindTexture to bind an existing named texture to one of the texture targets than it is to reload the texture image using glTexImage1D, glTexImage2D, or glTexImage3D.

Page 62: Introduction to OpenGL (Part 3)

Fall 2009 revised 67

Texture Objects

Texture properties saved in texture objects: Minification and magnification filters, wrapping

modes, border color and texture priority

When a texture object is bound again, one may edit the contents of the bound texture object. Any commands that change the above properties will change the currently bound texture as well as the current texture state.Texture environment, texgen, etc. are NOT stored in texture objects

Page 63: Introduction to OpenGL (Part 3)

Fall 2009 revised 68

Texture Loader (PNG, glpng.rar)

Features Build mipmap Load and bind 2D textures Load image data (image loader) Handle transparent image (cut-out texture)

Important API id = pngBind(filename, mipmap, trans, info,

wrapst, minfilter, magfilter) pngSetStencil(red, green, blue) pngSetStandardOrientation(1) pngLoad(filename, mipmap, trans, info)

TEXTURE ID IS RETURNED TO YOU BY PNG

LOADER

Page 64: Introduction to OpenGL (Part 3)

Fall 2009 revised 69

Texture Transforms

Texture coordinates are multiplied by a 4 by 4 matrix before any texture mapping occurs.Texture animation: using this, you can make the texture slide over the surface, rotate around it, stretch and shrink, …All matrix operations apply: Push/Pop/Mult/…

Page 65: Introduction to OpenGL (Part 3)

Fall 2009 revised 70

Texture Suite

cloud

explodesmoke

waterfire

Page 66: Introduction to OpenGL (Part 3)

Fall 2009 revised 71

Automatic TEXture Coordinate GENeration

void glTexGen{ifd}{v}(GLenum coord, GLenum pname, TYPEparam);

Coord: GL_S, GL_T, GL_R, GL_Q Pname: GL_TEXTURE_GEN_MODE Type: GL_OBJECT_LINEAR, GL_EYE_LINEAR, or

GL_SPHERE_MAP

Used when the tex coords are too cumbersome to specify, or will be changed with time.Texture environment, texgen, etc. are NOT stored in texture objects.

Page 67: Introduction to OpenGL (Part 3)

Fall 2009 revised 72

1D Texture According to Height

Continuous color gradation(0,1/32,2/32, …, 31/32)

Discrete white lines(0,0,0,1,0,0,0,1,…)

Page 68: Introduction to OpenGL (Part 3)

Fall 2009 revised 73

TexGen: Object/Eye_Linearfor a vertex with object coordinates (xo,yo,zo,wo), generated coordinate = p1xo + p2yo + p3zo + p4wo

Meaning: when p1, p2, p3 are normalized, this coord corresponds to signed distanceSimilarly, EYE_LINEAR applies to eye coordinates

(0,0,1,0)(xo,yo,zo,wo)

Initially, all texture generation functions are set to GL_EYE_LINEAR and are disabled. Both s plane equations are (1, 0, 0, 0), both t plane equations are (0, 1, 0, 0), and all r and q plane equations are (0, 0, 0, 0).

Page 69: Introduction to OpenGL (Part 3)

Fall 2009 revised 74

Eye_linear (ref)

Computing this distance in eye coordinates is a little tricky, since the plane and vertex must first be transformed to eye coordinates. if M is the modelview matrix at the time glTexGenfv( GLX, GL EYE PLANE, plane ) is called, then the transformed vertex V’ is V’ = MV, let’s call V’ = (xe, ye, ze, we). The plane must also be transformed to get a new plane A’x + B’y + C’z + D’w = 0 We get (A’,B’,C’,D’) = (A,B,C,D)M−1 and M is the modelview matrix when glTexGen is invoked. The texture coordinate is then computed as A’xe + B’ye + C’ze + D’we.

Page 70: Introduction to OpenGL (Part 3)

Fall 2009 revised 75

Eye_linear Summary

e

e

e

e

o

o

o

o

e

e

e

e

w

z

y

x

dcbatex

Mdcbadcba

M

w

z

y

x

M

w

z

y

x

coord

matrix modelview:,

1

Page 71: Introduction to OpenGL (Part 3)

Fall 2009 revised 76

Multi-Texture

What this is about … Extension Wrangler (GLEW)

Page 72: Introduction to OpenGL (Part 3)

Fall 2009 revised 77

Usages of Multitexture

Page 73: Introduction to OpenGL (Part 3)

Fall 2009 revised 78

can cascade up to 32 TE’sNote: default blending mode is GL_MODULATE

ARB_multitexture (ref)

(First) ARB-approved extension (1998)Support up to 32 texture units*Texture matrix and texgen affects the active texture environment

* glGetIntegerv (GL_MAX_TEXTURE_UNITS, &units);

My platform has only 4! OpenGL 3.1 requires minimum of 16 texture units

Page 74: Introduction to OpenGL (Part 3)

Fall 2009 revised 79

Details

OpenGL's multitexture support requires that every texture unit be fully functional and maintain state that is independent of any other texture units. Each texture unit has its own texture coordinate generation state, texture matrix state, texture enable state, and texture environment state. However, each texture unit within an OpenGL context shares the same set of texture objects.

Page 75: Introduction to OpenGL (Part 3)

Fall 2009 revised 80

Multi Texture

Page 76: Introduction to OpenGL (Part 3)

Fall 2009 revised 81

TexGen with MultitextureWhen the GL_ARB_multitexture extension is supported, glTexGen set the texture generation parameters for the currently active texture unit, selected with glActiveTexture.

TexUnit0:texture2D;(s,t) given

TexUnit1:texture1D; texGen

Page 77: Introduction to OpenGL (Part 3)

End of Part 3

Page 78: Introduction to OpenGL (Part 3)

Fall 2009 revised 83

Results from Xbm Editor

From top to bottomByte swapping

#define sample_width 16#define sample_height 10static char sample_bits[] = {0xff,0x00,0x00,0xff,0x00,0x00,0x07,0xe0,0x00,0x00,0xf0,0xf8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};

Page 79: Introduction to OpenGL (Part 3)

Fall 2009 revised 84

Converting to OpenGL Bitmap

Bottom to top & byte swapping#define sample_width 16#define sample_height 10static char sample_bits[] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0f,0x1f,0x00,0x00,0xe0,0x07,0x00,0x00,0x00,0xff,0xff,0x00};

Page 80: Introduction to OpenGL (Part 3)

Fall 2009 revised 85

Solution

Byte swap: resolved by glPixelStorei (GL_UNPACK_LSB_FIRST, 1);

Bottom to top: Recall width of bitmap need not be

multiples of 8, but it is stored in units of unsigned characters

But, the XBM Editor only allows width of multiples of 8 (8,16,24,…)

See the example code on reading it reversely

Page 81: Introduction to OpenGL (Part 3)

Fall 2009 revised 86

(almost) Useless API!

There seems to no way to make the bitmap larger (than it should be, pixels)

glPixelZoom won’t work!

Therefore, its use is limitedNevertheless, the color is free to change…

BACK

Page 82: Introduction to OpenGL (Part 3)

Fall 2009 revised 87

Texture Mapping

A way to render realistic picture w/o using too many polygons

Parallax mapping

Page 83: Introduction to OpenGL (Part 3)

Fall 2009 revised 88

Texture Coordinate System

Texture: a 2D array of color values, each unit is called texel (texture element)Every texture map has (s,t) coordinates [0,0] to [1,1]Each vertex in a polygon specifies its texture coordinates (s,t), then map to the given image to determine the corresponding texture

Page 84: Introduction to OpenGL (Part 3)

Fall 2009 revised 89

Example

Screen space view

OpenGL code

Texture Map Texture space view

Page 85: Introduction to OpenGL (Part 3)

Fall 2009 revised 90

Example

Screen space view

OpenGL code

Texture space viewTexture Map

BACK

Page 86: Introduction to OpenGL (Part 3)

Fall 2009 revised 91

Page 87: Introduction to OpenGL (Part 3)

Fall 2009 revised 92

Page 88: Introduction to OpenGL (Part 3)

Fall 2009 revised 93

Page 89: Introduction to OpenGL (Part 3)

Fall 2009 revised 94

BACK

Page 90: Introduction to OpenGL (Part 3)

Fall 2009 revised 95

OpenGL Extension (Wikipedia)

The OpenGL standard allows individual vendors to provide additional functionality through extensions as new technology is created. Extensions may introduce new functions and new constants, and may relax or remove restrictions on existing OpenGL functions. NV: Each vendor has an alphabetic abbreviation that is used in naming their new functions and constants. For example, NVIDIA's abbreviation (NV) is used in defining their proprietary function glCombinerParameterfvNV() and their constant GL_NORMAL_MAP_NV. EXT: It may happen that more than one vendor agrees to implement the same extended functionality. In that case, the abbreviation EXT is used. ARB: It may further happen that the Architecture Review Board "blesses" the extension. It then becomes known as a standard extension, and the abbreviation ARB is used.

Page 91: Introduction to OpenGL (Part 3)

Fall 2009 revised 96

Introduction

The second ARB extension was GL_ARB_multitexture, introduced in version 1.2.1. Following the official extension promotion path, multitexturing is no longer an optionally implemented ARB extension, but has been a part of the OpenGL core API since version 1.3.Before using an extension a program must first determine its availability, and then obtain pointers to any new functions the extension defines. The mechanism for doing this is platform-specific and libraries such as GLEW and GLEE exist to simplify the process.Specifications for nearly all extensions can be found at the official extension registry

Page 92: Introduction to OpenGL (Part 3)

Fall 2009 revised 97

Introduction

What extension wrangler does: Your application may find some extensions already available

through Microsoft's opengl32.lib. However, depending on your OpenGL device and device driver, a particular vendor-specific extension may or may not be present at link time.

If it's not present in opengl32.lib, you'll need to obtain the address of the extension's entry points at run time from the device's ICD.

After you obtain the entry point addresses of the extension functions you wish to use, simply call through them as normal function pointers:

FAQ: How to know which version of OpenGL you are running? What’s the difference among versions? How to know what extensions are supported?

Ref: All About OpenGL Extensions

Page 93: Introduction to OpenGL (Part 3)

Fall 2009 revised 98

Utilities

GLEW: OpenGL extension wrangler

Glview: OpenGL extension viewer

glewinfo.txt

Page 94: Introduction to OpenGL (Part 3)

Fall 2009 revised 99

Commonly Used Extensions

GL_ARB_multitextureGL_ARB_texture_cube_mapGL_ARB_texture_env_dot3GL_ARB_shadowGL_ARB_vertex_program, GL_ARB_fragment_programGL_ARB_occlusion _queryGL_ARB_texture_non_power_of_twoGL_EXT_texture3DGL_EXT_framebuffer_object

ARB – Extensions officially approved by the OpenGL Architecture Review Board

EXT – Extensions agreed upon by multiple OpenGL vendors

NV – NVIDIA Corporation

SGI – Silicon Graphics

SGIX – Silicon Graphics (experimental)

BACK