// 랜드링 시작 void BeginRender() { // Primary Surface가 Lost되었는지 검사 //if ( lpDDSPrimary->IsLost() == DDERR_SURFACELOST ) // lpDDSPrimary->Restore(); // Viewport 지우기 lpD3DViewport->Clear2( 1UL, &D3DRect, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET , smBackColor, 1, 0L ); // lpD3DViewport->Clear2( 1UL, &D3DRect, D3DCLEAR_ZBUFFER , // smBackColor, 1, 0L ); /* // Back Surface 지우기 DDBLTFX bltFx; ZeroMemory( &bltFx, sizeof(DDBLTFX) ); bltFx.dwSize = sizeof(DDBLTFX); bltFx.dwFillColor = 65535; bltFx.dwFillColor = 0; bltFx.dwFillColor = (1<<15)+(15<<10)+(15<<5)+31; lpDDSBack->Blt( NULL, NULL, NULL, DDBLT_WAIT | DDBLT_COLORFILL, &bltFx ); */ //lpD3DDevice->BeginScene(); //smRender.SetMaterialGroup( smMaterialGroup ); //기본 메트리얼 그룹 }
// Viewport 생성 BOOL CreateViewport() { D3DVIEWPORT2 viewport; // Viewport 생성 HRESULT hresult = lpD3D->CreateViewport( &lpD3DViewport, NULL ); if ( hresult != D3D_OK ) return FALSE; // Direct3D Device 에 Viewport 추가 hresult = lpD3DDevice->AddViewport( lpD3DViewport ); if ( hresult != D3D_OK ) return FALSE; ZeroMemory( &viewport, sizeof(D3DVIEWPORT2) ); viewport.dwSize = sizeof( viewport ); viewport.dwX = D3DRect.x1; viewport.dwY = D3DRect.y1; viewport.dwWidth = D3DRect.x2; viewport.dwHeight = D3DRect.y2; viewport.dvClipWidth = 2.0f; viewport.dvClipHeight = (D3DVALUE)(D3DRect.y2 * 2.0 / D3DRect.x2); viewport.dvClipX = -1.0f; viewport.dvClipY = viewport.dvClipHeight / 2.0f; viewport.dvMinZ = 0.0f; viewport.dvMaxZ = 1.0f; //viewport.dvMinZ = 0.0f; //viewport.dvMaxZ = 1.0f; // lpD3DViewport2 설정 hresult = lpD3DViewport->SetViewport2( &viewport ); if ( hresult != D3D_OK ) return FALSE; // 현제 Viewport를 lpD3DViewport2로 설정 hresult = lpD3DDevice->SetCurrentViewport( lpD3DViewport ); if ( hresult != D3D_OK ) return FALSE; //###################################################################################### //작 성 자 : 오 영 석 if( g_IsCreateFilterEffect ) CreateNewRenderTarget(); //###################################################################################### return TRUE; }
HRESULT __stdcall DDRAWSURFACE4_HOOK_Flip(LPVOID *ppvOut, LPDIRECTDRAWSURFACE4 lpDDSurfaceTargetOverride, DWORD dwFlags) { const unsigned int hpos = 11; HRESULT ret; if(!g_config.fullscreen && ((LPDIRECTDRAWSURFACE4)ppvOut) == g_frontbuffer) { RECT rect; POINT p1, p2; GetClientRect(g_hwnd, &rect); p1.x = rect.left; p1.y = rect.top; p2.x = rect.right; p2.y = rect.bottom; ClientToScreen(g_hwnd, &p1); ClientToScreen(g_hwnd, &p2); rect.left = p1.x; rect.top = p1.y; rect.right = p2.x; rect.bottom = p2.y; ret = ((LPDIRECTDRAWSURFACE4)ppvOut)->Blt(&rect, g_backbuffer, NULL, DDBLT_WAIT, NULL); Log("BLIT FLIP\n"); } else { DDRAWSURFACE4_Flip_Type ofn = (DDRAWSURFACE4_Flip_Type)ddrawsurface4_hooks[hpos].oldFunc; HRESULT ret = ofn(ppvOut, lpDDSurfaceTargetOverride, dwFlags); LogDXError(ret); Log("IDirectDrawSurface4::%s(this=%#010lx, lpDDSurfaceTargetOverride=%#010lx, dwFlags=%#010lx)\n", ddrawsurface4_hooks[hpos].name, ppvOut, lpDDSurfaceTargetOverride, dwFlags); if(g_d3ddevice != NULL && g_binkActive == FALSE) { LPDIRECT3DVIEWPORT3 lpVP = NULL; D3DVIEWPORT2 d3dvp_old, d3dvp_new; D3DRECT rect[4]; memset(&rect, 0, sizeof(rect)); memset(&d3dvp_old, 0, sizeof(d3dvp_old)); d3dvp_old.dwSize = sizeof(d3dvp_old); ((LPDIRECT3DDEVICE3)g_d3ddevice)->GetCurrentViewport(&lpVP); lpVP->GetViewport2(&d3dvp_old); memcpy(&d3dvp_new, &d3dvp_old, sizeof(d3dvp_new)); d3dvp_new.dwSize = 0; //special case for internal call d3dvp_old.dwSize = 0; d3dvp_new.dwX = d3dvp_new.dwY = 0; d3dvp_new.dwWidth = displaymode_options[g_config.displaymode].resX; d3dvp_new.dwHeight = displaymode_options[g_config.displaymode].resY; lpVP->SetViewport2(&d3dvp_new); SetD3DRect(rect[0], 0, displaymode_options[g_config.displaymode].resX, 0, g_currentviewport.y); SetD3DRect(rect[1], 0, displaymode_options[g_config.displaymode].resX, g_currentviewport.y+g_game.height, displaymode_options[g_config.displaymode].resY); SetD3DRect(rect[2], 0, g_currentviewport.x, 0, displaymode_options[g_config.displaymode].resY); SetD3DRect(rect[3], g_currentviewport.x+g_game.width, displaymode_options[g_config.displaymode].resX, 0, displaymode_options[g_config.displaymode].resY); lpVP->Clear2(4, (LPD3DRECT)&rect, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 0, 0); lpVP->SetViewport2(&d3dvp_old); } } return ret; }
// Direct3D 제거 void ReleaseD3D() { //###################################################################################### //작 성 자 : 오 영 석 DestroyDevice( lpDeviceDesc ); //###################################################################################### //###################################################################################### //작 성 자 : 오 영 석 ReleaseNewRenderTarget(); //###################################################################################### // Viewport 제거 if ( lpD3DViewport ) { // Direct3D Device 에서 Viewport 제거 lpD3DDevice->DeleteViewport( lpD3DViewport ); lpD3DViewport->Release(); lpD3DViewport = NULL; } // Direct3D Device 제거 if ( lpD3DDevice ) { lpD3DDevice->Release(); lpD3DDevice = NULL; } // Z-Buffer Surface 제거 if ( lpDDSZBuffer ) { // Back Surface 에서 Z-Buffer Surface 제거 if ( lpDDSBack ) lpDDSBack->DeleteAttachedSurface( 0L, lpDDSZBuffer ); lpDDSZBuffer->Release(); lpDDSZBuffer = NULL; } //###################################################################################### //작 성 자 : 오 영 석 if ( lpDDSBack ) { lpDDSBack->Release(); lpDDSBack = NULL; } //###################################################################################### // Direct3D Interface 제거 if ( lpD3D ) { lpD3D->Release(); lpD3D = NULL; } // Primary Surface 제거 if ( lpDDSPrimary ) { lpDDSPrimary->Release(); lpDDSPrimary = NULL; } // DirectDraw2 Interface 제거 if ( lpDD ) { // 비디오 모드 복귀 lpDD->RestoreDisplayMode(); lpDD->Release(); lpDD = NULL; } }
HRESULT InitialiseEnvironment( LPDIRECT3DDEVICE3 lpd3dDevice, LPDIRECT3DVIEWPORT3 pvViewport, HWND hwnd ) { if ( ! LoadFile("resource/Human1.asc", Human->currentFrame, 100 ) ) return E_FAIL; if (!Human->AdvanceFrame()) return E_FAIL; if ( ! LoadFile("resource/Human15.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human2.asc", Human->currentFrame, 100) ) return E_FAIL; if (!Human->AdvanceFrame()) return E_FAIL; if ( ! LoadFile("resource/Human25.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human3.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human35.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human4.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human45.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human5.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human55.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human6.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); if ( ! LoadFile("resource/Human65.asc", Human->currentFrame, 100) ) return E_FAIL; Human->AdvanceFrame(); cout << "Files Loaded" << endl << flush; if (! Human->LoadTextures(Textures, lpd3dDevice, hwnd) ) return E_FAIL; cout << "Textures Loaded" << endl << flush; // Get a ptr to the ID3D object to create materials and/or lights. Note: // the Release() call just serves to decrease the ref count. LPDIRECT3D3 pD3D; if( FAILED( lpd3dDevice->GetDirect3D( &pD3D ) ) ) return E_FAIL; pD3D->Release(); // Create the object material. This material will be used to draw the // triangle. Note: that when we use textures, the object material is // usually omitted or left as white. if( FAILED( pD3D->CreateMaterial( &g_pmtrlObjectMtrl, NULL ) ) ) return E_FAIL; if( FAILED( pD3D->CreateMaterial( &g_pmtrlObjectMtrl2, NULL ) ) ) return E_FAIL; // Set the object material as yellow. We're setting the ambient color here // since this tutorial only uses ambient lighting. For apps that use real // lights, the diffuse and specular values should be set. (In addition, the // polygons' vertices need normals for true lighting.) D3DMATERIAL mtrl; D3DMATERIAL mtrl2; D3DMATERIALHANDLE hmtrl; ZeroMemory( &mtrl, sizeof(D3DMATERIAL) ); mtrl.dwSize = sizeof(D3DMATERIAL); mtrl.dcvDiffuse.r = mtrl.dcvAmbient.r = 1.0f; mtrl.dcvDiffuse.g = mtrl.dcvAmbient.g = 1.0f; mtrl.dcvDiffuse.b = mtrl.dcvAmbient.b = 1.0f; mtrl.dcvDiffuse.a = mtrl.dcvAmbient.a = 1.0f; mtrl.dwRampSize = 16L; // A default ramp size mtrl.power = 40.0f; g_pmtrlObjectMtrl->SetMaterial( &mtrl ); ZeroMemory( &mtrl2, sizeof(D3DMATERIAL) ); mtrl2.dwSize = sizeof(D3DMATERIAL); mtrl2.dcvAmbient.r = 0.7f; mtrl2.dcvAmbient.g = 0.6f; mtrl2.dcvAmbient.b = 0.2f; g_pmtrlObjectMtrl2->SetMaterial( &mtrl2 ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_TEXTUREPERSPECTIVE, TRUE ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_SUBPIXEL, TRUE ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DRENDERSTATE_FILLMODE ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_NONE ); lpd3dDevice->SetRenderState( D3DRENDERSTATE_DITHERENABLE, FALSE ); // Put the object material into effect. Direct3D is a state machine, and // calls like this set the current state. After this call, any polygons // rendered will be drawn using this material. g_pmtrlObjectMtrl->GetHandle( lpd3dDevice, &hmtrl ); lpd3dDevice->SetLightState( D3DLIGHTSTATE_MATERIAL, hmtrl ); // The ambient lighting value is another state to set. Here, we are turning // ambient lighting on to full white. lpd3dDevice->SetLightState( D3DLIGHTSTATE_AMBIENT, 0xffffffff ); // lpd3dDevice->SetRenderState( D3DRENDERSTATE_FILLMODE, D3DFILL_WIREFRAME ); // lpd3dDevice->SetRenderState( D3DRENDERSTATE_CULLMODE, D3DCULL_CCW ); // Set the transform matrices. Direct3D uses three independant matrices: // the world matrix, the view matrix, and the projection matrix. For // convienence, we are first setting up an identity matrix. D3DMATRIX mat; mat._11 = mat._22 = mat._33 = mat._44 = 1.0f; mat._12 = mat._13 = mat._14 = mat._41 = 0.0f; mat._21 = mat._23 = mat._24 = mat._42 = 0.0f; mat._31 = mat._32 = mat._34 = mat._43 = 0.0f; // The world matrix controls the position and orientation of the polygons // in world space. We'll use it later to spin the triangle. D3DMATRIX matWorld = mat; matWorld._22 = 0.75f; matWorld._11 = 0.75f; lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_WORLD, &matWorld ); // The view matrix defines the position and orientation of the camera. // Here, we are just moving it back along the z-axis by 10 units. D3DMATRIX matView = mat; matView._43 = VIEW_DISTANCE; // matView._42 = -100.0f; lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_VIEW, &matView ); // The projection matrix defines how the 3D scene is "projected" onto the // 2D render target (the backbuffer surface). Refer to the docs for more // info about projection matrices. D3DMATRIX matProj = mat; matProj._11 = 1.0f; matProj._22 = 1.0f; matProj._34 = 1.0f; matProj._43 = -1.0f; matProj._44 = 1.0f; lpd3dDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj ); if( FAILED( pD3D->CreateLight( &g_pLight, NULL ) ) ) return E_FAIL; D3DLIGHT light; ZeroMemory( &light, sizeof(D3DLIGHT) ); light.dwSize = sizeof(D3DLIGHT); light.dltType = D3DLIGHT_POINT; light.dvPosition.x = light.dvDirection.x = 0.0; light.dvPosition.y = light.dvDirection.y = 0.0; light.dvPosition.z = light.dvDirection.z = -10.0; light.dcvColor.r = 1.0; light.dcvColor.g = 1.0; light.dcvColor.b = 1.0; light.dvAttenuation0 = 1.0f; g_pLight->SetLight( &light ); pvViewport->AddLight( g_pLight ); return S_OK; }
//----------------------------------------------------------------------------- // Name: RenderView() // Desc: Renders the scene. This tutorial draws a bunch of intersecting // triangles that are rotating about the y-axis. Without z-buffering, // the polygons could not be drawn correctly (unless the app performed // complex polygon-division routines and sorted the polygons in back-to- // front order.) //----------------------------------------------------------------------------- HRESULT RenderView( LPDIRECT3DDEVICE3 pd3dDevice, LPDIRECT3DVIEWPORT3 pvViewport, D3DRECT* prcViewportRect ) { // Clear the viewport to a blue color. Also "clear" the z-buffer to the // value 1.0 (which represents the far clipping plane). pvViewport->Clear2( 1UL, prcViewportRect, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0x00000022, 1.0f, 0L ); // Begin the scene if( FAILED( pd3dDevice->BeginScene() ) ) return E_FAIL; // Draw all the objects Element ** TempElements; int TotalElements; // FOR ALL OBJECTS TotalElements = Human->currentFrame->TotalElements; TempElements = Human->currentFrame->ElementList; for (int n = 0; n < TotalElements; n++ ) { pd3dDevice->SetTexture( 0, TempElements[n]->ElementTexture->ptexTexture ); pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, D3DFVF_VERTEX, TempElements[n]->FaceList, TempElements[n]->GetFaceCount() * 3, NULL ); } if ( time++ >= 10) { FrameCount++; time = 0; Human->AdvanceFrame(); } if ( FrameCount >= Human->TotalFrames ) FrameCount = 0; // g_pmtrlObjectMtrl2->GetHandle( pd3dDevice, &hmtrl ); // pd3dDevice->SetLightState( D3DLIGHTSTATE_MATERIAL, hmtrl ); // End the scene. pd3dDevice->EndScene(); return S_OK; }