Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS 2D Rendering."— Presentation transcript:

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

2 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

3 D3D Calls SetRenderStateSets a variety of states global to D3D (there are many) SetPixelShaderSelects how to express per-pixel calculations SetFVFSets the format of the vertices SetTextureSets a texture image (there can be more than one) SetSamplerStateSelects how the texture will be sampled from SetTextureStageStateSelects how the texture values will be used ClearFills a region of the screen to a single value DrawPrimitiveUPInitiates the actual drawing

4 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);

5 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);

6 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]));

7 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);

8 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);


Download ppt "UW EXTENSION CERTIFICATE PROGRAM IN GAME DEVELOPMENT 2 ND QUARTER: ADVANCED GRAPHICS 2D Rendering."

Similar presentations


Ads by Google