Beispiel #1
0
BOOL C3d::SubclassWindow(HWND hWnd)
{
	BOOL bRet = CWindowImpl<C3d>::SubclassWindow(hWnd);
	if(bRet)
		InitD3D();
	return bRet;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    switch( msg )
    {
        case WM_DESTROY:
            PostQuitMessage( 0 );
            return 0;

        case WM_TIMER:
        case WM_PAINT:
            Render();       // Update the main window when needed
            break;

        // If the display mode changes, tear down the graph and rebuild it.
        // The resolution may have changed or we may have lost surfaces due to
        // a transition from another application's full screen exclusive mode.
        case WM_DISPLAYCHANGE:
            Cleanup();
            InitD3D(hWnd);
            InitGeometry();
            break;

        case WM_CHAR:
        {
            // Close the app if the ESC key is pressed
            if (wParam == VK_ESCAPE)
            {
                PostMessage(hWnd, WM_CLOSE, 0, 0);
            }
            // else maybe background color change by space
            else if(wParam == VK_SPACE)
            {
                bkRed = (BYTE)(rand()%0xFF);
                bkGrn = (BYTE)(rand()%0xFF);
                bkBlu = (BYTE)(rand()%0xFF);
            }
            // else if 'enter' return to black
            else if(wParam == VK_RETURN )
            {
                bkRed = bkGrn = bkBlu = 0x0;
            }
        }
        break;

        case WM_SYSCOMMAND:
        {
            switch (wParam)
            {
                case ID_HELP_ABOUT:
                    // Create a modeless dialog to prevent rendering interruptions
                    CreateDialog(hInstance, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, 
                                (DLGPROC) AboutDlgProc);
                    return 0;
            }
        }
        break;
    }

    return DefWindowProc( hWnd, msg, wParam, lParam );
}
//------------------------------------------------------------
// Initialization code
//------------------------------------------------------------
bool InitEverything(HWND hWnd)
{
	// init D3D
	if (!InitD3D(hWnd))
	{
		return false;
	}

	// create a fullscreen quad
	InitFullScreenQuad();

	// create a render target
	if (FAILED(gpD3DDevice->CreateTexture(WIN_WIDTH, WIN_HEIGHT,
		1, D3DUSAGE_RENDERTARGET, D3DFMT_X8R8G8B8,
		D3DPOOL_DEFAULT, &gpSceneRenderTarget, NULL)))
	{
		return false;
	}

	// loading models, shaders and textures
	if (!LoadAssets())
	{
		return false;
	}

	// load fonts
	if (FAILED(D3DXCreateFont(gpD3DDevice, 20, 10, FW_BOLD, 1, FALSE, DEFAULT_CHARSET,
		OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, (DEFAULT_PITCH | FF_DONTCARE),
		"Arial", &gpFont)))
	{
		return false;
	}

	return true;
}
BOOL DoInit(HWND hWnd)
{
  // Initialize Direct3D
  InitD3D(&g_pD3D, &g_pD3DDevice, hWnd);

  // Load a skeletal mesh
  LoadMesh(&g_Mesh, &g_Frame, g_pD3DDevice, "..\\Data\\tiny.x", "..\\Data\\");

  // Get the bounding radius of the object
  g_MeshRadius = 0.0f;
  D3DXMESHCONTAINER_EX *pMesh = g_Mesh;
  while(pMesh) {

    // Lock the vertex buffer, get its radius, and unlock buffer
    if(pMesh->MeshData.pMesh) {
      D3DXVECTOR3 *pVertices, vecCenter;
      float Radius;
      pMesh->MeshData.pMesh->LockVertexBuffer(D3DLOCK_READONLY, (void**)&pVertices);
      D3DXComputeBoundingSphere(pVertices, 
                                pMesh->MeshData.pMesh->GetNumVertices(),
                                D3DXGetFVFVertexSize(pMesh->MeshData.pMesh->GetFVF()),
                                &vecCenter, &Radius);
      pMesh->MeshData.pMesh->UnlockVertexBuffer();

      // Update radius
      if(Radius > g_MeshRadius)
        g_MeshRadius = Radius;
    }

    // Go to next mesh
    pMesh = (D3DXMESHCONTAINER_EX*)pMesh->pNextMeshContainer;
  }

  return TRUE;
}
Beispiel #5
0
HRESULT CDirect3D::InitializeDX(HWND wnd, bool triplebuf)
{
#if LOG_D3D
    LOG_MSG("D3D:Starting Direct3D");
#endif

	backbuffer_clear_countdown = 0;

    // Check for display window
    if(!wnd) {
	LOG_MSG("Error: No display window set!");
	return E_FAIL;
    }

    hwnd = wnd;

	if (mhmodDX9 == NULL)
		mhmodDX9 = LoadLibrary("d3d9.dll");
    if (mhmodDX9 == NULL)
		return E_FAIL;

    // Set the presentation parameters
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.BackBufferWidth = dwWidth;
    d3dpp.BackBufferHeight = dwHeight;
    d3dpp.BackBufferCount = 1;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.Windowed = true;
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	Section_prop * sec=static_cast<Section_prop *>(control->GetSection("vsync"));
	if(sec) {
			d3dpp.PresentationInterval = (!strcmp(sec->Get_string("vsyncmode"),"host"))?D3DPRESENT_INTERVAL_DEFAULT:D3DPRESENT_INTERVAL_IMMEDIATE;
	}


    if(triplebuf) {
	LOG_MSG("D3D:Using triple buffering");
	d3dpp.BackBufferCount = 2;
    }

    // Init Direct3D
    if(FAILED(InitD3D())) {
	DestroyD3D();
	LOG_MSG("Error: Unable to initialize DirectX9!");
	return E_FAIL;
    }

#if D3D_THREAD
#if LOG_D3D
    LOG_MSG("D3D:Starting worker thread from thread: %u", SDL_ThreadID());
#endif

    thread_run = true;
    thread_command = D3D_IDLE;
    thread = SDL_CreateThread(EntryPoint, this);
    SDL_SemWait(thread_ack);
#endif

    return S_OK;
}
Beispiel #6
0
int WINAPI _tWinMain(HINSTANCE hInstance,
					 HINSTANCE hPreInstance,
					 LPTSTR lpCmdLine,
					 int nCmdShow)
{
	if (!InitD3D(hInstance))			//初始化D3D
	{
		MessageBox(NULL, _T("InitD3D Failed"), NULL, MB_OK);
		return FALSE;
	}

	MSG msg;
	while (true)						//开始消息循环
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
				break;
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else
		{
			Render();
		}
	}

	Cleanup();
	return msg.wParam;
}
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "D3D Tutorial", NULL };
    RegisterClassEx( &wc );

    HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 04", 
                              WS_OVERLAPPEDWINDOW,
                              100, 100, 300, 300,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

    if (FAILED( InitD3D(hWnd) ))      goto MAIN_END;
    if (FAILED( init_geometry() ))    goto MAIN_END;

    ShowWindow( hWnd, SW_SHOWDEFAULT );
    UpdateWindow( hWnd );

    MSG msg;
    ZeroMemory( &msg, sizeof(msg) );
    while ( msg.message != WM_QUIT ) {
        if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) ) {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
        else {
            Render();
        }
    }

MAIN_END:
    UnregisterClass( "D3D Tutorial", wc.hInstance );

    return 0;
}
Beispiel #8
0
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
	// Register the window class
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
		"D3D Tutorial", NULL };
	RegisterClassEx( &wc );
	// Create the application's window
	HWND hWnd = CreateWindow( "D3D Tutorial", "D3D_EulerAngle",
		WS_OVERLAPPEDWINDOW, 100, 100, 400, 400,
		GetDesktopWindow(), NULL, wc.hInstance, NULL );
	// Initialize Direct3D
	if( SUCCEEDED( InitD3D( hWnd ) ) )
	{
		// Show the window
		ShowWindow( hWnd, SW_SHOWDEFAULT );
		UpdateWindow( hWnd );

		// Enter the message loop
		MSG msg;
		ZeroMemory( &msg, sizeof(msg) );
		while( msg.message!=WM_QUIT )
		{
			if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			else
				Render();             
		}
	}
	UnregisterClass( "D3D Tutorial", wc.hInstance );
	return 0;
}
void DoResize()
{
	AppPreResize();
	InitD3D();
	AppPostResize();
	CallAppRender( true );
}
Beispiel #10
0
// ILAVDecoder
STDMETHODIMP CDecDXVA2::Init()
{
  DbgLog((LOG_TRACE, 10, L"CDecDXVA2::Init(): Trying to open DXVA2 decoder"));
  HRESULT hr = S_OK;

  // Initialize all D3D interfaces in non-native mode
  if (!m_bNative) {
    hr = InitD3D();
    if (FAILED(hr)) {
      DbgLog((LOG_TRACE, 10, L"-> D3D Initialization failed with hr: %X", hr));
      return hr;
    }

    if (CopyFrameNV12 == NULL) {
      int cpu_flags = av_get_cpu_flags();
      if (cpu_flags & AV_CPU_FLAG_SSE4) {
        DbgLog((LOG_TRACE, 10, L"-> Using SSE4 frame copy"));
        CopyFrameNV12 = CopyFrameNV12_SSE4;
      } else {
        DbgLog((LOG_TRACE, 10, L"-> Using fallback frame copy"));
        CopyFrameNV12 = CopyFrameNV12_fallback;
      }
    }
  }

  // Init the ffmpeg parts
  // This is our main software decoder, unable to fail!
  CDecAvcodec::Init();

  return S_OK;
}
Beispiel #11
0
int WINAPI WinMain(
				   HINSTANCE hInstance,
				   HINSTANCE PrevInstance,
				   PSTR cmdLine,
				   int showCmd)
{
	if(!InitD3D(hInstance, Width, Height, Windowed, D3DDEVTYPE_HAL, &Device))
	{
		::MessageBox(0, "InitD3D Failed", "Error", MB_OK);
		return 0;
	}
	if(!Setup())
	{
		::MessageBox(0, "Setup Failed", "Error", MB_OK);
		return 0;			
	}

	EnterMsgLoop( Display );

	Cleanup();
	
	Device->Release();

	return 0;
}
Beispiel #12
0
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "D3D Tutorial", NULL };
    RegisterClassEx( &wc );

    // Create the application's window
    HWND hWnd = CreateWindow( "D3D Tutorial", "D3D Tutorial 01: CreateDevice", 
                              WS_EX_TOPMOST, 100, 100, 300, 300,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    { 
        // Show the window
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );

        // Enter the message loop
        MSG msg; 
        while( GetMessage( &msg, NULL, 0, 0 ) )
        {
            TranslateMessage( &msg );
            DispatchMessage( &msg );
        }
    }

    UnregisterClass( "D3D Tutorial", wc.hInstance );
    return 0;
}
Beispiel #13
0
void Initilize(void)
{	
	// Register the window class
	WNDCLASSEX createWin = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
		_T("The Throne of The Kingdom"), NULL };
	RegisterClassEx( &createWin );

	// Create the application's window
	hwnd = CreateWindow( _T("The Throne of The Kingdom"), _T("TOK"),
		WS_OVERLAPPEDWINDOW, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
		NULL, NULL, createWin.hInstance, NULL );
	
	InitD3D(hwnd);
	if(!SUCCEEDED(D3DXCreateSprite(renderDevice, &sprite)))
	{
		MessageBox(NULL, _T("Error of create sprite"), NULL, NULL);
	}
	//ZeroMemory(&bg, sizeof(Objects));
	//ZeroMemory(&om, sizeof(ObjectManager));

	LoadData();

	// Show the window
	ShowWindow( hwnd, SW_SHOWDEFAULT );
	UpdateWindow( hwnd );
}
Beispiel #14
0
// Win32 MessageProc callback
LRESULT CALLBACK MessageProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    // Send event message to AntTweakBar
    if( TwEventWin(wnd, msg, wParam, lParam) )
        return 0;   // Event has been handled by AntTweakBar

    switch( msg )
    {
    case WM_CHAR:       
        if( wParam==VK_ESCAPE )
            PostQuitMessage(0);
        return 0;
    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    case WM_SIZE:   // Window size has been changed
        // Reset D3D device
        if( g_D3DDev )
        {
            g_D3Dpp.BackBufferWidth  = LOWORD(lParam);
            g_D3Dpp.BackBufferHeight = HIWORD(lParam);
            if( g_D3Dpp.BackBufferWidth>0 && g_D3Dpp.BackBufferHeight>0 )
            {
                g_D3DDev->Reset(&g_D3Dpp);
                InitD3D();  // re-initialize D3D states
            }
            // TwWindowSize has been called by TwEventWin32, 
            // so it is not necessary to call it again here.
        }
        return 0;
    default:
        return DefWindowProc(wnd, msg, wParam, lParam);
    }
}
Beispiel #15
0
// Initialize application window
// Most of the error checking omitted
bool App::Init()
{
	/*
	viewports[0].SetVPSize(winWidth/2, winHeight/2);
	Viewport vp(viewports[0]);
	vp.SetVPPosition(winWidth/2, winHeight/2);
	viewports.push_back(vp);
	*/

	if(!InitWindow())
		return false;

	if(!InitD3D())
		return false;

	// Call resize to do rest of window initialization
	Resize();

	if(!CompileShaders())
		return false;

	// Set up sampler states for perlin noise
	SetupSamplers();

	// Set up lookup textures for perlin noise
	SetupTextures();	

	// Initialize vertex buffer with canvas quad
	InitCanvas();

	// Init default viewport
	viewports[0].RefreshBuffer();

	// Initialize viewport buffer
	D3D11_SUBRESOURCE_DATA vpbufData;
	vpbufData.pSysMem			= viewports[0].GetBufferData();
	vpbufData.SysMemPitch		= NULL;
	vpbufData.SysMemSlicePitch	= NULL;
	HR(dev->CreateBuffer(&Viewport::viewportBufferDesc, NULL, &viewportBuffer));

	// Initialize shader params buffer;
	D3D11_BUFFER_DESC shaderBufferDesc= {
		sizeof(ShaderParams),
		D3D11_USAGE_DYNAMIC,
		D3D11_BIND_CONSTANT_BUFFER,
		D3D11_CPU_ACCESS_WRITE,
		0
	};
	D3D11_SUBRESOURCE_DATA shaderBuffer;
	shaderBuffer.pSysMem			= shaderParams;
	shaderBuffer.SysMemPitch		= NULL;
	shaderBuffer.SysMemSlicePitch	= NULL;
	HR(dev->CreateBuffer(&shaderBufferDesc, &shaderBuffer, &shaderParamsBuffer));

	// And finally update the window
	UpdateWindow(mainWnd);

	return true;
}
Beispiel #16
0
int WINAPI WinMain(HINSTANCE hInstance,
                   HINSTANCE hPrevInstance,
                   LPSTR lpCmdLine,
                   int nCmdShow)
{
    HWND hWnd;
    WNDCLASSEX wc;

    ZeroMemory(&wc, sizeof(WNDCLASSEX));

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WindowProc;
    wc.hInstance = hInstance;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
    wc.lpszClassName = "WindowClass";

    RegisterClassEx(&wc);

    RECT wr = {0, 0, 800, 600};
    AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);

    hWnd = CreateWindowEx(NULL,
                          "WindowClass",
                          "Our First Direct3D Program",
                          WS_OVERLAPPEDWINDOW,
                          300,
                          300,
                          wr.right - wr.left,
                          wr.bottom - wr.top,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);
    ShowWindow(hWnd, nCmdShow);
    InitD3D(hWnd);

    MSG msg;
    while(TRUE)
    {
        if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);

            if(msg.message == WM_QUIT)
                break;
        }
        else
        {
            // Run game code here
        }
    }

    CleanD3D();
    return msg.wParam;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
DEFINE_THREAD_ROUTINE(directx_renderer_thread, data)
{
    HWND hWnd = NULL;
	
	WNDCLASSEX wc =
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"A.R.Drone Video", NULL
	};
	RegisterClassEx( &wc );

	if (data == NULL)
	{
		// Create the application's window
		hWnd = CreateWindow( L"A.R.Drone Video", L"A.R.Drone Video",
								  WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
								  NULL, NULL, wc.hInstance, NULL );
	}
	else
	{
		hWnd = (HWND)data;
	}

    // Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
        // Create the scene geometry
        if( SUCCEEDED( InitGeometry() ) )
        {
            // Show the window
            ShowWindow( hWnd, SW_SHOWDEFAULT );
            UpdateWindow( hWnd );

            // Enter the message loop
            MSG msg;
            ZeroMemory( &msg, sizeof( msg ) );
            while( msg.message != WM_QUIT )
            {
                if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
                {
                    TranslateMessage( &msg );
                    DispatchMessage( &msg );
                }
                else
                    Render();
            }
        }
    }
	
	UnregisterClass( L"A.R.Drone Video", wc.hInstance );

	/* Tells ARDRoneTool to shutdown */
	signal_exit();

    return 0;
}
//-----------------------------------------------------------------------------
// Name: wWinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI wWinMain(HINSTANCE hInst, HINSTANCE, LPWSTR, INT)
{
	UNREFERENCED_PARAMETER(hInst);

	// Register the window class
	WNDCLASSEX wc =
	{
		sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
		"Shader Tutorial", NULL
	};
	RegisterClassEx(&wc);

	// Create the application's window
	HWND hWnd = CreateWindow("Shader Tutorial", "Shader Tutorial 00",
		WS_OVERLAPPEDWINDOW, 100, 100, 500, 500,
		NULL, NULL, wc.hInstance, NULL);

	// Direct3Dを初期化。
	InitD3D(hWnd);
	//モデルを初期化。
	InitGeometry();
	//エフェクトファイルのロード。
	LoadEffectFile();
	
	ZeroMemory( g_diffuseLightDirection, sizeof(g_diffuseLightDirection) );
	ZeroMemory( g_diffuseLightColor, sizeof(g_diffuseLightColor) );
			
	D3DXMatrixIdentity(&g_worldMatrix);
	D3DXMatrixIdentity(&g_rotationMatrix);
	//カメラの初期化。
	camera.Init();
	// Show the window
	ShowWindow(hWnd, SW_SHOWDEFAULT);
	UpdateWindow(hWnd);

	// ゲームループ
	MSG msg;
	ZeroMemory(&msg, sizeof(msg));
	while (msg.message != WM_QUIT)
	{
		if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else {
			Update();
			Render();
		}
	}
	

	UnregisterClass("Shader Tutorial", wc.hInstance);
	return 0;
}
Beispiel #19
0
int CDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CDialog::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	InitD3D(m_hWnd);
	Render();
	
	return 0;
}
Beispiel #20
0
	D3DContext::D3DContext(WindowProperties properties, void* deviceContext)
		: m_DebugLayerEnabled(true)
	{
		m_RenderTargetView = nullptr;
		m_DepthStencilView = nullptr;
		m_DepthStencilBuffer = nullptr;

		m_Properties = properties;
		InitD3D((HWND)deviceContext);
	}
Beispiel #21
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ) 
{ 
	// Register the window class 
	WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,  
		GetModuleHandle(NULL), NULL, LoadCursor(NULL, IDC_ARROW), NULL, NULL, 
		L"D3D Tutorial", NULL }; 
	RegisterClassEx( &wc ); 

	// Create the application's window 
	HWND hWnd = CreateWindow( L"D3D Tutorial", L"My first shader",  
		WS_OVERLAPPEDWINDOW , 0, 0, 600, 600, 
		NULL, NULL, wc.hInstance, NULL ); 

	// Get last time
	static DWORD lastTime = timeGetTime();

	// Initialize Direct3D 
	if( SUCCEEDED( InitD3D( hWnd ) ) ) 
	{  
		// Show the window 
		ShowWindow( hWnd, SW_SHOWDEFAULT ); 
		UpdateWindow( hWnd ); 

		// Enter the message loop 
		MSG    msg ;  
		ZeroMemory( &msg, sizeof(msg) ); 
		PeekMessage( &msg, NULL, 0U, 0U, PM_NOREMOVE ); 

		while (msg.message != WM_QUIT)   
		{ 
			if( PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE) != 0) 
			{ 
				TranslateMessage (&msg) ; 
				DispatchMessage (&msg) ; 
			} 
			else // Render the game if no message to process 
			{ 
				// Get current time
				DWORD currTime  = timeGetTime();

				// Calculate time elapsed
				float timeDelta = (currTime - lastTime) * 0.001f;

				// Render
				Render(timeDelta) ;

				// Update last time to current time for next loop
				lastTime = currTime;
			} 
		} 
	} 

	UnregisterClass( L"D3D Tutorial", wc.hInstance ); 
	return 0; 
} 
Beispiel #22
0
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
{
	WNDCLASSEX wc={sizeof(WNDCLASSEX), CS_CLASSDC | CS_DBLCLKS, MsgProc, 0L, 0L, GetModuleHandle(NULL), LoadIcon(hInstance, (LPCSTR)IDI_3DFX), LoadCursor(NULL, IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), NULL, "My D3D Application", NULL};
	RegisterClassEx(&wc);
	hWnd=CreateWindow("My D3D Application", "My Effect", WS_OVERLAPPEDWINDOW, WindowX, WindowY, WindowWidth, WindowHeight, GetDesktopWindow(), NULL, wc.hInstance, NULL);
	//SetWindowLong( hWnd, GWL_STYLE, WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX);

	char pInfo[500];
	UINT InfoID = 0;

	if(SUCCEEDED(InitD3D(hInstance)))
	{
		InfoID = InitMyScene();

		ShowWindow(hWnd,SW_SHOWDEFAULT);
		UpdateWindow(hWnd);

		MSG msg;
		while(GetMessage(&msg,NULL,0,0))
		{
			TranslateMessage(&msg);	
			DispatchMessage(&msg);	

#ifndef USE_DEBUG       //非DEBUG的时候有错误不能直接弹出对话框,要根据函数返回值退出后再提示,另外要用RELEASE版编译后运行才不会在退出显示MESSAGEBOX时出错
			if(InfoID != 0) 
			{
				SendMessage(hWnd, WM_CLOSE, 0, 0);
				continue;
			}
#endif

			if(msg.message==WM_CLOSE) break;
			ControlProc();

			//显示出错,可能是重置设备或切换分辨率的问题
			InfoID = DisplayMyScene();
#ifndef USE_DEBUG       //非DEBUG的时候有错误不能直接弹出对话框,要根据函数返回值退出后再提示,另外要用RELEASE版编译后运行才不会在退出显示MESSAGEBOX时出错
			if(InfoID != 0) 
			{
				SendMessage(hWnd, WM_CLOSE, 0, 0);
				continue;
			}
#endif
		}
	}

	ReleaseD3D();
	UnregisterClass("My D3D Application", wc.hInstance);
	LoadString(hInstance, InfoID, pInfo, 500);
	// 如果直接返回E_FAIL,就不要提示了(表示该错误类型内部字串中是没有的),直接退出即可
	if(InfoID != 0 && InfoID != E_FAIL)
		MessageBox(NULL, pInfo, "Fatal Error", MB_OK);
	return(0);
}
INT APIENTRY _tWinMain( _In_ HINSTANCE hInstance,
						_In_opt_ HINSTANCE hPrevInstance,
						_In_ LPTSTR    lpCmdLine,
						_In_ int       nCmdShow )
{
	UNREFERENCED_PARAMETER( hPrevInstance );
	UNREFERENCED_PARAMETER( lpCmdLine );
	UNREFERENCED_PARAMETER( nCmdShow );

	// 윈도우 클래스 등록
	WNDCLASSEX wc = { sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, L"D3D Tutorial", NULL };
	RegisterClassEx( &wc );

	// 윈도우 생성
	HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorials",
							  WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
							  GetDesktopWindow(), NULL, wc.hInstance, NULL );

	// Direct3D 초기화
	if ( SUCCEEDED( InitD3D( hWnd ) ) )
	{
		// 버텍스 버퍼 초기화
		if ( SUCCEEDED (InitVB()))
		{
			// 윈도우 출력
			ShowWindow( hWnd, SW_SHOWDEFAULT );
			UpdateWindow( hWnd );

			// 메시지 루프
			MSG msg;
			ZeroMemory( &msg, sizeof( msg ) );
			while ( msg.message != WM_QUIT)
			{
				// 메시지 큐에 메시지가 있으면 메시지 처리
				if ( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
				{
					TranslateMessage( &msg );
					DispatchMessage( &msg );
				}
				else
				{
					Render();
				}
			}
		}
	}

	// 등록 된 클래스 제거
	UnregisterClass( L"D3D Tutorial", wc.hInstance );
	
	return 0;
}
int WINAPI WinMain( __in HINSTANCE hInstance, __in_opt HINSTANCE hPrevInstance, __in LPSTR lpCmdLine, __in int nShowCmd )
{
	WNDCLASSEX wc;
	ZeroMemory(&wc, sizeof(wc));

	wc.cbSize = sizeof(wc);
	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
	wc.lpfnWndProc = (WNDPROC)MyWndProc;
	wc.lpszClassName = L"D3D";
	wc.style = CS_HREDRAW | CS_VREDRAW;

	RegisterClassEx(&wc);

	HWND hwnd = NULL;
	hwnd = CreateWindow(L"D3D", L"Simplest Video Play Direct3D (Texture)", WS_OVERLAPPEDWINDOW, 100, 100, 500, 500, NULL, NULL, hInstance, NULL);
	if (hwnd==NULL){
		return -1;
	}


	if(InitD3D( hwnd, pixel_w, pixel_h)==E_FAIL){
		return -1;
	}

	ShowWindow(hwnd, nShowCmd);
	UpdateWindow(hwnd);

	fp=fopen("../test_bgra_320x180.rgb","rb+");

	if(fp==NULL){
		printf("Cannot open this file.\n");
		return -1;
	}

	MSG msg;
	ZeroMemory(&msg, sizeof(msg));

	while (msg.message != WM_QUIT){
		//PeekMessage, not GetMessage
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		else{
			Sleep(40);
			Render();
		}
	}


	UnregisterClass(L"D3D", hInstance);
	return 0;
}
Beispiel #25
0
/**
 * AppInit()
 */
int AppInit(HINSTANCE hInst)
{
	CreateConsole();

	if(!InitD3D(hInst, windowed, screenWidth, screenHeight, multisampleType, multisampleQuality, HWnd, &D3D, &D3DDevice))
		return 0;

	if(!InitInput(hInst, HWnd, &DI, &DID_Keyboard, &DID_Mouse))
		return 0;

	return 1;
}
Beispiel #26
0
	bool D3DRenderContext::Init() {
		if (m_initialized || m_window == NULL) {
			return false;
		}

		if (!InitD3D()) {
			return false;
		}
		
		m_initialized = true;
		return true;
	}
/**-----------------------------------------------------------------------------
 * 프로그램 시작점
 *------------------------------------------------------------------------------
 */
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    /// 윈도우 클래스 등록
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "BasicFrame", NULL };
    RegisterClassEx( &wc );

    /// 윈도우 생성
    HWND hWnd = CreateWindow( "BasicFrame", WINDOW_TITLE,
                              WS_OVERLAPPEDWINDOW, 100, 100, WINDOW_W, WINDOW_H,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

	g_hwnd = hWnd;

	srand( GetTickCount() );

    /// Direct3D 초기화
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
		if( SUCCEEDED( InitObjects() ) )
		{
			if( SUCCEEDED( InitGeometry() ) )
			{

        		/// 윈도우 출력
				ShowWindow( hWnd, SW_SHOWDEFAULT );
				UpdateWindow( hWnd );

        		/// 메시지 루프
				MSG msg;
				ZeroMemory( &msg, sizeof(msg) );
				while( msg.message!=WM_QUIT )
				{
            		/// 메시지큐에 메시지가 있으면 메시지 처리
					if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
					{
						TranslateMessage( &msg );
						DispatchMessage( &msg );
					}
					else
					/// 처리할 메시지가 없으면 Render()함수 호출
						Render();
				}
			}
		}
    }

	DeleteObjects();
    UnregisterClass( "BasicFrame", wc.hInstance );
    return 0;
}
Beispiel #28
0
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
	UNREFERENCED_PARAMETER( hInst );

	// Register the window class
	WNDCLASSEX wc =
	{
		sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
		GetModuleHandle( NULL ), NULL, NULL, NULL, NULL,
		L"D3D Tutorial", NULL
	};
	RegisterClassEx( &wc );

	// Create the application's window
	HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 05: Textures",
		WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
		NULL, NULL, wc.hInstance, NULL );

	AllocConsole();
	freopen("CONOUT$", "w", stdout);
	printf("start App \n");

	if( SUCCEEDED( InitD3D( hWnd ) ) )
	{
		DxInput::GetInstance()->Create(hWnd);
		
		ShowWindow( hWnd, SW_SHOWDEFAULT );
		UpdateWindow( hWnd );

		MSG msg;
		ZeroMemory( &msg, sizeof( msg ) );
		while( msg.message != WM_QUIT )
		{
			if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
			{
				TranslateMessage( &msg );
				DispatchMessage( &msg );
			}
			else
			{
				Update();
				Render();
			}
		}
	}

	FreeConsole();
	DxInput::GetInstance()->Release();
	UnregisterClass( L"D3D Tutorial", wc.hInstance );
	
	return 0;
}
Beispiel #29
0
//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT )
{
    // Register the window class
    WNDCLASSEX wc =
    {
        sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L,
        GetModuleHandle( NULL ), NULL, LoadCursor(hInst, IDC_ARROW), NULL, NULL,
		AppName, NULL
    };
    RegisterClassEx( &wc );

    // Create the application's window
	::hWnd = CreateWindow(AppName, AppWinName,
                              WS_OVERLAPPEDWINDOW, 0, 0, Form_Width, Form_Height,
                              NULL, NULL, wc.hInstance, NULL );

	::hInst = hInst;
    // Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
        // Show the window
        ShowWindow( hWnd, SW_SHOWDEFAULT );
        UpdateWindow( hWnd );

		BaseGame* m_pMyGame = new GameClassName();
		m_pMyGame->InitGame();
		
		if( FAILED(m_pMyGame->Load()) )
			PostQuitMessage(0);
        // Enter the message loop
        MSG msg;
        ZeroMemory( &msg, sizeof( msg ) );
        while( msg.message != WM_QUIT )
        {
            if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
            {
                TranslateMessage( &msg );
                DispatchMessage( &msg );
            }
            else
			{
				m_pMyGame->Update();
				m_pMyGame->Draw();
			}
        }
		SafeDel(m_pMyGame);
    }

	
	UnregisterClass(AppName, wc.hInstance);
    return 0;
}
Beispiel #30
0
void __cdecl main()
{
    // Initialize Direct3D
    if( FAILED( InitD3D() ) )
        return;

    // Initialize the vertex buffer
    if( FAILED( InitScene() ) )
        return;

    InitTime();

	GameService::Initialize(
		FALSE,	// require online
		2,		// achievement count
		0,		// version id
		0,		// trial version
		TRUE	// dump log
#if defined(_PS3)
		, 5000	// free space available in KB for PS3
#endif
		);

    for(;;) // loop forever
    {
        // What time is it?
        UpdateTime();
        // Update the world
        Update();   

		GameService::Update();

#if defined(TRACKING_TEST)
		static int s_send = 0;
		static int s_level_id = 0;
		if (!s_send) // only send GAME_START tag once
		{
			s_send = 1;
			char tracking_attr[128];
			//char ls_reason[10];
			sprintf_s(tracking_attr, 128, "VERSION=%d&LICENSETYPE=%d&LANGUAGE=li", 13, 0);
			GameService::TrackingSendTag("GAME_START", tracking_attr);
		}
#endif

        // Render the scene
        Render();
    }

	GameService::Destroy();
}