Example #1
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(0,0,0),			//컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB )
		1.0f,				//깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 )
		0					//스텐실 버퍼를 채울값
		)))
	{
		//화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작
		g_pDevice->BeginScene();

		//r.SetTranslate(Vector3(0, 0, -498)); // teapot
		g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&g_LocalTm);

		g_pDevice->SetMaterial(&g_Mtrl);
		if (g_Mesh)
			g_Mesh->DrawSubset(0);

		//랜더링 끝
		g_pDevice->EndScene();
		//랜더링이 끝났으면 랜더링된 내용 화면으로 전송
		g_pDevice->Present( NULL, NULL, NULL, NULL );
	}
}
Example #2
0
void render()
{
    assert(g_pd3dDevice);

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

    D3DCOLOR color[3];
    color[0] = D3DCOLOR_XRGB(255, 0, 0);
    color[1] = D3DCOLOR_XRGB(0, 255, 0);
    color[2] = D3DCOLOR_XRGB(0, 0, 255);

    int i = 0;
    int step = 50;

    int delta = 0;
    int max_delta = 2;

    g_pd3dDevice->BeginScene();
    {
        RECT rect(*g_pRect);
        while(rect.top < rect.bottom) {
            delta = (rand() % max_delta) - max_delta / 2;
            rect.top += delta;
            g_pFont->DrawText(NULL, "This text is created using ID3DXFont =)))", -1, &rect, DT_TOP | DT_LEFT, color[i]);
            i = ++i % 3;
            rect.top += step;
        }
    }
    g_pd3dDevice->EndScene();

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

    camera();
}
Example #3
0
void Render()
{
	if(g_pD3DDevice==NULL) return;

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

	//Begin the scene
	g_pD3DDevice->BeginScene();

	SetupRotation();
	SetupCamera();
	SetupPerspective();

	//Rendering triangles
	int triCount=0;
	g_pD3DDevice->SetStreamSource(0, g_pVertexBuffer, 0, sizeof(CUSTOMVERTEX));
	g_pD3DDevice->SetFVF(D3DFVF_CUSTOMVERTEX);
	triCount+=g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);

	char msg[256];
	sprintf(msg, "每桢渲染的三角形数:%d", triCount);
	g_pFont->DrawText(msg, 5, 5, D3DCOLOR_XRGB(0, 255, 0));

	//End the scene
	g_pD3DDevice->EndScene();

	//Flip
	g_pD3DDevice->Present(NULL, NULL, NULL, NULL);
}
Example #4
0
VOID Render(float timeDelta)
{
	SetupMatrix() ;

	g_totalTime += timeDelta ;
	float x = cosf(g_totalTime) * 8.0f ;
	float y = sinf(g_totalTime) * 4.0f ;
	D3DXVECTOR3 pos(x, y, 20) ;
	
	g_Balls->Update(timeDelta, &pos) ;

	// 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) ;
		g_Balls->Render() ;

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

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #5
0
//*************************************************************************************************************
void Render(float alpha, float elapsedtime)
{
	static float time = 0;

	D3DXMATRIX viewproj;

	D3DXMatrixMultiply(&viewproj, &view, &proj);
	D3DXMatrixScaling(&world, 0.1f, 0.1f, 0.1f);

	time += elapsedtime;

	device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 0xff6694ed, 1.0f, 0);
	device->SetTransform(D3DTS_WORLD, &world);
	device->SetTransform(D3DTS_VIEW, &view);
	device->SetTransform(D3DTS_PROJECTION, &proj);

	mesh.Update(elapsedtime, &world);

	effect->SetMatrix("matViewProj", &viewproj);

	if( SUCCEEDED(device->BeginScene()) )
	{
		mesh.Draw();
		device->EndScene();
	}
	
	device->Present(NULL, NULL, NULL, NULL);
}
Example #6
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render(bool b_AutoRotation, bool b_WireframeMode)
{
    // Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the world, view, and projection matrices
		// SetupMatrices();
        if (b_AutoRotation) SetupMatrices();
		g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, (b_WireframeMode) ? D3DFILL_WIREFRAME : D3DFILL_SOLID);
		g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, (b_WireframeMode) ? D3DCULL_NONE : D3DCULL_CCW);

        // D3DRenderer are divided into subsets, one for each material. Render them in
        // a loop
        for( DWORD i = 0; i < g_dwNumMaterials; i++ )
        {
            // Set the material and texture for this subset
            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );

            // Draw the mesh subset
            g_pMesh->DrawSubset( i );
        }

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

    // Present the backbuffer contents to the display
    // g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #7
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())){

		setWorldMatrix();
		//First, Render the not transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a == 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}

		//Second , Render the transparent part
		for(DWORD i=0; i<g_dwNumMaterials; ++i){
			if(g_pMeshMaterials[i].Diffuse.a != 1.0f){
				g_pDevice->SetMaterial(&g_pMeshMaterials[i]);
				g_pDevice->SetTexture(0, g_pMeshTextures[i]);

				g_pMesh->DrawSubset(i);
			}
		}
		g_pDevice->EndScene();
	}
	g_pDevice->Present(NULL, NULL, NULL, NULL);
}
Example #8
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer and the zbuffer
    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() ) )
    {
        // Setup the world, view, and projection matrices
        SetupMatrices();

        // Meshes are divided into subsets, one for each material. Render them in
        // a loop
        for( DWORD i=0; i<g_dwNumMaterials; i++ )
        {
            // Set the material and texture for this subset
            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] );
        
            // Draw the mesh subset
            g_pMesh->DrawSubset( i );
        }

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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #9
0
// ---------- framework : display ----------
bool rtvsD3dApp::display (LPDIRECT3DDEVICE9 pd3dDevice)
{
 	// clear backbuffers
  pd3dDevice->Clear( 0,
	NULL,
	D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
	D3DCOLOR_COLORVALUE(0.0f,0.3f,0.7f,1.0f),
	1.0f,
	0);

  // check if should render
  if (m_antShouldRender) { // ant says render
    if (
      !m_pTracer->m_shouldRender // tracer isn't rendering
      && !m_pTracer->m_isRenderDone // tracer isn't done
    ) { 
      // tell it to render
      m_pTracer->startRender();
    }
    else if (
      !m_pTracer->m_shouldRender // tracer isn't rendering
      && m_pTracer->m_isRenderDone // tracer is done
    ) {
      // reset and tell it to render
      m_pTracer->resetRender(pTexture);
      m_pTracer->startRender();
    }
  }
  else // ant says don't render
  {
    if(m_pTracer->m_shouldRender) // tracer is rendering
      m_pTracer->m_shouldRender = false; // tell it to stop
  }

  // if tracer should be rendering
  if(m_pTracer->m_shouldRender)
  {
    // trace line by line & check if done
    m_antShouldRender = m_pTracer->traceNextLine();

    // try to render
    returnvalue = m_pTracer->render(pTexture);
    if (FAILED(returnvalue))
      return false;
  }

	// display solid textured quad
	pd3dDevice->SetMaterial( &quadMtrl );
	pd3dDevice->SetTexture( 0, pTexture );
	pd3dDevice->SetStreamSource( 0, pQuadVertexBuffer, 0, sizeof(QuadVertex) );
	pd3dDevice->SetFVF( QuadVertex::FVF_Flags );
	pd3dDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, numQuadTriangles );

	TwDraw();  // draw the tweak bar GUI

	// ok
	return true;

}
Example #10
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	// 取得視窗大小
	int w, h;
	GutGetWindowSize(w, h);
	// 清除畫面
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(100, 100, 100, 255), 1.0f, 0);
	// 開始下繪圖指令
	device->BeginScene(); 
	// view matrix
	Matrix4x4 view_matrix = g_Control.GetViewMatrix();
	Matrix4x4 object_matrix = g_Control.GetObjectMatrix();
	g_view_matrix = object_matrix * view_matrix;
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *)&g_view_matrix);
	// projection matrix
	device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX *)&g_projection_matrix);
	// render objects
	RenderSolarSystemDX9();

	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 
	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
//////////////////////////////////////////////////////////////////////////
// 화면 그리기
//////////////////////////////////////////////////////////////////////////
VOID Render()
{
	if ( NULL == g_pd3dDevice )
	{
		return;
	}

	// 후면 버퍼 지우기
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 20, 0, 0 ), 1.0f, 0 );

	// 렌더링 시작
	if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// 실제 렌더링 명령들이 나열될 곳
		
		//////////////////////////////////////////////////////////////////////////
		// 이 내부는 짧고 간결할 수록 좋다
		//////////////////////////////////////////////////////////////////////////

		// 행렬 설정
		SetupMatrices();

		// 버텍스 내용물 그리기
		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 #12
0
void Render(float timeDelta)
{
	if (!g_bActive)
	{
		Sleep(50) ;
	}

	SetupMatrix(timeDelta) ;

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

	// Begin the scene
	if(SUCCEEDED(g_pd3dDevice->BeginScene()))
	{
		g_pd3dDevice->SetVertexShader(g_pVertexShader);
		g_pd3dDevice->SetPixelShader(g_pPixelShader);

		// 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 Render()
{
    /// 후면버퍼와 Z버퍼 초기화
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 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 );
        /// 렌더링 종료
        g_pd3dDevice->EndScene();
    }

    /// 후면버퍼를 보이는 화면으로!
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #14
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);

	device->SetRenderState(D3DRS_LIGHTING, FALSE);

	// 設定轉換矩陣
	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);

	// 開始下繪圖指令
	device->BeginScene(); 

	SetupLightingDX9();

	g_Model_DX9.Render();

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

	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Example #15
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(); 
	// `設定資料格式`
	device->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL);
	// `套用shader`
	device->SetVertexShader(g_pSelected_VS);
	device->SetPixelShader(g_pVertexColor_PS);
	// `設定光源`
	SetupLightingDX9();
	// `設定轉換矩陣`
	Matrix4x4 world_view_proj_matrix = g_world_matrix * g_view_proj_matrix;
	device->SetVertexShaderConstantF(0, &world_view_proj_matrix[0][0], 4);
	device->SetVertexShaderConstantF(4, &g_world_matrix[0][0], 4);
	// `鏡頭位置, 計算Specular會用到.`
	device->SetVertexShaderConstantF(8, &g_eye[0], 1);
	// `畫出格子`
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP, 0, g_iNumGridVertices, g_iNumGridTriangles, 
		g_pGridIndices, D3DFMT_INDEX16, g_pGridVertices, sizeof(Vertex_V3N3) );
	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 
	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
Example #16
0
void AVDirector::RunToInnerSystem()
{
	static LPDIRECT3DDEVICE9 device = m_Application->GetD3DDevice();

    device->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(200,200,200), 1.0f, 0 );

	if( m_isStart )
	{
		if( m_state == AV_STATE_END )			
			SCENE->End();
		if( m_state == AV_STATE_INIT )		
			SCENE->Init(); 

		if( m_state != AV_STATE_LOOP )
		{
			m_state = (m_state + 1) % 3;
			return;
		}

		SCENE->Loop();
	}

	if( SUCCEEDED( device->BeginScene() ) )
	{
		//이너 업데이트에서 랜더부분, update부분 따로 뜯는걸 찾아보든가
		//솔까 루프 2번돌면 귀찮은데 이대로 하자
		SCENE->InnerUpdate();
		device->EndScene();
	}

	m_Application->GetD3DDevice()->Present(NULL,NULL,NULL,NULL);
}
Example #17
0
void render()
{
    if (NULL != pd3dDevice)
    {
        pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                          D3DCOLOR_XRGB(0, 0, 0),
                          1.0f, 0);
		pd3dDevice->BeginScene();

		// create the camera
		createCamera(0.1f, 10.0f);		// near clip plane, far clip plane

        // Position camera so cube is same projected size as in OpenGL version
		moveCamera(D3DXVECTOR3(0.0f, 0.0f, -1.6f));
		pointCamera(D3DXVECTOR3(0.0f, 0.0f, 0.0f));

		// draw the objects
		drawCube();
        drawCursor();
		
		pd3dDevice->EndScene();
        pd3dDevice->Present(NULL, NULL, NULL, NULL);

    }
}
Example #18
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, 102, 204), 1.0f, 0)))
		return false;

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

	return true;
}
Example #19
0
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	device->BeginScene(); 

	Matrix4x4 view_matrix = g_Control.GetViewMatrix();
	Matrix4x4 world_matrix = g_Control.GetObjectMatrix();

	// normal pass
	if ( g_bPosteffect )
	{
		device->SetRenderTarget(0, g_pFrameSurface[FULLSIZE]);
		device->SetDepthStencilSurface(NULL);
	}
	else
	{
		device->SetRenderTarget(0, g_pMainSurface);
		device->SetDepthStencilSurface(NULL);
	}

	device->Clear(0, NULL, D3DCLEAR_TARGET, 0x0, 1.0f, 0);

	device->SetVertexShader(NULL);
	device->SetPixelShader(NULL);

	device->SetRenderState(D3DRS_LIGHTING, FALSE);
	device->SetRenderState(D3DRS_ZENABLE, FALSE);
	device->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);

	device->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&g_proj_matrix);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&view_matrix);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *)&world_matrix);

	g_Model_DX9.Render();

	if ( g_bPosteffect )
	{
		ConverToLogLuminance(g_pFrameBuffer[FULLSIZE], &g_ImageInfo);
		// ExpLuminance(g_pFrameSurface[FULLSIZE], g_pFrameBuffer[DOWNSAMPLED_256x256], &g_Image256x256);

		AverageLuminance(g_pFrameBuffer[DOWNSAMPLED_256x256]);
		ExpLuminance();
		AdaptiveLuminance();

		device->SetRenderTarget(0, g_pMainSurface);
		device->SetDepthStencilSurface(NULL);
		//device->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, 0x0, 1.0f, 0);
		
		AutoExposure();

		if ( g_iMode & 0x01 )
		{
			DrawImage(g_pFrameBuffer[LUMINANCE_TEMP], &g_Image1x1, -1.0f, -1.0f, 0.1f, 0.1f);
			DrawImage(g_pFrameBuffer[LUMINANCE_CURRENT], &g_Image1x1, -0.9f, -1.0f, 0.1f, 0.1f);
		}
	}

	device->EndScene();
	device->Present( NULL, NULL, NULL, NULL );
}
Example #20
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer and the zbuffer
    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() ) )
    {
        // Setup the lights and materials
        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 );
        g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );

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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #21
0
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 
		DrawTeapot();

		// 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并发目的,浪费性能)
}
Example #23
0
//-----------------------------------------------------------------------------
// Desc: 渲染图形 
//-----------------------------------------------------------------------------
VOID Render()
{
	//清空后台缓冲区
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(45, 50, 170), 1.0f, 0 );

	//开始在后台缓冲区绘制图形
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		//设置世界矩阵
		SetupWorldMatrice();

		//在后台缓冲区绘制图形
		static bool first = true;
		if (first)
		{
			g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
			g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
			first = false;
		}
		g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2 );

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

	//将在后台缓冲区绘制的图形提交到前台缓冲区显示
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #24
0
bool RageDisplay_D3D::BeginFrame()
{
	GraphicsWindow::Update();

	switch( g_pd3dDevice->TestCooperativeLevel() )
	{
	case D3DERR_DEVICELOST:
		return false;
	case D3DERR_DEVICENOTRESET:
		{
			bool bIgnore = false;
			RString sError = SetD3DParams( bIgnore );
			if( sError != "" )
				RageException::Throw( sError );

			break;
		}
	}

	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
						 D3DCOLOR_XRGB(0,0,0), 1.0f, 0x00000000 );
	g_pd3dDevice->BeginScene();

	return RageDisplay::BeginFrame();
}
Example #25
0
//! Prepares the projection and view matrices on the device for rendering object to impostor.
VOID IImpostorable::PrepareRenderToImpostor(LPDIRECT3DDEVICE9 pd3dDevice,
                                 const D3DXVECTOR3* m_corners, 
                                 const D3DXVECTOR3* pEyePt, 
                                 const D3DXVECTOR3* pObjPt, 
                                 const D3DXVECTOR3* pWorldUp, 
                                 const D3DVIEWPORT9* pViewport, 
                                 const D3DXMATRIX* pMatProj, 
                                 const D3DXMATRIX* pMatWorld)
{
    HRESULT hr;
    // Use VIEWPOINT NORMAL, NOT lookAt Normal for view matrix (ie: normal of direction from camera to object).
    D3DXMATRIX viewpointView;
    D3DXMatrixLookAtLH(&viewpointView, pEyePt, pObjPt, pWorldUp); 

    GenerateWorldSpaceBBPlaneCoordinates(m_corners, pViewport, pMatProj, &viewpointView, pMatWorld);  

    // Get Matrices        
    D3DXMATRIX newview, newproj;
    D3DXVECTOR3 newcenter;
    GetProjViewMatrices(&newproj, &newview, &newcenter, pEyePt, pWorldUp);        

    //
    // Set Matrices and RENDER TO IMPOSTOR!
    //
    V(pd3dDevice->SetTransform(D3DTS_PROJECTION, &newproj) );
    V(pd3dDevice->SetTransform(D3DTS_VIEW, &newview) );        

    // begin scene
    V( m_pRenderToSurface->BeginScene( m_pTextureSurface, NULL ) );

    V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, 
                     D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0) );

}
Example #26
0
VOID Render()
{
	SetupLight() ;
	SetupLight() ;
	SetupMatrix() ;

	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() ) )
	{
		// Draw teapot
		g_pTeapotMesh->DrawSubset(0) ;

		RenderFog(0xff00ff00, D3DFOG_LINEAR, TRUE, 10.f) ;

		//RenderGround() ;

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

	// Present the back-buffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Example #27
0
void Render::Draw(IDirect3DSurface9* renderTarget, D3DXMATRIX* view, D3DXMATRIX* projection)
{
    // Get or create device
    LPDIRECT3DDEVICE9 device = GetDevice();
    if (device == NULL) return;

    // Load shaders if it is required
//    if (!EnsureShaders()) return;

    // Prepare depth surface
    D3DSURFACE_DESC renderTargetDescription;
    renderTarget->GetDesc(&renderTargetDescription);
    D3DSURFACE_DESC depthSurfaceDescription;
    if (depthSurface != NULL) depthSurface->GetDesc(&depthSurfaceDescription);
    if (depthSurface == NULL || depthSurfaceDescription.Width != renderTargetDescription.Width || depthSurfaceDescription.Height != renderTargetDescription.Height)
    {
        if (depthSurface != NULL) depthSurface->Release();
        device->CreateDepthStencilSurface(renderTargetDescription.Width, renderTargetDescription.Height, D3DFMT_D24X8, D3DMULTISAMPLE_NONE, 0, FALSE, &depthSurface, NULL);
        if (depthSurface == NULL) return;
    }

    device->SetRenderTarget(0, renderTarget);
    device->SetDepthStencilSurface(depthSurface);
    device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);

    if (lowPolySphere == NULL)
    {
        // Create spheres
        lowPolySphere = CreateSphere(2);
        middlePolySphere = CreateSphere(3);
        highPolySphere = CreateSphere(5);
        // Create cylinders
        lowPolyCylinder = CreateCylinder(3);
        middlePolyCylinder = CreateCylinder(12);
        highPolyCylinder = CreateCylinder(24);
    }



    // FIXME: light dir must be slightly different!
    D3DVECTOR lightDirection;
    lightDirection.x = view->_13;
    lightDirection.y = view->_23;
    lightDirection.z = view->_33;
    D3DVECTOR viewDirection;
    viewDirection.x = view->_13;
    viewDirection.y = view->_23;
    viewDirection.z = view->_33;
    elementMaterials[0].SetViewLightDirection(&viewDirection, &lightDirection);

    // Rendering
    device->BeginScene();


    DrawAtoms(view, projection);
    DrawBonds(view, projection);
    DrawResidues(view, projection);

    device->EndScene();
}
//---------------------------------------
//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,D3DCOLOR_XRGB(45,50,170),1.0f,0);//蓝色

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

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

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

	//翻转
	g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}
Example #29
0
/**-----------------------------------------------------------------------------
* 화면 그리기
*------------------------------------------------------------------------------
*/
void Render()
{
	/// 후면버퍼와 Z버퍼 초기화
	g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

	/// 렌더링 시작
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		if( g_bWireMode )
			g_pd3dDevice->SetRenderState( D3DRS_FILLMODE , D3DFILL_WIREFRAME );
		else
			g_pd3dDevice->SetRenderState( D3DRS_FILLMODE , D3DFILL_SOLID );

		BaseTextureRender();
		g_pTerrain->AlphaTextureRender();
		g_pTerrain->MiniAlphaTextureRender();
		DrawFPS();
		DrawText();

		float BrushSize = g_pTerrain->GetBrushSize();
		float SmoothSize = g_pTerrain->GetSmoothSize();
		g_pTerrain->DrawPickCircle(30, SmoothSize ,0xffffff00);
		g_pTerrain->DrawPickCircle(30, BrushSize ,0xffff0000);
	
		/// 렌더링 종료
		g_pd3dDevice->EndScene();
	}

	/// 후면버퍼를 보이는 화면으로!
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
/**-----------------------------------------------------------------------------
 * 화면 그리기
 *------------------------------------------------------------------------------
 */
VOID Render()
{
	UINT nPass;

    /// 후면버퍼와 Z버퍼 초기화
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(200,200,200), 1.0f, 0 );
	g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, g_bWireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID );

	/// 애니메이션 행렬설정
	Animate();
    /// 렌더링 시작
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
		if( g_bUseVS )	// 정점 쉐이더를 사용하여 출력?
		{
			g_pEffect->SetFloat( "g_fTime", (float)(timeGetTime()) / 100 );

			/// 정점선언값과 정점 설정
			g_pd3dDevice->SetVertexDeclaration( g_pDecl );
			g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(MYVERTEX) );

			/// fx출력에 사용할 테크닉 선정
			g_pEffect->SetTechnique( "MyShader" );
			
			/// fx를 사용한 출력개시
			g_pEffect->Begin( &nPass, D3DXFX_DONOTSAVESTATE );

			/// PASS 개수만큼 출력
			for( int i = 0; i < nPass ; i++ )
			{
				g_pEffect->BeginPass( i );
				g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
				g_pEffect->EndPass();
			}

			/// fx를 사용한 출력종료
			g_pEffect->End();
		}
		else
		{
			// fx를 사용한뒤에는 이 값을 NULL로 해야 D3D고정 파이프라인을 사용할 수 있다.
			g_pd3dDevice->SetVertexShader( NULL );
			g_pd3dDevice->SetPixelShader( NULL );
			g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(MYVERTEX) );
			g_pd3dDevice->SetFVF( MYVERTEX::FVF );
			g_pd3dDevice->SetTexture( 0, g_pTexture );
			g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );	/// MODULATE연산으로 색깔을 섞음
			g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );	/// 첫번째 섞을색은 텍스쳐 색
			g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );	/// 두번째 섞을색은 정점 색
			g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_DISABLE );	/// alpha연산은 사용하지 않음
			g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );
		}

		g_pd3dDevice->EndScene();
    }

    /// 후면버퍼를 보이는 화면으로!
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}