Exemple #1
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 );
}
bool CXModel::LoadXFile(char *file)
{
   if(!m_device) return false;

   CD3DAllocate alh;

   // Load X mesh from a file.
   if(FAILED(D3DXLoadMeshHierarchyFromX(file, D3DXMESH_MANAGED,
      m_device, &alh, NULL, &m_root, &m_animControl))) return false;

   // Record max number of animation sets in the X model.
   if(m_animControl)
      m_numAnimations = m_animControl->GetMaxNumAnimationSets();

   // Setup Bones.
   if(m_root)
      {
         SetupMatrices((stD3DFrameEx*)m_root, NULL);

         m_boneMatrices = new D3DXMATRIX[m_maxBones];
         ZeroMemory(m_boneMatrices, sizeof(D3DXMATRIX)*m_maxBones);

         D3DXFrameCalculateBoundingSphere(m_root, &m_center,
                                          &m_radius);
      }

   // Set initialize animation.
   SetAnimation(0);

   return true;
}
Exemple #3
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 );
}
//////////////////////////////////////////////////////////////////////////
// 화면 그리기
//////////////////////////////////////////////////////////////////////////
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 );
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer to a black color
    float ClearColor[4] = {0, 0, 0, 0};
    g_pd3dDevice->ClearRenderTargetView(g_pSwapChainRTV, ClearColor);

    // Run CUDA to update vertex positions
    runCuda();

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

        // Render the vertex buffer contents
        UINT stride = sizeof(CUSTOMVERTEX);
        UINT offset = 0;
        g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVB, &stride, &offset);

        g_pSimpleTechnique->GetPassByIndex(0)->Apply(0);
        g_pd3dDevice->Draw(g_NumVertices, 0);
    }

    // Present the backbuffer contents to the display
    g_pSwapChain->Present(0, 0);

    anim += 0.01f;
}
Exemple #6
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();
}
bool CEffectTechnique::BeginRender()
{
    if ( m_Effect )
    {
        // Obtain the direct x effect
        LPD3DXEFFECT l_Effect = m_Effect->GetEffect();
        D3DXHANDLE l_Handle = NULL;

        //
        // Debug color, only for debug primitives
        //
        m_Effect->SetDebugColor( mUseDebugColor, m_DebugColor );

        if ( mUseFBSize )
        {
          uint32 lWidth, lHeight;
          GraphicsInstance->GetWidthAndHeight( lWidth, lHeight );
          if( !m_Effect->SetFBSize( Math::Vect2u(lWidth, lHeight ) ) )
            LOG_WARNING_APPLICATION("Error setting Fb size" );
        }

        SetupMatrices();
        SetupLights();
    }

    return true;
}
Exemple #8
0
void CSprite::Render()
{
	const LPDIRECT3DDEVICE9 pd3dDevice = g_D3dDevice->GetDevice() ;

	SetupMatrices() ;

	pd3dDevice->SetTexture( 0, m_pTexture ) ;

	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR );
	pd3dDevice->SetRenderState( D3DRS_TEXTUREFACTOR, D3DCOLOR_ARGB( m_nAlpha, 0, 0, 0 ));	// 텍스쳐를 해당 수치만큼 밝게 한다
	//g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);	// 정점색에 있는 Alpha 채널을 값으로 알파조정 ex) pVertices[3].color = D3DCOLOR_ARGB(m_Alpha, m_R, m_G, m_B) ;

	//g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR) ;
	//g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR) ;

	pd3dDevice->SetRenderState(D3DRS_ZENABLE, TRUE) ;			// Z 버퍼 ON
	pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE) ;
	pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL ) ;

	pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE ) ; // 알파 블렌딩 ON
	pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ) ;
	pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA ) ;

	pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(SPRITE_VERTEX) );
	pd3dDevice->SetFVF( D3DFVF_SPRITE_VERTEX );
	pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2) ;

	pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE ) ; // 알파 블렌딩 OFF

	pd3dDevice->SetRenderState(D3DRS_ZENABLE, FALSE) ;			// Z 버퍼 OFF
	pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, FALSE) ;
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID D3DSample::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();

		// Meshes2 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 );
}
Exemple #10
0
void D3DProxyDevice::Init(ProxyHelper::ProxyConfig& cfg)
{
	OutputDebugString("D3D ProxyDev Init");
	stereoView = StereoViewFactory::Get(cfg);
	SetupMatrices(cfg);
	SetupOptions(cfg);
	SetupText();
}
Exemple #11
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
    g_pd3dDevice->BeginScene();

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

    // Setup our texture. Using textures introduces the texture stage states,
    // which govern how textures get blended together (in the case of multiple
    // textures) and lighting information. In this case, we are modulating
    // (blending) our texture with the diffuse color of the vertices.
    g_pd3dDevice->SetTexture( 0, g_pTexture );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_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 );

#ifdef SHOW_HOW_TO_USE_TCI
    // Note: to use D3D texture coordinate generation, use the stage state
    // D3DTSS_TEXCOORDINDEX, as shown below. In this example, we are using
    // the position of the vertex in camera space to generate texture
    // coordinates. The tex coord index (TCI) parameters are passed into a
    // texture transform, which is a 4x4 matrix which transforms the x,y,z
    // TCI coordinates into tu, tv texture coordinates.

    // In this example, the texture matrix is setup to 
    // transform the texture from (-1,+1) position coordinates to (0,1) 
    // texture coordinate space:
    //    tu =  0.5*x + 0.5
    //    tv = -0.5*y + 0.5
    D3DXMATRIX mat;
    mat._11 = 0.25f; mat._12 = 0.00f; mat._13 = 0.00f; mat._14 = 0.00f;
    mat._21 = 0.00f; mat._22 =-0.25f; mat._23 = 0.00f; mat._24 = 0.00f;
    mat._31 = 0.00f; mat._32 = 0.00f; mat._33 = 1.00f; mat._34 = 0.00f;
    mat._41 = 0.50f; mat._42 = 0.50f; mat._43 = 0.00f; mat._44 = 1.00f;

    g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, &mat );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2 );
    g_pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, D3DTSS_TCI_CAMERASPACEPOSITION );
#endif

    // Render the vertex buffer contents
    g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
    g_pd3dDevice->SetVertexShader( 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 );
}
Exemple #12
0
void VP8SetSegmentParams(VP8Encoder* const enc, float quality) {
  int i;
  int dq_uv_ac, dq_uv_dc;
  const int num_segments = enc->config_->segments;
  const double amp = SNS_TO_DQ * enc->config_->sns_strength / 100. / 128.;
  const double c_base = QualityToCompression(quality);
  for (i = 0; i < num_segments; ++i) {
    // The file size roughly scales as pow(quantizer, 3.). Actually, the
    // exponent is somewhere between 2.8 and 3.2, but we're mostly interested
    // in the mid-quant range. So we scale the compressibility inversely to
    // this power-law: quant ~= compression ^ 1/3. This law holds well for
    // low quant. Finer modelling for high-quant would make use of kAcTable[]
    // more explicitely.
    // Additionally, we modulate the base exponent 1/3 to accommodate for the
    // quantization susceptibility and allow denser segments to be quantized
    // more.
    const double expn = (1. - amp * enc->dqm_[i].alpha_) / 3.;
    const double c = pow(c_base, expn);
    const int q = (int)(127. * (1. - c));
    assert(expn > 0.);
    enc->dqm_[i].quant_ = clip(q, 0, 127);
  }

  // purely indicative in the bitstream (except for the 1-segment case)
  enc->base_quant_ = enc->dqm_[0].quant_;

  // fill-in values for the unused segments (required by the syntax)
  for (i = num_segments; i < NUM_MB_SEGMENTS; ++i) {
    enc->dqm_[i].quant_ = enc->base_quant_;
  }

  // uv_alpha_ is normally spread around ~60. The useful range is
  // typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  // We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  dq_uv_ac = (enc->uv_alpha_ - MID_ALPHA) * (MAX_DQ_UV - MIN_DQ_UV)
                                          / (MAX_ALPHA - MIN_ALPHA);
  // we rescale by the user-defined strength of adaptation
  dq_uv_ac = dq_uv_ac * enc->config_->sns_strength / 100;
  // and make it safe.
  dq_uv_ac = clip(dq_uv_ac, MIN_DQ_UV, MAX_DQ_UV);
  // We also boost the dc-uv-quant a little, based on sns-strength, since
  // U/V channels are quite more reactive to high quants (flat DC-blocks
  // tend to appear, and are displeasant).
  dq_uv_dc = -4 * enc->config_->sns_strength / 100;
  dq_uv_dc = clip(dq_uv_dc, -15, 15);   // 4bit-signed max allowed

  enc->dq_y1_dc_ = 0;       // TODO(skal): dq-lum
  enc->dq_y2_dc_ = 0;
  enc->dq_y2_ac_ = 0;
  enc->dq_uv_dc_ = dq_uv_dc;
  enc->dq_uv_ac_ = dq_uv_ac;

  SetupMatrices(enc);

  SetupFilterStrength(enc);   // initialize segments' filtering, eventually
}
Exemple #13
0
void VP8SetSegmentParams(VP8Encoder* const enc, float quality) {
  int i;
  int dq_uv_ac, dq_uv_dc;
  const int num_segments = enc->segment_hdr_.num_segments_;
  const double amp = SNS_TO_DQ * enc->config_->sns_strength / 100. / 128.;
  const double Q = quality / 100.;
  const double c_base = enc->config_->emulate_jpeg_size ?
      QualityToJPEGCompression(Q, enc->alpha_ / 255.) :
      QualityToCompression(Q);
  for (i = 0; i < num_segments; ++i) {
    // We modulate the base coefficient to accommodate for the quantization
    // susceptibility and allow denser segments to be quantized more.
    const double expn = 1. - amp * enc->dqm_[i].alpha_;
    const double c = pow(c_base, expn);
    const int q = (int)(127. * (1. - c));
    assert(expn > 0.);
    enc->dqm_[i].quant_ = clip(q, 0, 127);
  }

  // purely indicative in the bitstream (except for the 1-segment case)
  enc->base_quant_ = enc->dqm_[0].quant_;

  // fill-in values for the unused segments (required by the syntax)
  for (i = num_segments; i < NUM_MB_SEGMENTS; ++i) {
    enc->dqm_[i].quant_ = enc->base_quant_;
  }

  // uv_alpha_ is normally spread around ~60. The useful range is
  // typically ~30 (quite bad) to ~100 (ok to decimate UV more).
  // We map it to the safe maximal range of MAX/MIN_DQ_UV for dq_uv.
  dq_uv_ac = (enc->uv_alpha_ - MID_ALPHA) * (MAX_DQ_UV - MIN_DQ_UV)
                                          / (MAX_ALPHA - MIN_ALPHA);
  // we rescale by the user-defined strength of adaptation
  dq_uv_ac = dq_uv_ac * enc->config_->sns_strength / 100;
  // and make it safe.
  dq_uv_ac = clip(dq_uv_ac, MIN_DQ_UV, MAX_DQ_UV);
  // We also boost the dc-uv-quant a little, based on sns-strength, since
  // U/V channels are quite more reactive to high quants (flat DC-blocks
  // tend to appear, and are displeasant).
  dq_uv_dc = -4 * enc->config_->sns_strength / 100;
  dq_uv_dc = clip(dq_uv_dc, -15, 15);   // 4bit-signed max allowed

  enc->dq_y1_dc_ = 0;       // TODO(skal): dq-lum
  enc->dq_y2_dc_ = 0;
  enc->dq_y2_ac_ = 0;
  enc->dq_uv_dc_ = dq_uv_dc;
  enc->dq_uv_ac_ = dq_uv_ac;

  SetupFilterStrength(enc);   // initialize segments' filtering, eventually

  if (num_segments > 1) SimplifySegments(enc);

  SetupMatrices(enc);         // finalize quantization matrices
}
void CXModel::SetupMatrices(stD3DFrameEx *inFrame,
                            LPD3DXMATRIX parentMatirx)
{
   if(!m_device) return;

   stD3DContainerEx *containerEx = (stD3DContainerEx*)inFrame->pMeshContainer;

   if(containerEx)
      {
         if(!m_currentContainer)
            m_currentContainer = containerEx;

         if(containerEx->pSkinInfo && containerEx->MeshData.pMesh)
            {
               D3DVERTEXELEMENT9 Declaration[MAX_FVF_DECL_SIZE];

               if(FAILED(containerEx->MeshData.pMesh->GetDeclaration(Declaration)))
                  return;

               containerEx->MeshData.pMesh->CloneMesh(D3DXMESH_MANAGED,
                  Declaration, m_device, &containerEx->originalMesh);

               m_maxBones = max(m_maxBones, containerEx->pSkinInfo->GetNumBones());

               for(unsigned int i = 0; i < containerEx->pSkinInfo->GetNumBones(); i++)
                  {   
                     stD3DFrameEx *temp = (stD3DFrameEx*)D3DXFrameFind(m_root,
                        containerEx->pSkinInfo->GetBoneName(i));

                     containerEx->boneMatrices[i] = &temp->finalMatrix;
                  }

            }
      }

   if(inFrame->pFrameSibling)
      SetupMatrices((stD3DFrameEx*)inFrame->pFrameSibling, parentMatirx);

   if(inFrame->pFrameFirstChild)
      SetupMatrices((stD3DFrameEx*)inFrame->pFrameFirstChild, &inFrame->finalMatrix);
}
VOID Render( )
{
	RECT rt1, rt2;
	D3DXMATRIX matWorld, matScale, matRotateZ, matTrans;

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

	if ( SUCCEEDED( g_pD3DDevice->BeginScene( ) ) )
	{

		SetupMatrices( );
		SetRect( &rt1, 10, 10, 0, 0 );
		if (!g_Method)
		{
			g_pFont->DrawTextW( NULL, L"AABB 충돌(left click으로 방법 변경)", -1, &rt1, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) );
		}
		else
		{
			g_pFont->DrawTextW( NULL, L"OBB 충돌(left click으로 방법 변경)", -1, &rt1, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) );
		}
		


		g_pD3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );


		for ( DWORD i = 0; i < sizeof( g_Box ) / sizeof( g_Box[1] ); ++i )
		{
			D3DXMatrixTranslation( &matTrans, g_Box[i].CenterPos.x, g_Box[i].CenterPos.y, g_Box[i].CenterPos.z );
			D3DXMatrixScaling( &matScale, g_Box[i].BoxScaling, g_Box[i].BoxScaling, g_Box[i].BoxScaling );
			D3DXMatrixRotationZ( &matRotateZ, g_Box[i].BoxRotateZ );
			matWorld = matRotateZ * matScale * matTrans;

			g_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld );

			g_pMesh->DrawSubset( 0 );
		}
		SetRect( &rt2, 10, 30, 0, 0 );

		if ( g_CheckFlag )
		{
			g_pFont->DrawTextW( NULL, L"박았음!!", -1, &rt2, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) );
		}
		else
		{
			g_pFont->DrawTextW( NULL, L"아직 멀었음!!", -1, &rt2, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) );
		}

		g_pD3DDevice->EndScene( );
	}

	g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
}
HRESULT WINAPI D3DProxyDeviceMono::EndScene()
{
    // delay to avoid crashing on start
    static int initDelay = 120;
    initDelay--;

    if(!stereoView->initialized && initDelay < 0)
    {
        stereoView->Init(m_pDevice);
        SetupMatrices();
    }

    return D3DProxyDevice::EndScene();
}
//-----------------------------------------------------------------------------
// 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, 0 ), 1.0f, 0 );

	// Begin the scene
	if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		// Setup the world, view, and projection matrices
		SetupMatrices();

		SetupLights();

		// 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 );
		}
		D3DXMATRIXA16 mat;
		D3DXMatrixTranslation( &mat, 1,0,0 );
		g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat );
		for( DWORD i = 0; i < g_dwNumMaterials2; i++ )
		{
			// Set the material and texture for this subset
			g_pd3dDevice->SetMaterial( &g_pMeshMaterials2[i] );
			g_pd3dDevice->SetTexture( 0, g_pMeshTextures2[i] );

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

		// End the scene
		g_pd3dDevice->EndScene();
	}
	LPDIRECT3DTEXTURE9* pTemp = g_pMeshTextures;
	g_pMeshTextures = g_pMeshTextures2;
	g_pMeshTextures2 = pTemp;
	// Present the backbuffer contents to the display
	g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
VOID Render()
{
    if ( !g_pd3dDevice ) return;
    LPDIRECT3DDEVICE9 d = g_pd3dDevice;

    d->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    if ( SUCCEEDED( d->BeginScene() ) ) {
        SetupMatrices();

        d->SetStreamSource( 0, g_pVertexBuff, 0, sizeof(CUSTOMVERTEX) );
        d->SetFVF( D3DFVF_CUSTOMVERTEX );
        d->SetIndices( g_pIndexBuff ); // 인덱스 버퍼 선택
        d->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12 );
        d->EndScene();
    }
    d->Present( NULL, NULL, NULL, NULL );
}
//-----------------------------------------------------------------------------
// 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 );

	
		D3DLOCKED_RECT locked;
		if(g_pTexture->LockRect(0, &locked, NULL, /*D3DLOCK_DISCARD*/0)==D3D_OK)
		{	
			memcpy(locked.pBits, videoFrame, TEXTURE_WIDTH*TEXTURE_HEIGHT*3);
			g_pTexture->UnlockRect(0);
		}

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Setup the world, view, and projection matrices
        SetupMatrices();

        // Setup our texture. Using textures introduces the texture stage states,
        // which govern how textures get blended together (in the case of multiple
        // textures) and lighting information. In this case, we are modulating
        // (blending) our texture with the diffuse color of the vertices.
        g_pd3dDevice->SetTexture( 0, g_pTexture );
        g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_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 );

        // Render the vertex buffer contents
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof( CUSTOMVERTEX ) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
		// Draws two triangles (makes a quad that will support our drone video picture)
        g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );

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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Exemple #20
0
void Rander()
{
	Update();
	if (g_pDevice == NULL)
		return;
	SetupMatrices();
	g_pDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,D3DCOLOR_XRGB(204,138,64),1.0f,0);// 清空图形绘制区
	g_pDevice->BeginScene();

	switch (g_iGameState)
	{
	case 1:
		{
			if (g_iGameState == g_iOldState)
			{
				g_pStartUI->Rander(g_dElapsedTime);
			}
		}
		break;
	case 2:
		{
			if (g_iGameState != g_iOldState)
			{
				if (g_iOldState == 1)
				{
					g_pLoadUI->Render(g_dElapsedTime);
				}
			}
			else
			{
				g_pScene->Render();
			}
		}
		break;
	default:
		break;
	}

	g_pDevice->SetRenderState(D3DRS_ZENABLE,FALSE);
	//g_pDevice->SetRenderState(D3DRS_FOGENABLE,FALSE);
	g_pDevice->EndScene();
	g_pDevice->Present(NULL,NULL,NULL,NULL);
}
VOID Render()
{
    if( !g_pd3dDevice ) return;
    LPDIRECT3DDEVICE9 d = g_pd3dDevice;

    d->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    if( SUCCEEDED( d->BeginScene() ) ) {
        SetupLights();
        SetupMatrices();

        d->SetStreamSource( 0, g_pVertexBuff, 0, sizeof(CUSTOMVERTEX) );
        d->SetFVF( D3DFVF_CUSTOMVERTEX );
        d->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 * 50 - 2 );
        //d->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
        d->EndScene();
    }
    d->Present( NULL, NULL, NULL, NULL );
}
VOID Render()
{
	if ( NULL == g_pd3dDevice )
	{
		return;
	}

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

	if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
	{
		SetupLights();

		SetupMatrices();

		g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_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 );

		D3DXMATRIXA16 thisMatrix;

		D3DXMatrixTranslation( &thisMatrix, 0.0f, -10.0f, 30.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );
		D3DXMatrixRotationY( &thisMatrix, timeGetTime() / 1000.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );
		D3DXMatrixScaling( &thisMatrix, 1.0f, 1.2f, 1.0f );
		g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix );


		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 );
}
HRESULT ColladaLoader::Run()
{
	StartLogging();

	if(!Initialize()) {
        StopLogging();
        return -1;
    } else {
        SetupShaders();
        SetupMatrices();
        SetupLights();
        SetupGeometry();
        MainLoop();
        Terminate();
        StopLogging();
    }

	return 0;

}
	void Graphics::DrawWorld( float dt )
	{
		//Setup the world, view, and projection matrices
		SetupMatrices();

		//TODO: Draw background

		//Iterate through the link list of sprite and draw them all
		//TODO: Need Visibility to cull off screen sprites
    SpriteList.sort( std::less<Sprite*>() );
    for ( std::list<Sprite*>::iterator it = SpriteList.begin(); it != SpriteList.end(); ++it )
    {
      (*it)->Draw( pDevice, shaders_[(*it)->sIndex_].effect_ );
    }

    for ( ObjectLinkList<Text>::iterator it = TextList.begin(); it != TextList.end(); ++it )
    {
      it->Draw();
    }
	}
VOID Render()
{
    if ( !g_pd3dDevice ) return;
    LPDIRECT3DDEVICE9 d = g_pd3dDevice;

    d->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );
    
    if ( SUCCEEDED( d->BeginScene() )) {
        SetupMatrices();

        for (int i = 0; i< g_materialNums; ++i) {
            d->SetMaterial( &g_pMeshMaterials[i] );
            d->SetTexture( 0, g_pMeshTextures[i] );
            g_pMesh->DrawSubset( i );
        }

        d->EndScene();
    }
    d->Present( NULL, NULL, NULL, NULL );
}
VOID Render()
{
	g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 );

	if ( SUCCEEDED( g_pD3DDevice->BeginScene() ) )
	{
		SetupLights();

		SetupMatrices();

		g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_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 );

		//soldier
		D3DXMATRIXA16 matFirstTiger, matTrans, matRotate;
		//D3DXMatrixIdentity(&matFirstTiger);

		//g_pD3DDevice->GetTransform(D3DTS_WORLD, &matFirstTiger);
		D3DXMatrixTranslation( &matTrans, 0.f, -2.f, 0.f );
		D3DXMatrixRotationY( &matRotate, timeGetTime() / 1000.0f );
		D3DXMatrixMultiply( &matFirstTiger, &matRotate, &matTrans );
		g_pD3DDevice->SetTransform( D3DTS_WORLD, &matFirstTiger );


		for ( DWORD i = 0; i < g_dwNumMaterials; ++i )
		{
			g_pD3DDevice->SetMaterial( &g_pMeshMaterials0[i] );
			g_pD3DDevice->SetTexture( 0, g_pMeshTextures0[i] );

			g_pMesh0->DrawSubset( i );
		}

		g_pD3DDevice->EndScene();
	}

	g_pD3DDevice->Present( NULL, NULL, NULL, NULL );
	g_tick++;
}
Exemple #27
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    // Clear the backbuffer 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();

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

    // Render the vertex buffer contents
    g_pd3dDevice->SetStreamSource( 0, g_pVB, sizeof(CUSTOMVERTEX) );
    g_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
    g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 1 );

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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
int RenderMesh(LPD3DXMESH mesh,D3DMATERIAL9* pMeshMaterials,LPDIRECT3DTEXTURE9* pMeshTextures,DWORD dwNumMaterials,D3DXMATRIXA16* pMatWorld)
{
    
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
                         D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 );

    // 开始渲染 scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
       
        SetupMatrices();

      
        for( DWORD i = 0; i < dwNumMaterials; i++ )
        {
			
			//执行变换矩阵
			
			 g_pd3dDevice->SetTransform( D3DTS_WORLD, pMatWorld );
           
            g_pd3dDevice->SetMaterial( &pMeshMaterials[i] );
            g_pd3dDevice->SetTexture( 0, pMeshTextures[i] );

			mesh->DrawSubset( i );

        }
		 


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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );

	return 1;
}
HRESULT CMainFrame::Render()
{
    HRESULT hr = E_FAIL;
    CHECK_POINTER_RETURN_VALUE_IF_FAIL(m_pD3dDevice, E_POINTER);

    // Clear the backbuffer to a blue color
    DX_VERIFY(m_pD3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
        D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ));

    // Begin the scene
    DX_VERIFY(m_pD3dDevice->BeginScene());
    if( SUCCEEDED( hr ))
    {
#ifndef DRAW_FISHJAM_2D
        DX_VERIFY(SetupLights());
        DX_VERIFY(SetupMatrices());
#endif

        //通过Stream的方式绘制 vertices,先指定 Source
        DX_VERIFY(m_pD3dDevice->SetStreamSource( 0, m_pD3dVertexBuffer, 0, sizeof(FISHJAM_VERTEX)));

        //设置FVF的格式,使得D3D知道 m_pD3dVertexBuffer 中 Vertex 的格式
        DX_VERIFY(m_pD3dDevice->SetFVF( D3DFVF_FISHJAM_VERTEX ));
        //输出

        //DX_VERIFY(m_pD3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1));  //输出三角形
        DX_VERIFY(m_pD3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2*50-2)); //输出圆柱
        
                                               
        // End the scene
        DX_VERIFY(m_pD3dDevice->EndScene());
    }

    // Present the back buffer contents to the display
    DX_VERIFY(m_pD3dDevice->Present( NULL, NULL, NULL, NULL ));

    return hr;
}
HRESULT D3D9RenderImpl::CreateResources()
{
    m_pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE);
    m_pDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE);
    m_pDevice->SetRenderState( D3DRS_LIGHTING, FALSE);
    m_pDevice->SetRenderState( D3DRS_DITHERENABLE, TRUE);

    m_pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
    m_pDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    m_pDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

    m_pDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
    m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
    m_pDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_SPECULAR);

    m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
    m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    m_pDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);

    HR(CreateRenderTarget(m_presentParams.BackBufferWidth, m_presentParams.BackBufferHeight));
    
    return SetupMatrices(m_presentParams.BackBufferWidth, m_presentParams.BackBufferHeight);
}