80 likes | 213 Views
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.
E N D
UW ExtensionCertificate Program inGame Development 2nd 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
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);
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);
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]));
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);
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);