void RenderGradientBackground() { // clear textures g_pd3dDevice->SetTexture( 0, NULL ); g_pd3dDevice->SetTexture( 1, NULL ); d3dSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE ); d3dSetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); // don't write to z-buffer d3dSetRenderState( D3DRS_ZENABLE, FALSE ); g_pd3dDevice->SetVertexShader( D3DFVF_XYZRHW | D3DFVF_DIFFUSE ); g_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, g_BGVertices, sizeof(BG_VERTEX) ); return; }
bool CPingPong::Draw(CRenderD3D* render) { LPDIRECT3DDEVICE8 d3dDevice = render->GetDevice(); D3DXMATRIX mProjection; D3DXMatrixPerspectiveFovLH( &mProjection, DEGTORAD( 60.0f ), (f32)render->m_Width / (f32)render->m_Height, 0.1f, 2000.0f ); d3dDevice->SetTransform( D3DTS_PROJECTION, &mProjection ); // Fill in the vertex buffers with the quads TRenderVertex* vert = NULL; m_VertexBuffer->Lock( 0, 0, (BYTE**)&vert, 0); vert = AddQuad(vert, m_Ball.m_Pos, m_Ball.m_Size, m_Ball.m_Col.RenderColor()); vert = AddQuad(vert, m_Paddle[0].m_Pos, m_Paddle[0].m_Size, m_Paddle[0].m_Col.RenderColor()); vert = AddQuad(vert, m_Paddle[1].m_Pos, m_Paddle[1].m_Size, m_Paddle[1].m_Col.RenderColor()); m_VertexBuffer->Unlock(); d3dSetRenderState(D3DRS_ZENABLE, FALSE); d3dSetRenderState(D3DRS_LIGHTING, FALSE); d3dSetRenderState(D3DRS_COLORVERTEX,TRUE); d3dSetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID ); d3dSetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); d3dSetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); d3dSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1); d3dSetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE); d3dSetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); d3dSetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); d3dDevice->SetTexture( 0, NULL ); d3dDevice->SetStreamSource( 0, m_VertexBuffer, sizeof(TRenderVertex) ); d3dDevice->SetVertexShader( TRenderVertex::FVF_Flags ); CMatrix m; m.Identity(); d3dDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&m); m._43 = 70.0f; d3dDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&m); for (int pnr=0; pnr<NUMQUADS; pnr++) { d3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, pnr*4, 2 ); } return true; }
//-- Render ------------------------------------------------------------------- // //----------------------------------------------------------------------------- void ShadeWorm_c::Render() { static State_e state = STATE_NEWCOL; static int fadeCol = 0; IDirect3DSurface8* oldSurface; IDirect3DSurface8* newSurface; m_device->GetRenderTarget(&oldSurface); oldSurface->Release(); m_bufferTexture->GetSurfaceLevel(0, &newSurface); m_device->SetRenderTarget(newSurface, NULL); newSurface->Release(); if (state == STATE_NEWCOL) { if (m_randomColMap) { int newCol = rand() % m_numColMaps; if (newCol == m_colMap) m_colMap = (m_colMap+1) % m_numColMaps; else m_colMap = newCol; } else { m_colMap = (m_colMap+1) % m_numColMaps; } CreateColMap(m_colMap); m_device->Clear( 0L, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0,0,0), 1.0f, 0L ); float x = 256.0f + (100 - (rand() % 200)); float y = 256.0f + (100 - (rand() % 200)); for (int i = 0; i < m_numWorms; i++) { m_worms[i].vx = 0; m_worms[i].vy = 0; m_worms[i].x = x; m_worms[i].y = y; } state = STATE_FADEUP; m_timer = 60 * m_drawTime; } d3dSetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); d3dSetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); d3dSetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); d3dSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); d3dSetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); d3dSetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); d3dSetRenderState(D3DRS_ALPHABLENDENABLE, true); d3dSetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD); d3dSetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); d3dSetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); d3dSetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); d3dSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); d3dSetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); d3dSetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); if (state == STATE_FADEDOWN || state == STATE_DRAWING) { for (int i = 0; i < m_numWorms; i++) { m_worms[i].vx += GetRand(); Clamp(-1, 1, m_worms[i].vx); m_worms[i].vy += GetRand(); Clamp(-1, 1, m_worms[i].vy); m_worms[i].x += m_worms[i].vx; Clamp(0, 512, m_worms[i].x); m_worms[i].y += m_worms[i].vy; Clamp(0, 512, m_worms[i].y); } m_device->SetTexture(0, m_spriteTexture); for (int i = 0; i < m_numWorms; i++) RenderSprite(m_worms[i].x , m_worms[i].y, 5, 5, 0x05ffffff); } if (state == STATE_FADEUP) { fadeCol += 0x08; if (fadeCol >= 0xff) { fadeCol = 0xff; state = STATE_DRAWING; } } else if (state == STATE_FADEDOWN) { fadeCol -= 0x08; if (fadeCol <= 0) { fadeCol = 0; state = STATE_NEWCOL; } } else if (state == STATE_DRAWING) { m_timer--; if (m_timer <= 0) state = STATE_FADEDOWN; } d3dSetRenderState(D3DRS_ALPHABLENDENABLE, false); m_device->SetRenderTarget(oldSurface, NULL); m_device->SetTexture(0, m_bufferTexture); m_device->SetTexture(1, m_colMapTexture); d3dSetTextureStageState(1, D3DTSS_MAGFILTER, D3DTEXF_POINT); d3dSetTextureStageState(1, D3DTSS_MINFILTER, D3DTEXF_POINT); d3dSetTextureStageState(1, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); d3dSetTextureStageState(1, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); m_device->SetPixelShader(m_pShader); float size = fadeCol / 255.0f; RenderSprite(m_width/2.0f, m_height/2.0f, m_width/(2.0f * size), m_height/(2.0f * size), fadeCol << 24); m_device->SetPixelShader(0); m_device->SetTexture(0, NULL); m_device->SetTexture(1, NULL); } // Render
void SetupRenderState() { SetCamera(); SetMaterial(); d3dSetRenderState( D3DRS_CULLMODE, D3DCULL_CCW ); d3dSetRenderState( D3DRS_LIGHTING, TRUE ); d3dSetRenderState( D3DRS_ZENABLE, TRUE); //D3DZB_TRUE ); d3dSetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ); d3dSetRenderState( D3DRS_NORMALIZENORMALS, FALSE ); d3dSetRenderState( D3DRS_SPECULARENABLE, g_shininess > 0 ); if(world.isWireframe) d3dSetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else d3dSetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); if (world.isTextureMode) { d3dSetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE); d3dSetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE); d3dSetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT); d3dSetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE); d3dSetTextureStageState(0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR); d3dSetTextureStageState(0, D3DTSS_MINFILTER, D3DTEXF_LINEAR); d3dSetTextureStageState(0, D3DTSS_MIPFILTER, D3DTEXF_NONE); d3dSetTextureStageState(0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP); d3dSetTextureStageState(0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP); d3dSetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE); d3dSetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE); g_pd3dDevice->SetTexture( 0, g_Texture ); g_pd3dDevice->SetTexture( 1, NULL ); } }