Exemplo n.º 1
0
//===============================================================
// DrawAllSection
// Info : 씬의 모든 부분을 그린다.
VOID CLobbyUI::DrawLobbySection(VOID)
{
	for (int x = 0; x <= MAX_XPOS; x += 2)
	{
		for (int y = 0; y <= MAX_YPOS; y++)
		{
			DrawUI(x, y);
		}
	}
}
Exemplo n.º 2
0
int GameLoop()
{
	Timer Timer;
	int Frame = 0;

	bool quit = false;
	SDL_Event PollEvent;
	while(!quit)
	{
		int frameTicks = Timer.start();

		while(SDL_PollEvent(&PollEvent))
		{
			if(PollEvent.type == SDL_QUIT)
			{
				quit = true;
				break;
			}
			if(HandleInput(PollEvent, frameTicks) == -1)
			{
				quit = true;
				break;
			}			
		}
		if(quit == true)
			break;

		Actions(frameTicks);
		
		SDL_FillRect(screen, &(screen->clip_rect), backgroundColor);

		DrawCamera();
		DrawUI();

		if(SDL_Flip(screen) == -1)
			return 1;

        //Cap the frame rate
        if( Timer.get_ticks() < 1000 / MAX_FPS )
        {
			int delay =  ( 1000 / MAX_FPS ) - Timer.get_ticks();
            SDL_Delay(delay);
        }

		Frame++;
		if(Frame % MAX_FPS == 0)
			Frame = 0;
	}

	return 0;
}
Exemplo n.º 3
0
void Draw()
{
	int i;
	ScreenClear();
	SetColor(11, 0);

	DrawUI();
	SetColor(9, 0);
	ScreenPrint(g_nCharXPos, g_nCharYPos, "!!");
	SetColor(12, 0);
	for (i = 0; i < 3; i++){
		ScreenPrint(g_nEnemyXPos[i], g_nEnemyYPos[i], "00");
	}
	SetColor(14, 0);
	ScreenPrint(g_nCoinXPos, g_nCoinYPos, "$");
	for (i = 0; i < 5; i++){
		if (g_nBulletFalg[i] == TRUE)
		{
			SetColor(14, 0);
			ScreenPrint(g_nBulletXPos[i], g_nBulletYPos[i], "||");
		}
	}
	if (g_nItemKeyFlag == TRUE){
		SetColor(13, 0);
		ScreenPrint(g_nItemXPos, g_nItemYPos, "+");
	}

	sprintf(strTemp, "%d", g_nLife);
	sprintf(strTemp2, "%d", g_nTimeElapsed);
	sprintf(strTemp3, "%d", g_nKills);

	SetColor(15, 0);
	ScreenPrint(0, 22, "Life: ");
	ScreenPrint(6, 22, strTemp);
	ScreenPrint(0, 24, "Score: ");
	ScreenPrint(7, 24, strTemp2);
	ScreenPrint(0, 23, "Kills: ");
	ScreenPrint(7, 23, strTemp3);

	ScreenFlipping();
}
Exemplo n.º 4
0
void C_Mod::loop()
{
    continuer = true;
    click = keyboard = false;
    bool clickOnUI = false;
    sf::Clock camTimer;
    float previousX = 0, previousY = 0;

    sf::String str_fps;
    int compt_fps = 0;
    sf::Clock timer_fps;
    str_fps.SetScale(0.4f, 0.4f);
    str_fps.SetColor(sf::Color::White);
    str_fps.SetPosition(10, 10);

    _screen->PreserveOpenGLStates(true);

    while(continuer)
    {
        while(_screen->GetEvent(_event))
        {
///EVENT
            if(_event.Type == sf::Event::Closed)
                continuer = false;
            else if(_event.Type == sf::Event::MouseButtonReleased && click)
            {
                click = false;

                float xxx = _screen->GetInput().GetMouseX();
                float yyy = _screen->GetInput().GetMouseY();
                for(unsigned int i=0;i<_widget.size();i++)
                    _widget[i]->clicked(xxx, yyy);

                MouseReleased();
            }
            else if(_event.Type == sf::Event::MouseButtonPressed)
            {
                click = true;
                clickOnUI = false;

                previousX = _screen->GetInput().GetMouseX();
                previousY = _screen->GetInput().GetMouseY();
                for(unsigned int i=0;i<_widget.size();i++)
                {
                    if(_widget[i]->mouseOver(previousX, previousY))
                    {
                        clickOnUI = true;
                        break;
                    }
                }

                if(!clickOnUI)
                    _cam->SetMousePosition(previousX, previousY);

                MousePressed();
            }
            else if(_event.Type == sf::Event::MouseMoved)
            {
                _cam->OnMouseMotion(_screen->GetInput().GetMouseX(), _screen->GetInput().GetMouseY());
                _screen->SetCursorPosition(_screen->GetWidth()/2, _screen->GetHeight()/2);
                MouseMoved();
            }
            else if(_event.Type == sf::Event::MouseWheelMoved)
            {
                MouseWheel();
                _event.MouseWheel.Delta = 0;
            }
            else if(_event.Type == sf::Event::KeyPressed)
            {
                bool wigdetHasFocus = false;

                for(unsigned int i=0;i<_widget.size();i++)
                {
                    if(_widget[i]->injectKey(_event.Key.Code, true))
                    {
                        wigdetHasFocus = true;
                        break;
                    }
                }

                if(!wigdetHasFocus)
                {
                    keyboard = true;
                    _cam->OnKeyboard(_event);
                    KeyPressed();
                }
            }
            else if(_event.Type == sf::Event::KeyReleased)
            {
                for(unsigned int i=0;i<_widget.size();i++)
                    _widget[i]->injectKey(_event.Key.Code, false);
                //if(keyboard)
                {
                    keyboard = false;
                    _cam->OnKeyboard(_event);
                    KeyReleased();
                }
            }
        }
        glDisable(GL_LIGHTING);
        _cam->animate(int(camTimer.GetElapsedTime()*10000));
        camTimer.Reset();

        TimerManagement();
///DRAW
        _screen->SetActive();
        if(click && !clickOnUI)
            _screen->SetCursorPosition(previousX, previousY); //_screen->GetWidth()/2, _screen->GetHeight()/2);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

        glViewport(0, 0, _screen->GetWidth(), _screen->GetHeight());
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(70, float(_screen->GetWidth()) / float(_screen->GetHeight()), 0.1f, 5000.0f);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        _skydome.Draw();

        _cam->look();

        glPushMatrix();
        Draw();
        glPopMatrix();

        DrawUI();

        if(timer_fps.GetElapsedTime() > 1.0f)
        {
            str_fps.SetText("FPS : "+IntToString(compt_fps));
            compt_fps = 0;
            timer_fps.Reset();
        }
        compt_fps++;
        _screen->Draw(str_fps);

        _screen->Display();
    }
}
Exemplo n.º 5
0
void INTERFACEOBJECT::Render(BUFFER &pBuffer)
{
	//draw object
	DrawUI(pBuffer, pic, pos.x, pos.y, size.x, size.y, 0, 0, imagesize.x, imagesize.y);
}
Exemplo n.º 6
0
Arquivo: snake.cpp Projeto: qhw/Snake
//
//  FUNCTION: WndProc(HWND, unsigned, WORD, LONG)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_COMMAND	- process the application menu
//  WM_PAINT	- Paint the main window
//  WM_DESTROY	- post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	int wmId, wmEvent;
	PAINTSTRUCT ps;
	HDC hdc,hMemDC;
	TCHAR szHello[MAX_LOADSTRING];
	LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING);
	
	switch (message) 
	{
		case WM_COMMAND:
			wmId    = LOWORD(wParam); 
			wmEvent = HIWORD(wParam); 
			// Parse the menu selections:
			switch (wmId)
			{
				case IDM_ABOUT:
				   DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About);
				   break;
				case IDM_EXIT:
				   DestroyWindow(hWnd);
				   break;
				case IDM_UP:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_UP,0);
					break;
				case IDM_LEFT:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_LEFT,0);
					break;
				case IDM_RIGHT:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_RIGHT,0);
					break;
				case IDM_DOWN:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_DOWN,0);
					break;
				case IDM_START_PAUSE:
					SendMessage(hWnd,WM_KEYDOWN,(WPARAM)VK_SPACE,0);
					break;
				default:
				   return DefWindowProc(hWnd, message, wParam, lParam);
			}
			break;
		case WM_CREATE:
			m = 20;
			n = 15;
			for(i = 0; i < n_body; i++)
			{
				Position[i].x = m-i;
				Position[i].y = n;
				Matrix[Position[i].x][Position[i].y] = 1;
			}
			CreateFood();
			CreateUI(hWnd);
			SetTimer(hWnd,100,speed,NULL);
				break;
		case WM_KEYDOWN:
			switch(wParam)
			{
			case VK_UP:
				//KillTimer(hWnd,100);
				if(direction != 2 && n>0 && CheckOver(hWnd,m,n-1))
				{
					
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					n--;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].y = n;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}
					CreateFood();
					direction = 0;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_LEFT:
			//	KillTimer(hWnd,100);
				if(direction != 1 && m>0 && CheckOver(hWnd,m-1,n))
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					m--;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].x = m;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}	
					CreateFood();
					direction = 3;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_RIGHT:
				//KillTimer(hWnd,100);
				if(direction != 3 && m<39 && CheckOver(hWnd,m+1,n))
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					m++;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].x = m;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}	
					CreateFood();
					direction = 1;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			case VK_SPACE:
				if(start_or_pause)
				{
					KillTimer(hWnd,100);
					start_or_pause = false;
				}else
				{
					SetTimer(hWnd,100,speed,NULL);
					start_or_pause = true;
				}
				break;
			case VK_DOWN:
			//	KillTimer(hWnd,100);
				if(direction != 0 && n<31 && CheckOver(hWnd,m,n+1) )
				{
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 0;
					}
					n++;
					CheckFood();
					for(i = n_body-1; i > 0; i--)
					{
						Position[i] = Position[i-1];
					}
					Position[0].y = n;
					for(i = 0; i < n_body; i++)
					{
						Matrix[Position[i].x][Position[i].y] = 1;
					}
					CreateFood();
					direction = 2;
					DrawUI(hWnd);
				}
				else
					MessageBeep(0);
			//	SetTimer(hWnd,100,500,NULL);
				break;
			}
			break;
		case WM_PAINT:
			hdc = BeginPaint(hWnd, &ps);
			// TODO: Add any drawing code here...
			
			//GetClientRect(hWnd, &rt);
			hbr = (HBRUSH)GetStockObject(BLACK_BRUSH);
			hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
			hMemDC  =  CreateCompatibleDC(hdc);   
			hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);

			//Matrix[10][10] = 1;
			
			for(i = 0; i < 40; i++)
				for(j =0; j <32; j++)
				{
						rt.left = i * 16;
					rt.top = 24 + j *16;
					switch(Matrix[i][j])
					{
						case 0:
							{
								rt.right = rt.left + 16;
								rt.bottom = rt.top + 16 ;
								FillRect(hdc,&rt,hbr);
							}
							break;
						case 1:
							{
								hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
								hMemDC  =  CreateCompatibleDC(hdc);   
								hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);
								BitBlt(hdc,rt.left,rt.top,16,16,hMemDC,0,0,SRCCOPY);
								SelectObject(hMemDC, hBmpOld);   
								DeleteObject(hBmp);   
								DeleteObject(hMemDC); 
							}
							break;
						case 2:
							{
								hBmp  =   LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP2));
								hMemDC  =  CreateCompatibleDC(hdc);   
								hBmpOld  =   (HBITMAP)SelectObject(hMemDC,hBmp);
								BitBlt(hdc,rt.left,rt.top,16,16,hMemDC,0,0,SRCCOPY);
								SelectObject(hMemDC, hBmpOld);   
								DeleteObject(hBmp);   
								DeleteObject(hMemDC); 
							}
							break;
					}
				}
			SelectObject(hMemDC, hBmpOld);   
			DeleteObject(hBmp);   
			DeleteObject(hMemDC); 
			EndPaint(hWnd, &ps);
			break;
		case WM_TIMER:
			//KillTimer(hWnd,100);
			switch(direction)
			{
			case 0://UP
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(n>0)
				{
					n--;
				}
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].y = n;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 1://RIGHT
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(m<39)
					m++;
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].x = m;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 2://DOWN
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(n<31)
				  n++;
				else
				{
				//	MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false ;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}	
				Position[0].y = n;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			case 3://LEFT
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 0;
				}
				if(m>0)
					m--;
				else
				{
					//MessageBox(NULL,"Game Over!",NULL,NULL);
					KillTimer(hWnd,100);
					gameover = false;
				}
				CheckFood();
				for(i = n_body-1; i > 0; i--)
				{
					Position[i] = Position[i-1];
				}
				Position[0].x = m;
				for(i = 0; i < n_body; i++)
				{
					Matrix[Position[i].x][Position[i].y] = 1;
				}
				CreateFood();
				DrawUI(hWnd);
				break;
			}
			//SetTimer(hWnd,100,500,NULL);
			break;
		case WM_DESTROY:
			PostQuitMessage(0);
			break;
		default:
			return DefWindowProc(hWnd, message, wParam, lParam);
   }
   return 0;
}
Exemplo n.º 7
0
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
    static TCHAR szAppName[] = TEXT("SampleSRS");
    static int xBlock, yBlock;
    static HINSTANCE hInstance;
    static RECT rect_time1, rect_time2, rect_bk;
    static HBRUSH hBrushRed;

    SetRect(&rect_time1, PLAYER1_TIME_X1 - 10, PLAYER1_TIME_Y1 - 10, PLAYER1_TIME_X2, PLAYER1_TIME_Y2);
    SetRect(&rect_time2, PLAYER2_TIME_X1, PLAYER2_TIME_Y1 - 10, PLAYER2_TIME_X2 + 10, PLAYER2_TIME_Y2 - 10);
    SetRect(&rect_bk, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);

    switch(msg) {
    case WM_CREATE:
        hInstance = ((LPCREATESTRUCT)lParam)->hInstance;
        DrawUI(hwnd, &lParam, hInstance);

        /* Load Image (Background && Chessboard) */
        LoadRc(hInstance);

        hBrushRed = CreateSolidBrush(RGB(255, 0, 0));

        MessageBox(hwnd, "Load Resource Successfully", "Info", MB_OK);
        break;
    case WM_SIZE:
        xBlock = (BOARD_X2 - BOARD_X1) / 3;
        yBlock = (BOARD_Y2 - BOARD_Y1) / 3;
        break;
    case WM_PAINT:
        InitRc(hwnd);
        break;
    case WM_LBUTTONDOWN:
        /* */
        break;
    case WM_TIMER:
        if (is_pause == FALSE) {
            if (n_chess & 1) {
                InvalidateRect(hwnd, &rect_time2, TRUE);
                DrawTime(hwnd, hBrushRed);
            } else {
                InvalidateRect(hwnd, &rect_time1, TRUE);
                DrawTime(hwnd, hBrushRed);
            }
        }
        break;
    case WM_COMMAND:
        log_to_text("Button Pressed: %d\n", LOWORD(wParam));

        if (LOWORD(wParam) == BTN_PLAYER1_RECORD) { /* Speech Recogniton for player 1*/
            player1_or_player2 = PLAYER1;
            ControlRecord(hwnd, hInstance, PLAYER1);

        } else if (LOWORD(wParam) == BTN_PLAYER2_RECORD) { /* Speech Recogniton for player 2*/
            player1_or_player2 = PLAYER2;
            ControlRecord(hwnd, hInstance, PLAYER2);

        } else if (LOWORD(wParam) == BTN_RESET) { /* Reset Button */
            InitGame(hwnd);

        } else if (LOWORD(wParam) == BTN_PAUSE) {  /* Pause Button */
            if (is_pause) {
                SetWindowText(GetDlgItem(hwnd, BTN_PAUSE), S_PAUSE);
            } else {
                SetWindowText(GetDlgItem(hwnd, BTN_PAUSE), S_CONTINUE);
            } 
            is_pause = !is_pause;

        } else if (LOWORD(wParam) == BTN_REDO) { /* Redo Button */
            back(hwnd, hInstance);
            GameCon();
        } else if (LOWORD(wParam) == BTN_EXIT) { /* Exit Button */
            if (IDYES == AskConfirmation(hwnd)) {
                DestroyWindow(hwnd) ;
            }
        }
        break;
    case WM_DESTROY:
        KillTimer(hwnd, ID1_TIMER);
		KillTimer(hwnd, ID2_TIMER);
        DeleteObject(hBkBitmap);
        DeleteObject(hBdBitmap);
        PostQuitMessage(0);
        break;
    }

    return DefWindowProc(hwnd, msg, wParam, lParam);
}
Exemplo n.º 8
0
///////////////////////////////////////////////////////////////////////////////////////////////////
/// CelShadeApp::CelShadeD3D
///
/// @brief
///     Render a cel-shading demo using Direct3D
/// @return
///     N/A
///////////////////////////////////////////////////////////////////////////////////////////////////
void CelShadeApp::CelShadeD3D()
{
    ID3D11DeviceContext* pContext = m_pDxData->pD3D11Context;
    ID3D11Device* pDevice = m_pDxData->pD3D11Device;

    D3DX11_IMAGE_LOAD_INFO imageLoadInfo;
    memset( &imageLoadInfo, 0, sizeof(D3DX11_IMAGE_LOAD_INFO) );
    imageLoadInfo.BindFlags = D3D11_BIND_SHADER_RESOURCE;
    imageLoadInfo.Format = DXGI_FORMAT_R8G8B8A8_UNORM;

    DxTextureCreateInfo shadeTexInfo;
    memset(&shadeTexInfo, 0, sizeof(DxTextureCreateInfo));
    shadeTexInfo.flags.RenderTarget = TRUE;
    shadeTexInfo.flags.ShaderInput = TRUE;
    shadeTexInfo.format = DXGI_FORMAT_R8G8B8A8_UNORM;
    shadeTexInfo.width = m_screenWidth;
    shadeTexInfo.height = m_screenHeight;
    DxTexture* pShadeTex = DxTexture::Create(pDevice, &shadeTexInfo);

    DxTextureCreateInfo edgeTexInfo;
    memset(&edgeTexInfo, 0, sizeof(DxTextureCreateInfo));
    edgeTexInfo.flags.RenderTarget = TRUE;
    edgeTexInfo.flags.ShaderInput = TRUE;
    edgeTexInfo.format = DXGI_FORMAT_R8G8B8A8_UNORM;
    edgeTexInfo.width = m_screenWidth;
    edgeTexInfo.height = m_screenHeight;
    DxTexture* pEdgeTex = DxTexture::Create(pDevice, &edgeTexInfo);

    // Samplers  /////////////////////////////////////////////////////////////////////////////

    // SamplerState PointSampler : register(s0);

    D3D11_SAMPLER_DESC pointSamplerDesc;
    memset(&pointSamplerDesc, 0, sizeof(D3D11_SAMPLER_DESC));
    pointSamplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT;
    pointSamplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    pointSamplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    pointSamplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP;
    pointSamplerDesc.MinLOD = -FLT_MAX;
    pointSamplerDesc.MaxLOD = FLT_MAX;
    pointSamplerDesc.MipLODBias = 0.0f;
    pointSamplerDesc.MaxAnisotropy = 16;

    ID3D11SamplerState* pPointSampler = NULL;
    pDevice->CreateSamplerState(&pointSamplerDesc, &pPointSampler);

    //
    UINT numVertices = 0, numIndices = 0;
    VertexPTN* pVB = NULL;
    UINT* pIB = NULL;
    ImportPly("Content/dragon_vrip_res3.ply", numVertices, &pVB, numIndices, &pIB);
    //ImportPly("Content/bun_zipper_res4.ply", numVertices, &pVB, numIndices, &pIB);
    DxMeshCreateInfo meshCreateInfo = {0};
    meshCreateInfo.indexCount = numIndices;
    meshCreateInfo.pIndexArray = pIB;
    meshCreateInfo.indexFormat = DXGI_FORMAT_R32_UINT;
    meshCreateInfo.pVertexArray = pVB;
    meshCreateInfo.vertexCount = numVertices;
    meshCreateInfo.vertexElementSize = sizeof(VertexPTN);
    DxMesh* pMesh = DxMesh::Create(pDevice, &meshCreateInfo);

    Plane p;
    DxMeshCreateInfo planeMeshInfo;
    memset(&planeMeshInfo, 0, sizeof(planeMeshInfo));
    planeMeshInfo.pVertexArray = p.GetVB();
    planeMeshInfo.vertexCount = p.NumVertices();
    planeMeshInfo.vertexElementSize = sizeof(VertexPTN);

    DxMesh* pPlaneMesh = DxMesh::Create(pDevice, &planeMeshInfo);

    Cube c;
    DxMeshCreateInfo cubeMeshInfo;
    memset(&cubeMeshInfo, 0, sizeof(cubeMeshInfo));
    cubeMeshInfo.pVertexArray = c.GetVB();
    cubeMeshInfo.vertexCount = c.NumVertices();
    cubeMeshInfo.vertexElementSize = sizeof(VertexPT);

    DxMesh* pCubeMesh = DxMesh::Create(pDevice, &cubeMeshInfo);

    D3D11_SUBRESOURCE_DATA cbInitData;
    memset(&cbInitData, 0, sizeof(D3D11_SUBRESOURCE_DATA));	

    // Camera Buffer
    CameraBufferData cameraData;
    memset(&cameraData, 0, sizeof(CameraBufferData));

    DxBufferCreateInfo cameraBufferCreateInfo = {0};
    cameraBufferCreateInfo.flags.cpuWriteable = TRUE;
    cameraBufferCreateInfo.elemSizeBytes = sizeof(CameraBufferData);
    cameraBufferCreateInfo.pInitialData = &cameraData;
    DxBuffer* pCameraBuffer = DxBuffer::Create(pDevice, &cameraBufferCreateInfo);

    // Shaders ////////////////////////////////////////////////////////////////////////////////////

    m_pPosTexTriVS = DxShader::CreateFromFile(pDevice, "PosTexTri", "Content/shaders/CelShade.hlsl", PosTexVertexDesc, PosTexElements);
    m_pPosTexNormVS = DxShader::CreateFromFile(pDevice, "PosTexNorm", "Content/shaders/CelShade.hlsl", PosTexNormVertexDesc, PosTexNormElements);

    m_pCelShadePS = DxShader::CreateFromFile(pDevice, "CelShade", "Content/shaders/CelShade.hlsl");
    DxShader* pDetectEdges = DxShader::CreateFromFile(pDevice, "DetectEdges", "Content/shaders/CelShade.hlsl");
    DxShader* pApplyTexPS = DxShader::CreateFromFile(pDevice, "ApplyTex", "Content/shaders/CelShade.hlsl");

    DxShader* pCubeVS = DxShader::CreateFromFile(pDevice, "PosTex", "Content/shaders/CelShade.hlsl", PosTexVertexDesc, PosTexElements);
    DxShader* pCubePS = DxShader::CreateFromFile(pDevice, "CubePS", "Content/shaders/CelShade.hlsl");


    ////////////////////////////////////////////////////////////////////////////////////////

    pContext->ClearState();

    // SET RENDER STATE

    FLOAT clearColor[4];
    clearColor[0] = 0.2f;
    clearColor[1] = 0.2f;
    clearColor[2] = 0.2f; 
    clearColor[3] = 1.0f;

    D3D11_RASTERIZER_DESC shadeDesc;
    shadeDesc.FillMode = D3D11_FILL_SOLID;
    shadeDesc.CullMode = D3D11_CULL_BACK;
    shadeDesc.FrontCounterClockwise = FALSE;
    shadeDesc.DepthBias = 0;
    shadeDesc.DepthBiasClamp = 0.0f;
    shadeDesc.SlopeScaledDepthBias = 0;
    shadeDesc.DepthClipEnable = false;
    shadeDesc.ScissorEnable = false;
    shadeDesc.MultisampleEnable = false;
    shadeDesc.AntialiasedLineEnable = false;

    ID3D11RasterizerState* pShadeRS = NULL;
    pDevice->CreateRasterizerState(&shadeDesc, &pShadeRS);

    pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    m_pWindow->Show();

    BOOL quit = false;
    FLOAT yRotationAngle = 0.0f;
    while (!quit)
    {
        ProcessUpdates();

        BeginFrame();

        CameraBufferData* pCameraData = NULL;

        // new frame, clear state
        pContext->ClearState();

        pContext->RSSetViewports(1, &m_pDxData->viewport);
        pContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

        pContext->RSSetState(pShadeRS);
        pContext->PSSetSamplers(0, 1, &pPointSampler);

        pContext->OMSetRenderTargets(1,
                                       &m_pDxData->pAppRenderTargetView,
                                       m_pDxData->pAppDepthStencilTex->GetDepthStencilView());
        pContext->ClearRenderTargetView(m_pDxData->pAppRenderTargetView, clearColor);
        pContext->ClearDepthStencilView(m_pDxData->pAppDepthStencilTex->GetDepthStencilView(),
                                          D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL,
                                          1.0,
                                          0);

        ///// Draw Mesh ///////////////////////////////////////////////////////////////////////////

        FLOAT viewRotationY = (GetMousePos().x - (m_screenWidth / 2.0f)) /(m_screenWidth / 2.0f);
        viewRotationY *= (3.14159f / 4.0f);

        FLOAT viewRotationZ = (GetMousePos().y - (m_screenHeight / 2.0f)) /(m_screenHeight / 2.0f);
        viewRotationZ *= (3.14159f / 4.0f);

        pCameraData = reinterpret_cast<CameraBufferData*>(pCameraBuffer->Map(pContext));
        pCameraData->worldMatrix = XMMatrixScaling(25, 25, 25) * XMMatrixRotationY(yRotationAngle) *
                                   XMMatrixTranslation(m_pCamera->Position().x,
                                                       m_pCamera->Position().y,
                                                       m_pCamera->Position().z) ;
        // translate world +6 in Z to position camera -9 from world origin
        pCameraData->viewMatrix = m_pCamera->W2C();
        pCameraData->projectionMatrix = m_pCamera->C2S();

        pCameraBuffer->Unmap(pContext);

        pCameraBuffer->BindVS(pContext, 0);

        pMesh->Bind(pContext);

        m_pPosTexNormVS->Bind(pContext);
        m_pCelShadePS->Bind(pContext);
        pMesh->Draw(pContext);

        ///// Detect Edges ///////////////////////////////////////////////////////////////////////////


        ///// Draw Light Position ////////////////////////////////////////////////////////////////////

        //yRotationAngle = 0;
        pCameraData = reinterpret_cast<CameraBufferData*>(pCameraBuffer->Map(pContext));
        pCameraData->worldMatrix = XMMatrixScaling(1, 1, 1);
                                 //  XMMatrixRotationY(yRotationAngle);
                                  // XMMatrixTranslation(-10, 10, 10);
        // translate world +6 in Z to position camera -9 from world origin
        pCameraData->viewMatrix = XMMatrixTranslation(0, 0, 10) * m_pCamera->W2C();
        pCameraData->projectionMatrix = m_pCamera->C2S();

        pCameraBuffer->Unmap(pContext);
        pCameraBuffer->BindVS(pContext, 0);

        pCubeVS->Bind(pContext);

        pCubePS->Bind(pContext);

        pCubeMesh->Bind(pContext);
        pCubeMesh->Draw(pContext);

        ///// Draw UI ////////////////////////////////////////////////////////////////////////////////

        ///@todo Consider moving the following UI drawing to Draw2D()
        m_pUI->Begin();
        // Draw UI stuff
        m_pUI->RenderRect();
        m_pUI->RenderText();
        m_pUI->End();

        /// Blend UI onto final image
        DrawUI();

        m_pDxData->pDXGISwapChain->Present(0,0);

        EndFrame();

        Sleep(50);
        yRotationAngle += 3.14159f / 60.0f;
    }

    // Shader Resource Views

    pCameraBuffer->Destroy();

    // Shaders
    m_pCelShadePS->Destroy();
    m_pCelShadePS = NULL;

    m_pPosTexTriVS->Destroy();
    m_pPosTexTriVS = NULL;

    m_pPosTexNormVS->Destroy();
    m_pPosTexNormVS = NULL;

    pApplyTexPS->Destroy();
    pApplyTexPS = NULL;

    pPlaneMesh->Destroy();
    pPlaneMesh = NULL;

    // Samplers
    pPointSampler->Release();

    // Rasterizer State
    pShadeRS->Release();

    m_pDxData->pD3D11Context->ClearState();
    m_pDxData->pD3D11Context->Flush(); 
}