Example #1
0
//-----------------------------------------------------------------------------
// Name: render_1()
// Desc:
//-----------------------------------------------------------------------------
void render_1( void )
{
    D3DXMATRIX matView;
    D3DXMATRIX matWorld;
    D3DXMATRIX matRotation;
    D3DXMATRIX matTranslation;

    // Now we can clear just view-port's portion of the buffer to green...
    g_pd3dDevice_1->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 0.0f, 1.0f, 0.0f, 1.0f ), 1.0f, 0 );

    g_pd3dDevice_1->BeginScene();

    // For the left view-port, leave the view at the origin...
    D3DXMatrixIdentity( &matView );
    g_pd3dDevice_1->SetTransform( D3DTS_VIEW, &matView );

    // ... and use the world matrix to spin and translate the teapot
    // out where we can see it...
    D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f );
    D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
    matWorld = matRotation * matTranslation;
    g_pd3dDevice_1->SetTransform( D3DTS_WORLD, &matWorld );


    g_pd3dDevice_1->SetMaterial( &g_teapotMtrl );
    g_pTeapotMesh_1->DrawSubset(0);

    g_pd3dDevice_1->EndScene();

    // We're done! Now, we just call Present()
    g_pd3dDevice_1->Present( NULL, NULL, NULL, NULL );
}
Example #2
0
/*
 * Game update function
 */
void Game_Run(HWND hwnd)
{
    //make sure the Direct3D device is valid
    if (!d3ddev) return;

    //create pointer to the back buffer
    d3ddev->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backbuffer);

    //start rendering
    if (d3ddev->BeginScene())
    {
		RECT rect; 
		rect.top = NULL;
		rect.left = NULL;
		rect.right = 950;
		rect.bottom = 768;

		RECT rect2;
		rect2.top = 270;
		rect2.left = 110;
		rect2.right = 900;
		rect2.bottom = 768;

        d3ddev->StretchRect(surface, &rect2
			, backbuffer, &rect, D3DTEXF_NONE);
     
        //stop rendering
        d3ddev->EndScene();
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }

    //check for escape key (to exit program)
    if (KEY_DOWN(VK_ESCAPE))
        PostMessage(hwnd, WM_DESTROY, 0, 0);
}
Example #3
0
//-----------------------------------------------------------------------------
// Desc: 渲染图形
//-----------------------------------------------------------------------------
VOID Render()
{
    //设置是否启用图形反锯齿
    if(antiAlisa)
        g_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS,TRUE);
    else
        g_pd3dDevice->SetRenderState(D3DRS_MULTISAMPLEANTIALIAS,FALSE);

    //清空后台缓冲区
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(45, 50, 170)
                         , 1.0f, 0 );

    //开始在后台缓冲区绘制图形
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        //在后台缓冲区绘制图形
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );

        //结束在后台缓冲区渲染图形
        g_pd3dDevice->EndScene();
    }

    //将在后台缓冲区绘制的图形提交到前台缓冲区显示
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #4
0
//랜더
void Render(int timeDelta)
{
	//화면 청소
	if (SUCCEEDED(g_pDevice->Clear( 
		0,			//청소할 영역의 D3DRECT 배열 갯수		( 전체 클리어 0 )
		NULL,		//청소할 영역의 D3DRECT 배열 포인터		( 전체 클리어 NULL )
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,	//청소될 버퍼 플레그 ( D3DCLEAR_TARGET 컬러버퍼, D3DCLEAR_ZBUFFER 깊이버퍼, D3DCLEAR_STENCIL 스텐실버퍼
		D3DCOLOR_XRGB(255, 255, 255),			//컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB )
		1.0f,				//깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 )
		0					//스텐실 버퍼를 채울값
		)))
	{
		//화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작
		g_pDevice->BeginScene();

		static float y = 0;
		y += timeDelta / 1000.f;
		// 각도가 2*PI 에 이르면 0으로 초기화한다.
		if (y >= 6.28f)
			y = 0;

		Matrix44 rx, ry, r;
		rx.SetRotationX(MATH_PI/4.f); 	// x축으로 45도 회전시킨다.
		ry.SetRotationY(y); // y축으로 회전
		r = rx*ry;
		g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&r);

		g_pMesh->DrawSubset(0) ;

		//랜더링 끝
		g_pDevice->EndScene();
		//랜더링이 끝났으면 랜더링된 내용 화면으로 전송
		g_pDevice->Present( NULL, NULL, NULL, NULL );
	}
}
// Draw one frame of the scene
void RenderScene( float updateTime )
{
    // Begin the scene
    if (SUCCEEDED(g_pd3dDevice->BeginScene()))
    {
		// Clear the z buffer & stencil buffer - no need to clear back-buffer 
		// as the skybox will always fill the background
		g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,
		                     0, 1.0f, 0 );

		// Prepare camera
		MainCamera->CalculateMatrices();

		// Render all entities
		EntityManager.RenderAllEntities( MainCamera );

		// Draw on-screen text
		RenderSceneText( updateTime );

		// End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #6
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// 消除畫面
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// 開始下繪圖指令
	device->BeginScene(); 
	// 設定轉換矩陣
	Matrix4x4 view_matrix = g_Control.GetViewMatrix();
	Matrix4x4 world_matrix = g_Control.GetObjectMatrix();
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &world_matrix);
	// 在只傳入2維貼圖座標時, Direct3D使用3x3矩陣來轉換貼圖座標.
	Matrix4x4 converted_matrix3x3 = g_texture_matrix;
	converted_matrix3x3[2] = g_texture_matrix[3];
	device->SetTransform(D3DTS_TEXTURE0, (D3DMATRIX *) &converted_matrix3x3);
	//device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
	//device->SetTexture(0, g_pTexture);
	// 畫出矩形
	device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Quad, sizeof(Vertex_VT));
	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 
	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Example #7
0
// Advances GFx animation and draws the scene.
void FxPlayerTiny::AdvanceAndDisplay()
{
    // Clear the back buffer to a black color.
    pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(200,200,200), 1.0f, 0);

    // *** GFx Rendering    
    if (pMovie)
    {
        // GRendererD3D9 does not modify D3DRS_FILLMODE, so we can set it here.
        pDevice->SetRenderState(D3DRS_FILLMODE,
            Wireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID);

        UInt32  time    = timeGetTime();
        Float   delta   = ((Float)(time - MovieLastTime)) / 1000.0f;

        // Advance time and display the movie.
        if (!Paused)
            pMovie->Advance(delta);
        pMovie->Display();

        MovieLastTime = time;
    }

    // Present the back buffer contents to the display.
    pDevice->Present(NULL, NULL, NULL, NULL);
}
Example #8
0
//
//  함수: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  목적: 주 창의 메시지를 처리합니다.
//
//  WM_COMMAND	- 응용 프로그램 메뉴를 처리합니다.
//  WM_PAINT	- 주 창을 그립니다.
//  WM_DESTROY	- 종료 메시지를 게시하고 반환합니다.
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;

	switch (message)
	{
	case WM_COMMAND:
		wmId    = LOWORD(wParam);
		wmEvent = HIWORD(wParam);
		// 메뉴 선택을 구문 분석합니다.
		switch (wmId)
		{
		case IDM_ABOUT:
			DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
			break;
		case IDM_EXIT:
			DestroyWindow(hWnd);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
		}
		break;
	case WM_PAINT:
		{
			//화면 청소
			if( SUCCEEDED( g_pDevice->Clear( 
				0,			//청소할 영역의 D3DRECT 배열 갯수		( 전체 클리어 0 )
				NULL,		//청소할 영역의 D3DRECT 배열 포인터		( 전체 클리어 NULL )
				D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL,	//청소될 버퍼 플레그 ( D3DCLEAR_TARGET 컬러버퍼, D3DCLEAR_ZBUFFER 깊이버퍼, D3DCLEAR_STENCIL 스텐실버퍼
				0xffffff00,			//컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB )
				1.0f,				//깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 )
				0					//스텐실 버퍼를 채울값
				) ) )
			{
				//화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작
				g_pDevice->BeginScene();

				//여기서부터 랜더링 명령이 실행된다..




				//랜더링 끝
				g_pDevice->EndScene();


				//랜더링이 끝났으면 랜더링된 내용 화면으로 전송
				g_pDevice->Present( NULL, NULL, NULL, NULL );
			}

		}
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}
Example #9
0
//渲染函数
//
//
bool Display(float timeDelta)
{
	timedelta=timeDelta;
	if( Device ) 
	{ 
		
		//*************绘制区域*********************
		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
		Device->BeginScene ();
		
		if(g_currentGUI == GUI_MAIN_SCREEN)
			ProcessGUI(g_MainGUI, g_LMBDown, g_MouseX,g_MouseY, GUICallback);
		else if(g_currentGUI == GUI_START_SCREEN)
			ProcessGUI(g_StartGUI, g_LMBDown, g_MouseX,g_MouseY, GUICallback);
		else if(g_currentGUI == GUI_LOAD_SCREEN)
			ProcessGUI(g_ControlGUI , g_LMBDown, g_MouseX,g_MouseY, GUICallback);
		else if(g_currentGUI == GUI_OPTION_SCREEN)
			ProcessGUI(g_StoreGUI , g_LMBDown, g_MouseX,g_MouseY, GUICallback);
		else
			ProcessGUI(g_MainGUI, g_LMBDown, g_MouseX,g_MouseY, GUICallback);

		Device->EndScene ();
		Device->Present(0, 0, 0, 0);//提交后台缓存示翻转)

	}
	return true;
}
Example #10
0
void Render()
{
    g_pd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);
    g_pd3dDevice->BeginScene();

    D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY(&matWorld, timeGetTime() / 1000.0f);
    g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);

    D3DXVECTOR3 vEyePt(0.0f, 3.0f,-5.0f);
    D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
    D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f);
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
    g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView);

    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f);
    g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj);

    for (DWORD i = 0; i < g_dwNumMaterials; i++)
    {
        g_pd3dDevice->SetMaterial(&g_pMeshMaterials[i]);
        g_pd3dDevice->SetTexture(0, g_pMeshTextures[i]);
        g_pMesh->DrawSubset(i);
    }

    g_pd3dDevice->EndScene();
    g_pd3dDevice->Present(0, 0, 0, 0);
}
Example #11
0
//-----------------------------------------------------------------------------
// Desc: 渲染场景
//-----------------------------------------------------------------------------
VOID Render()
{
	// 清除缓冲区
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
		D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

	//开始渲染场景
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		SetWorldMatrix();  //设置世界矩阵

		//逐块渲染网格模型
		for( DWORD i=0; i<g_dwNumMaterials; i++ )
		{
			//设置材料和纹理
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

			//渲染模型
			g_pMesh->DrawSubset( i );
		}

		//场景渲染结束
		g_pd3dDevice->EndScene();
	}

	//在屏幕上显示场景
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #12
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// 消除畫面
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
	// 開始下繪圖指令
	device->BeginScene(); 
	// 設定座標轉換矩陣
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_world_matrix);
	// 套用貼圖
	device->SetTexture(0, g_pTexture);
	// trilinear filter
	device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
	// 自動產生貼圖座標
	device->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEREFLECTIONVECTOR);
	//device->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT3);
	// 使用自動normalize功能
	device->SetRenderState(D3DRS_NORMALIZENORMALS, TRUE);
	// 畫模型
	// 傳入0代表不套用模型中的材質, 經由外部來設定.
	g_Model_DX9.Render(0);
	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 
	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Example #13
0
//ループ処理
bool Application::Loop()
{
	MSG msg;

	//前のフレームの描画を終了する
	d3dDevice->EndScene();

	//前のフレームの描画を反映する
	d3dDevice->Present(0, 0, 0, 0);

	//Windowsメッセージを処理する
	while (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);

		//ウィンドウを閉じる
		if (WM_QUIT == msg.message)
			return false;
	}

	//画面のクリア
	if (FAILED(d3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 60, 160), 1.0f, 0)))
		return false;

	//今のフレームの描画を開始する
	d3dDevice->BeginScene();

	return true;
}
Example #14
0
VOID Render()
{
	SetupMatrix() ;

	OnFrameMove() ;

	g_pCamera->Update(0.1f, 1.0f) ;

	// Clear the back-buffer to a RED color
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		RenderTerrain() ;

		RenderTree() ;

		RenderTeapot() ;

		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #15
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID CDlg::Render()
{
	if (! SUCCEEDED( InitVB() )) {
		return;
	}
    // Clear the backbuffer to a blue color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Draw the triangles in the vertex buffer. This is broken into a few
        // steps. We are passing the vertices down a "stream", so first we need
        // to specify the source of that stream, which is our vertex buffer. Then
        // we need to let D3D know what vertex shader to use. Full, custom vertex
        // shaders are an advanced topic, but in most cases the vertex shader is
        // just the FVF, so that D3D knows what type of vertices we are dealing
        // with. Finally, we call DrawPrimitive() which does the actual rendering
        // of our geometry (in this case, just one triangle).
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        //g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
        g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 3 );

        // End the scene
        g_pd3dDevice->EndScene();
    }

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #16
0
HRESULT KG3DGraphicsEngine::Present(CONST RECT * pSourceRect, CONST RECT * pDestRect, HWND hDestWindowOverride, CONST RGNDATA * pDirtyRegion)
{
    HRESULT hr = S_OK;

    /*
      Screen Shot
    */
    if (m_eShotImageType != D3DXIFF_FORCE_DWORD)
    {
        ScreenShotImpl();
        m_eShotImageType = D3DXIFF_FORCE_DWORD;
    }

    /*
      Present 
     */

    hr = g_pd3dDevice->Present(m_PresentParam.Windowed ? pSourceRect : NULL, pDestRect, hDestWindowOverride, pDirtyRegion);
	ASSERT(hr != D3DERR_DRIVERINTERNALERROR);

    if (hr == D3DERR_DEVICELOST)
        m_bDeviceLost = true;
    else
        KGLOG_COM_PROCESS_ERROR(hr);

Exit0:
    return hr;
}
Example #17
0
//135.
// this is the function used to render a single frame
//136.
void render_frame(void)
//137.
{
// 138.
    // clear the window to a deep blue
//139.
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0);
// 140.

//141.
    d3ddev->BeginScene(); // begins the 3D scene
//142.

// 143.
    // do 3D rendering on the back buffer here
//144.

// 145.
    d3ddev->EndScene(); // ends the 3D scene
//146.

//147.
    d3ddev->Present(NULL, NULL, NULL, NULL); // displays the created frame on the screen
//148.
}
//------------------------------------
//NAME : Direct3DRender()
//DESC : 绘制3D场景
//------------------------------------
void Direct3DRender()
{
	/*
	Direct3D的绘制过程就是:绘制→显示→绘制→显示。
	但是,每当开始绘制图形之前,都需要通过IDirect3DDevice9接口的Clear方法将后台缓存中的内容进行清空,并设置表面的填充颜色等

	HRESULT IDirect3DDevice9::Clear( 
	DWORD   Count,
	const D3DRECT *pRects, //指定对表面指定的矩形区域进行清除操作,数组中包含的矩形的数量由Count参数指定
	DWORD    Flags, //指定了需要清除的表面,该参数可以取值于D3DCLEAR_TARGET、D3DCLEAR_ZBUFFER和D3DCLEAR_STENCIL,分别表示对后台缓存、深度缓存和模板缓存进行清除
	D3DCOLOR Color, //用于指定在清除缓存内容后设置的背景色,可以通过D3DCOLOR_XRGB宏将RGB值转换给该参数
	float        Z, //指定当清除缓存内容后设置深度缓存的值
	DWORD    Stencil 
	); 

	*/
	g_pd3dDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(0,0,0),1.0f,0);//黑色背景

	//开始绘制
	g_pd3dDevice->BeginScene();

	//在绘制立方体之前,分别取得绕x,y,z轴旋转变换的矩阵,然后将他们组合并让立方体同时绕这3个轴旋转
	SetTransform();

	/*图形绘制的实际过程*/
	DrawPrimitive();

	//结束绘制
	g_pd3dDevice->EndScene();

	//翻转
	g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
Example #19
0
void render()
{
    assert(g_pd3dDevice);

    camera();

    g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0);

    g_pd3dDevice->BeginScene();
    {
        switch(g_object) {
            case sphere:
                g_pSphereMesh->DrawSubset(0);
                break;

            case cube:
                g_pCubeMesh->DrawSubset(0);
                break;

            case torus:
                g_pTorusMesh->DrawSubset(0);
                break;

            default:
                assert(!"Invalid object");
                break;
        }
    }
    g_pd3dDevice->EndScene();

    g_pd3dDevice->Present(NULL, NULL, NULL, NULL);

    g_rotation += ROTATION_DELTA;
}
Example #20
0
void Direct3DUpdate(HWND hwnd)
{
    //////////////////////////////////////////////////////////////////////////
    // Five steps of rendering: clear, beginScene, render, EndScene, present  
    //////////////////////////////////////////////////////////////////////////   
	gPD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	gPD3DDevice->BeginScene();

	gPD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);

	gPD3DDevice->SetStreamSource(0, gPVertexBuffer, 0, sizeof(CUSTOM_VERTEX));
	gPD3DDevice->SetFVF(D3DFVF_CUSTOM_VERTEX);
	gPD3DDevice->SetIndices(gPIndexBuffer);
	gPD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 17, 0, 16);

	int charCount = swprintf_s(gStrFPS, 20, _T("FPS:%0.3f"), GetFPS());
	gPFont->DrawText(NULL, gStrFPS, charCount, &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_XRGB(255, 39, 136));


	gPD3DDevice->EndScene();
	gPD3DDevice->Present(nullptr, nullptr, nullptr, nullptr);
}
Example #21
0
// 使用Direct3D9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	device->SetRenderState( D3DRS_LIGHTING, FALSE );
	device->Clear(
		0, NULL, // 清除整個畫面 
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, // 清除顏色跟Z Buffer
		D3DCOLOR_ARGB(0, 0, 0, 0), // 設定要把顏色清成黑色
		1.0f, // 設定要把Z值清為1, 也就是離鏡頭最遠.
		0 // 設定要把Stencil buffer清為0, 在這沒差.
		);

	// 計算出一個可以轉換到鏡頭座標系的矩陣
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	// 計算出一個使用非平行投影的矩陣
	Matrix4x4 perspective_matrix = GutMatrixPerspectiveRH_DirectX(90.0f, 1.0f, 1.0f, 100.0f);
	// 把這兩個矩陣相乘
	Matrix4x4 view_perspective_matrix = view_matrix * perspective_matrix;
	// 把空間中的座標點轉換到螢幕座標系上
	Vector4 vertices[16];
	for ( int i=0; i<16; i++ )
	{
		vertices[i] = g_vertices[i] * view_perspective_matrix;
		vertices[i] /= vertices[i].GetW();
	}

	device->BeginScene(); // 開始下繪圖指令
	device->SetFVF(D3DFVF_XYZ); // 設定資料格式
	// 畫出金字塔的8條邊線
	device->DrawPrimitiveUP(D3DPT_LINELIST, 8, vertices, sizeof(Vector4)); 
	device->EndScene(); // 宣告所有的繪圖指令都下完了

	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
/**-----------------------------------------------------------------------------
 * 화면 그리기
 *------------------------------------------------------------------------------
 */
VOID Render()
{
    /// 후면버퍼와 Z버퍼 초기화
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(200,200,200), 1.0f, 0 );

	/// 애니메이션 행렬설정
	Animate();
    /// 렌더링 시작
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
		g_pd3dDevice->SetTexture( 0, g_pTexDiffuse );							/// 0번 텍스쳐 스테이지에 텍스쳐 고정(색깔맵)
		g_pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );	/// 0번 텍스처 스테이지의 확대 필터
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 );		/// 0번 텍스처 : 0번 텍스처 인덱스 사용

		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE);
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

		DrawMesh( &g_matAni );
		if ( !g_bHideFrustum )
		{
			g_pFrustum->Draw( g_pd3dDevice );
		}

		/// 렌더링 종료
		g_pd3dDevice->EndScene();
    }

    /// 후면버퍼를 보이는 화면으로!
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #23
0
VOID Render() 
{ 
	// Clear the back-buffer to a RED color 
	HRESULT hr ;

	// D3DCOLOR
	hr = g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0, 1.0f, 0);

	if (FAILED(hr))
	{
		DXTRACE_ERR_MSGBOX(DXGetErrorDescription(hr), hr) ;
	}

	// Begin the scene 
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) 
	{
		// Set cull mode
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE) ;
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW) ;
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW) ; // Default option

		g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( ScreenVertex ) );
		g_pd3dDevice->SetFVF( SCREEN_SPACE_FVF );
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 );

		// End the scene 
		g_pd3dDevice->EndScene(); 
	} 

	// Present the back-buffer contents to the display 
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); 
} 
Example #24
0
VOID render(){
	g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0);

	if(SUCCEEDED(g_pDevice->BeginScene())){
		
		//Render the Shutter
		g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
		g_pDevice->SetTransform(D3DTS_WORLD, &g_matShutter);
		g_pDevice->SetStreamSource(0, g_pShutter, 0, sizeof(CUSTOMVERTEX));
		g_pDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
		g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

		//Render the Mesh
		g_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
		g_pDevice->SetTransform(D3DTS_WORLD, &g_matTank);
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
			g_pDevice->SetTexture(0, g_pMeshTextures[i]);

			g_pMesh->DrawSubset(i);
		}//Render the Mesh
		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
Example #25
0
VOID Render()
{
	// 背景为蓝色
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// 茶壶的材料颜色也定义在这个函数中
		SetupLights();

		// Setup the world, view, and projection matrices
		SetupMatrices();

		// Render the vertex buffer contents
		g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
		g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );

		//创建一个茶壶

		D3DXMATRIX  Worlds;
		D3DXCreateTeapot(g_pd3dDevice, &Objects, 0);
		Objects->DrawSubset(0);
		//释放Mesh(网格)
		Objects->Release();
		Objects = 0;
		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the backbuffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
	//Objects->Release();
}
Example #26
0
VOID Render(float timeDelta) 
{ 
	if(!PrepareShader()) 
		return ; 

	SetupMatrix(timeDelta) ; 

	// Clear the back-buffer to a RED color 
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); 

	// Begin the scene 
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) 
	{ 
		// Rendering of scene objects can happen here 
		g_pd3dDevice->SetPixelShader(g_pPixelShader) ; 

		g_pTorusMesh->DrawSubset(0) ; 

		// End the scene 
		g_pd3dDevice->EndScene(); 
	} 

	// Present the back-buffer contents to the display 
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); 
} 
Example #27
0
// `使用Direct3D9來繪圖`
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// `開始下繪圖指令`
	device->BeginScene(); 
	// `計算出一個可以轉換到鏡頭座標系的矩陣`
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);

	// `設定資料格式`
	// D3DFVF_XYZ = `使用3個浮點數來記錄位置`
	// D3DFVF_DIFFUSE = `使用32bits整數型態來記錄BGRA顏色`
	device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); 

	// `太陽`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_sun_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pSunVertices, sizeof(Vertex_VC) );
	// `地球`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_earth_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pEarthVertices, sizeof(Vertex_VC) );
	// `月亮`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_moon_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pMoonVertices, sizeof(Vertex_VC) );

	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 

	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
Example #28
0
static void Antialiasing_None(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	device->BeginScene(); 

	// `設定轉換矩陣`
	Matrix4x4 ident_matrix; ident_matrix.Identity();

	device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *) &ident_matrix);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &ident_matrix);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_world_matrix);

	device->SetRenderState(D3DRS_ZENABLE, FALSE);

	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, D3DCOLOR_RGBA(0,0,255,255), 1.0f, 0);
	// `畫出3角形`
	device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
	device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
	device->SetRenderState(D3DRS_TEXTUREFACTOR, 0xffffffff);
	device->SetFVF(D3DFVF_XYZ);
	device->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, g_Triangle, sizeof(Vector4));
	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 
	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
void Render(float timeDelta)
{
	if (!g_bActive)
	{
		Sleep(50) ;
	}

	SetupMatrix() ;

	// Clear the back-buffer to a RED color
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// Draw teapot 
		g_pTeapotMesh->DrawSubset(0) ;

		// End the scene
		g_pd3dDevice->EndScene();
	}

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
VOID renderScene() {
	d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(1, 0, 0, 0), 1.0f, 0);

	//渲染过程
	d3dDevice->BeginScene();//必须与EndScene()成对出现,指示GPU读取要渲染的数据
	/*
	  ... 渲染数据 ...
	  Draw(Box0);
	  Draw(Box1);
	  Draw(Box2);
	  Draw(Box3);
	*/
	//------------------------------------------------------------------------------------------
	d3dDevice->SetStreamSource(0, d3dVertexBuf, 0, sizeof(D3DVertexXYZRHW));//让设备载入顶点缓存
	d3dDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE);//设置设备的顶点数据结构
	d3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);//让设备根据其内的顶点缓存绘制图元
	//------------------------------------------------------------------------------------------
	d3dDevice->EndScene();//与BeginScene()成对出现,指示GPU停止读取渲染数据,并开始对已读取的数据进行计算渲染
	/*
	  ... CPU处理事项 ...
	  AI
	  逻辑
	*/
	d3dDevice->Present(NULL, NULL, NULL, NULL);//指示CPU从GPU读取渲染结果,并呈现  (此操作会等待GPU计算渲染完成才会返回,故不宜距离EndScene()过近,使CPU长期处于阻塞状态,以致失去CPU与GPU并发目的,浪费性能)
}