UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics

8
UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS 2D Rendering

description

UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics. 2D Rendering. Goals. Learn the basic states used in 2D rendering See how to render 2D images on the screen Review the fixed function pixel pipeline. D3D Calls. Typical global configuration. - PowerPoint PPT Presentation

Transcript of UW Extension Certificate Program in Game Development 2 nd quarter: Advanced Graphics

Page 1: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

UW EXTENSION

CERTIFICATE PROGRAM INGAME DEVELOPMENT

2ND QUARTER:ADVANCED GRAPHICS2D Rendering

Page 2: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Goals

1. Learn the basic states used in 2D rendering

2. See how to render 2D images on the screen

3. Review the fixed function pixel pipeline

Page 3: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

D3D CallsSetRenderState Sets a variety of states global to D3D (there are

many)

SetPixelShader Selects how to express per-pixel calculations

SetFVF Sets the format of the vertices

SetTexture Sets a texture image (there can be more than one)

SetSamplerState Selects how the texture will be sampled from

SetTextureStageState

Selects how the texture values will be used

Clear Fills a region of the screen to a single value

DrawPrimitiveUP Initiates the actual drawing

Page 4: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Typical global configuration Disable Z-buffering and stencil

SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); SetRenderState(D3DRS_ZWRITEENABLE, FALSE); SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

Disable pixel shader (will use the texture stage states)

SetPixelShader(NULL);

Normal shading and no culling SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

Page 5: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Typical global configuration (cont.)

Enable alpha-blending SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, FALSE); SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE); SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);

Disable alpha-testing SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);

Page 6: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Basic primitive: the rectangle Create the vertices

Vertex const vertices[4] = { { 20, 20, 0, 1, … }, { 100, 20, 0, 1, … }, { 20, 100, 0, 1, … }, { 100, 100, 0, 1, … }, };

Set up the vertex format (must match the data!) SetFVF(D3DFVF_XYZRHW | …);

And render DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices,

sizeof(vertices[0]));

Page 7: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Textures Select the texture image:

SetTexture(0, pTexture);

Select the sampling settings: SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); SetSamplerState(0, D3DSAMP_ADDRESSU,

D3DADDRESS_CLAMP); SetSamplerState(0, D3DSAMP_ADDRESSV,

D3DADDRESS_CLAMP);

Page 8: UW Extension Certificate Program in Game Development  2 nd  quarter: Advanced Graphics

Texture calculations Perform custom calculations for every pixel. For instance:

SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); SetTextureStageState(0, D3DTSS_ALPHAOP,

D3DTOP_SELECTARG1); SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT); SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);

Disable the first one that’s not needed SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);