Ejemplo n.º 1
0
int main()
{
	ifstream stream, wavStream;
	MSG message;
	Window window({ 1280, 720 });
	
	if (window.Create())
	{
		Renderer &renderer = window.GetRenderer();
		//WAV wav;
		//wav.ReadData(&wavStream, L"F:\\assets\\live.wav");
		//WaveOut waveOut;
		//waveOut.Write(wav.GetSelected(), wav.GetSelectedLength(), wav.GetPCMFormat());
		
		Texture texture1;
		BMP::Automatic(stream, L"F:\\assets\\test1.bmp", texture1);
		Texture texture2;
		BMP::Automatic(stream, L"F:\\assets\\c.bmp", texture2);
		Texture texture3;
		BMP::Automatic(stream, L"F:\\assets\\button.bmp", texture3);

		Character *c = (Character *)window.GetEntity(window.AppendEntity(new Character(window.GetRenderer())));
		
		c->SwitchDisplayMode(CharacterDisplayMode::Normal);
		c->SwitchFX(CharacterFX::Normal);
		c->BindTexture(&texture2);
		c->SetPosition({ -50, 50 });
		c->SetSize({ 40.0f, 80.0f });
		
		Button *b = (Button *)window.GetEntity(window.AppendEntity(new Button(window.GetRenderer())));

		b->BindTexture(&texture3);
		b->SetPosition({ 0.0f, 30.0f });
		b->SetSize({ 20.0f, 10.0f });
		
		while (true)
		{
			glClear(GL_COLOR_BUFFER_BIT);

			if (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
			{
				if (message.message == WM_QUIT)
					return 0;
				else
				{
					TranslateMessage(&message);
					DispatchMessage(&message);
				}
			}
			window.DrawTestImage();
	
			renderer.DrawBackGroundImage(texture1.Index);
			c->Render();
			b->Render();

			glFlush();
			window.Flush();
		}
	}
}
Ejemplo n.º 2
0
int main(int argc, char *argv[])
{
	Init();

	Character *snake = new Snake("snake2.bmp", 20, 20);
	Character *dot = new Dot("dot.bmp", 20, 20);

	bool quit = false;

	while (!quit)
	{
		while (SDL_PollEvent(&event) != 0)
		{
			if (event.type == SDL_QUIT) {
				quit = true;
			}
		}
		SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);		// select colour for drawing
		SDL_RenderClear(renderer);									// clear entire screen to our selected colour

		snake->m_Move();  // (*snake).Move();
		dot->Render();
		OutOfScreen(*snake);
		collisionDetection(*snake, *dot);

		if (collisionDetection(*snake, *dot)) {						// checks IF TRUE
			dot->NewDot();
			dot->Render();
		}
		

		SDL_RenderPresent(renderer);								/* everything before this was drawn behind the scenes this actually
																	puts the colour on screen for us */
		SDL_Delay(70);												// gives us time to see the screen
	}

	Close();

	return 0;
}
Ejemplo n.º 3
0
void TriPickDemo::drawScene()
{

	HR(g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0));

	HR(g_pDevice->BeginScene());

	//rendering characters
	{
		ID3DXEffect* pMAEffect = m_pCharacter->GetEffect();

		if (pMAEffect)
		{
			pMAEffect->SetMatrix("g_mViewProj", &(g_Camera->viewProj()));
		}
		//set lighting
		D3DXVECTOR4 v(m_Light.dirW.x, m_Light.dirW.y, m_Light.dirW.z, 1.0f);
		if (pMAEffect)
		{
			pMAEffect->SetVector("lhtDir", &v);
		}
		SAFE_RELEASE(pMAEffect);
		/*/ compute reorientation matrix based on default orientation and bounding radius
		D3DXMATRIX mx, Orientation;
		//float fScale = 1.f / g_Character.GetBoundingRadius() / 7.f;
		//D3DXMatrixScaling(&mx, fScale, fScale, fScale);
		D3DXMatrixScaling(&mx, 1.0f, 1.0f, 1.0f);
		Orientation = mx;
		//D3DXMatrixRotationX(&mx, -D3DX_PI / 2.0f);
		D3DXMatrixRotationX(&mx, 0.0f);
		D3DXMatrixMultiply(&Orientation, &Orientation, &mx);
		//D3DXMatrixRotationY(&mx, D3DX_PI);
		D3DXMatrixRotationY(&mx, 0.0f);
		D3DXMatrixMultiply(&Orientation, &Orientation, &mx);

		D3DXMATRIX mxWorld;

		// compute world matrix based on pos/face
		D3DXMatrixRotationY(&mxWorld, 0.0f);
		D3DXMatrixTranslation(&mx, 0.0f, 0.0f, 0.0f);
		D3DXMatrixMultiply(&mxWorld, &mxWorld, &mx);
		D3DXMatrixMultiply(&mxWorld, &Orientation, &mxWorld);*/
		m_pCharacter->SetPose(m_matWorld);
		//check seclection
		D3DXVECTOR3  mouseMV;
		if (gDInput->mouseButtonDown(0))
		{
			if (L_Hand->isPick == false)
				L_Hand->isPick = checkBonePick(L_Hand->pCylinder, L_Hand->curWorld);

			if (R_Hand->isPick == false)
				R_Hand->isPick = checkBonePick(R_Hand->pCylinder, R_Hand->curWorld);

			if (L_Leg->isPick == false)
				L_Leg->isPick = checkBonePick(L_Leg->pCylinder, L_Leg->curWorld);

			if (R_Leg->isPick == false)
				R_Leg->isPick = checkBonePick(R_Leg->pCylinder, R_Leg->curWorld);
			//get move vector
			if (L_Hand->isPick)
			{
				mouseMV = getMouseMoveVector(1.0f);
				m_pIK->addLHMove(mouseMV);
			}
			else
				if (R_Hand->isPick)
				{
					mouseMV = getMouseMoveVector(1.0f);
					m_pIK->addRHMove(mouseMV);
				}
				else
					if (L_Leg->isPick)
					{
						mouseMV = getMouseMoveVector(1.0f);
						m_pIK->addLLMove(mouseMV);
					}
					else
						if (R_Leg->isPick)
						{
							mouseMV = getMouseMoveVector(1.0f);
							m_pIK->addRLMove(mouseMV);
						}
		}
		else
		{
			L_Hand->isPick = false;
			R_Hand->isPick = false;
			L_Leg->isPick = false;
			R_Leg->isPick = false;
		}
		// wireframe
		//g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
		//Update IK
		if (m_pIK)
		{
			m_pIK->UpdateHeadIK();
			m_pIK->UpdateIK();
		}
		//m_pCharacter->DrawBoneCylinder(m_pCharacter->getPBone(), NULL, m_matWorld);
		m_pCharacter->Render(NULL);
	}

	HR(g_pDevice->EndScene());

	HR(g_pDevice->Present(0, 0, 0, 0));
}
//--------------------------------------------------------------------------------------
// Render the scene using the D3D11 device
//--------------------------------------------------------------------------------------
void CALLBACK OnD3D11FrameRender( ID3D11Device* pd3dDevice, ID3D11DeviceContext* pd3dImmediateContext, double fTime,
                                 float fElapsedTime, void* pUserContext )
{
    if (g_bPresentTimerStarted)
    {
        TIMER_End(); // Present
        // Reset the timer at start of frame
        TIMER_Reset();
        g_bPresentTimerStarted = false;
    }


    // If the settings dialog is being shown, then render it instead of rendering the app's scene
    if( g_SettingsDlg.IsActive() )
    {
        g_SettingsDlg.OnRender( fElapsedTime );
        return;
    }       
	TIMER_Begin(0, L"Total");

	g_Context.m_Affinity.SetRenderGpuMask(GPUMASK_BOTH);

    DXUTSetupD3D11Views(pd3dImmediateContext);

    // Switch off alpha blending
    float BlendFactor[1] = { 0.0f };
	pd3dImmediateContext->OMSetBlendState(g_Context.m_pOpaqueState, BlendFactor, 0xffffffff);
    pd3dImmediateContext->OMSetDepthStencilState(g_Context.m_pDepthStateOpaque, 0);
    

    // Render objects here...
	if (g_Context.m_ShaderCache.ShadersReady())
	{
		float ClearColor[4] = { 0.0f, 0.0f, 0.3f, 1.0f }; // red,green,blue,alpha

		// RenderToDirectDisplay
		ID3D11RenderTargetView* pRtv = nullptr;
		pd3dImmediateContext->OMGetRenderTargets(1, &pRtv, nullptr);
		pd3dImmediateContext->ClearRenderTargetView(pRtv, ClearColor);
		pRtv->Release();


		auto pDSV = DXUTGetD3D11DepthStencilView();
		if (pDSV != NULL)
		{
            pd3dImmediateContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0, 0);
        }

		g_Character.Time();

//		g_Context.m_Affinity.SetRenderGpuMask(GPUMASK_BOTH);
		g_Background.Render(pd3dImmediateContext, g_Context.m_fbWidth, g_Context.m_fbHeight);

		g_Context.m_Affinity.SetRenderGpuMask(GPUMASK_BOTH);
		pDSV = DXUTGetD3D11DepthStencilView();
		if (pDSV != NULL)
		{
			pd3dImmediateContext->ClearDepthStencilView(pDSV, D3D11_CLEAR_DEPTH, 1.0, 0);
		}

		if (g_HUD.m_GUI.GetCheckBox(IDC_CHECKBOX_DRAW_FOBLINMESH)->GetChecked())
		{
			g_Character.Render(pd3dImmediateContext, g_Context.m_fbWidth, g_Context.m_fbHeight);
		}
		TIMER_Begin(0, L"Transfer");
		g_Context.m_Affinity.TransferRightEye(pd3dImmediateContext, g_Context.m_fbWidth, g_Context.m_fbHeight);
		TIMER_End() // Transfer
	}