HRESULT InitD3D( HWND hWnd )
{
	// Create the D3D object.
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
		return E_FAIL;

	// Set up the structure used to create the D3DDevice
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory( &d3dpp, sizeof(d3dpp) );
	d3dpp.Windowed = TRUE;
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	// Create the D3DDevice
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		return E_FAIL;
	}

	InitVB();

	// Disable lighting, since the vertex contains colors
	g_pd3dDevice->SetRenderState( D3DRS_LIGHTING , FALSE );

	return S_OK;
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID CDlg::Render()
{
	if (! SUCCEEDED( InitVB() )) {
		return;
	}
    // Clear the backbuffer to a blue color
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 );

    // Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        // Draw the triangles in the vertex buffer. This is broken into a few
        // steps. We are passing the vertices down a "stream", so first we need
        // to specify the source of that stream, which is our vertex buffer. Then
        // we need to let D3D know what vertex shader to use. Full, custom vertex
        // shaders are an advanced topic, but in most cases the vertex shader is
        // just the FVF, so that D3D knows what type of vertices we are dealing
        // with. Finally, we call DrawPrimitive() which does the actual rendering
        // of our geometry (in this case, just one triangle).
        g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) );
        g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        //g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
        g_pd3dDevice->DrawPrimitive( D3DPT_POINTLIST, 0, 3 );

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

    // Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
Beispiel #3
0
/**
@input	VOID
@return	생성결과
@brief	초기화 및 정점 버퍼 생성
*/
HRESULT TestCube::Create()
{
	InitVB();
	InitIB();

	return S_OK;
}
HRESULT InitD3D( HWND hWnd )
{
	// Create the D3D object, which is needed to create the D3DDevice.
	if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
	{
		MessageBoxA(NULL, "Create D3D9 object failed!", "Error", 0) ;
		return E_FAIL;
	}

	ZeroMemory( &d3dpp, sizeof(d3dpp) );

	d3dpp.Windowed = TRUE; // use window mode, not full screen
	d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;

	// Create device
	if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp, &g_pd3dDevice ) ) )
	{
		MessageBoxA(NULL, "Create D3D9 device failed!", "Error", 0) ;
		return E_FAIL;
	}

	// Create teapot
	D3DXCreateTeapot(g_pd3dDevice, &g_pTeapotMesh, NULL) ;

	// Create vertex buffer
	InitVB();

	return S_OK;
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
	InitMatrix();
	InitTexture();
	InitVB();
	InitPS();
	return S_OK;
}
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;
}
FontRasterizer::FontRasterizer(BaseCamera* cam, CXMMATRIX proj, LitTexEffect* effect, int numRows, int numCols, 
	ID3D11ShaderResourceView* texture, ID3D11Device* device) : 
		m2DCam(cam),
		mEffect(effect),
		mNumRows(numRows),
		mNumCols(numCols),
		mFontImage(texture)
{
	XMStoreFloat4x4(&m2DProj, proj);
	InitVB(device);
	InitIB(device);
}
Beispiel #8
0
bool CSprite::Init(float Width, float Height, char *texfile)
{
	m_fWidth = Width ;
	m_fHeight = Height ;

	if(FAILED(InitVB()))
		return false ;
	if(!SetTexture(texfile))
		return false ;

	return true ;
}
void Terrain::Init(ID3D11Device* device, const InitInfo& info)
{
	mTerrainData = info;
	LoadHeightMap();
	InitVB(device);
	InitIB(device);

	mEffect = new TerrainEffect();
	mEffect->LoadEffect(L"FX/terrain.fx", device);

	LoadTextures(device);
}
Beispiel #10
0
bool CSprite::Init(char *texfile)
{
	if(!SetTexture(texfile))
		return false ;

	m_fWidth = (float)m_pTexInfo->Width ;
	m_fHeight = (float)m_pTexInfo->Height ;

	if(FAILED(InitVB()))
		return false ;

	return true ;
}
Beispiel #11
0
//-----------------------------------------------------------------------------
// Name: wWinMain()
// 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, NULL, NULL, NULL,
        L"OpenGL TestBed", NULL
    };
    RegisterClassEx( &wc );

    // Create the application's window
    HWND hWnd = CreateWindow( L"OpenGL TestBed", L"OpenGL TestBed",
                              WS_OVERLAPPEDWINDOW, 100, 100, 300, 300,
                              NULL, NULL, wc.hInstance, NULL );

    // Initialize Direct3D
    if(InitGL(hWnd))
    {
        // Create the vertex buffer
        if(InitVB())
        {
            // 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"OpenGL TestBed", wc.hInstance );
    return 0;
}
Beispiel #12
0
//-----------------------------------------------------------------------------
// Desc: 入口函数
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    //注册窗口类
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L,
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      L"ClassName", NULL
                    };
    RegisterClassEx( &wc );

    //创建窗口
    HWND hWnd = CreateWindow( L"ClassName", L"图形反锯齿",
                              WS_OVERLAPPEDWINDOW, 200, 100, 300, 300,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );

    //初始化Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    {
        //创建并填充顶点缓冲区
        if( SUCCEEDED( InitVB() ) )
        {
            //显示窗口(最大化)
            ShowWindow( hWnd, SW_SHOWMAXIMIZED );
            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"ClassName", wc.hInstance );
    return 0;
}
Sprite::Sprite(FXMVECTOR pos2D, FXMVECTOR scale2D,
	unsigned short frameWidth, unsigned short frameHeight,
	float depth, const std::vector<Frame*>& frames,
	float frameRate, ID3D11Device* device) :
	mFrameWidth(frameWidth),
	mFrameHeight(frameHeight),
	mDepth(depth),
	mFrames(frames),
	mFrameRate(frameRate),
	mFrameIndex(0),
	mAngle(0),
	mCurrFrameTime(0.0f)
{
	XMStoreFloat2(&mPos, pos2D);
	XMStoreFloat2(&mScale, scale2D);

	InitVB(device);
	InitIB(device);
}
HRESULT ResetDevice(D3DPRESENT_PARAMETERS d3dpp)
{
	// Check device state
	HRESULT hr = g_pd3dDevice->TestCooperativeLevel() ;

	// Device can be reset now
	if (SUCCEEDED(hr) || hr == D3DERR_DEVICENOTRESET)
	{
		// Release resource allocated as D3DPOOL_DEFAULT
		g_pVB->Release();

		// Reset device
		HRESULT hr = g_pd3dDevice->Reset(&d3dpp) ;
		if (FAILED(hr))
		{
			const CHAR* errorString = DXGetErrorString(hr) ;
			DXTRACE_ERR_MSGBOX(errorString, hr) ;
		}

		// Recreate the vertex buffer, since it is create by using
		// D3DPOOL_DEFAULT, the function MUST placed here!!! why?
		// you cann't place it before the return clause of this function
		// what's the inner cause?
		InitVB();
	}
	// Device is still in lost state, wait
	else if (hr == D3DERR_DEVICELOST)
	{
		Sleep(25) ;
	}
	else // Other error, Show error box
	{
		const CHAR* errorString = DXGetErrorString(hr) ;
		DXTRACE_ERR_MSGBOX(errorString, hr) ;
	}

	return hr ;
}
/**-----------------------------------------------------------------------------
 * 기하정보 초기화
 *------------------------------------------------------------------------------
 */
HRESULT InitGeometry()
{
    if ( FAILED( InitTexture() ) )
    {
        return E_FAIL;
    }
    if ( FAILED( InitVB() ) )
    {
        return E_FAIL;
    }
    if ( FAILED( InitIB() ) )
    {
        return E_FAIL;
    }
    SetupCamera();

    // 최초의 마우스 위치 보관
    POINT	pt;
    GetCursorPos( &pt );
    g_dwMouseX = pt.x;
    g_dwMouseY = pt.y;
    return S_OK;
}
void Cube::InitBuffers(ID3D11Device* device, float width, float height,float depth)
{
	InitVB(device, width, height, depth);
	InitIB(device);
}
Beispiel #17
0
//-------------------------------------------------------------------------------------
void BillBoard::SetMesh(){
	InitVB();
	InitIB();
	InitSprite();
	SetupMatrix();
}
Beispiel #18
0
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR szCmdLine, int iCmdShow) 
{ 
	WNDCLASSEX winClass ; 

	winClass.lpszClassName = "ScreenQuad"; 
	winClass.cbSize        = sizeof(WNDCLASSEX); 
	winClass.style         = CS_HREDRAW | CS_VREDRAW; 
	winClass.lpfnWndProc   = MsgProc; 
	winClass.hInstance     = hInstance; 
	winClass.hIcon         = NULL ; 
	winClass.hIconSm       = NULL ; 
	winClass.hCursor       = LoadCursor(NULL, IDC_ARROW) ; 
	winClass.hbrBackground = NULL ; 
	winClass.lpszMenuName  = NULL ; 
	winClass.cbClsExtra    = 0; 
	winClass.cbWndExtra    = 0; 

	RegisterClassEx (&winClass) ;   

	HWND hWnd = CreateWindowEx(NULL,   
		winClass.lpszClassName,	// window class name 
		"ScreenQuad",			// window caption 
		WS_OVERLAPPEDWINDOW,	// window style 
		32,						// initial x position 
		32,						// initial y position 
		512,					// initial window width 
		512,					// initial window height 
		NULL,					// parent window handle 
		NULL,					// window menu handle 
		hInstance,				// program instance handle 
		NULL) ;					// creation parameters 

	// Create window failed 
	if(hWnd == NULL) 
	{ 
		MessageBoxA(hWnd, "Create Window failed!", "Error", 0) ; 
		return -1 ; 
	} 

	// Initialize Direct3D 
	if( SUCCEEDED(InitD3D(hWnd))) 
	{  
		if (SUCCEEDED(InitVB()))
		{
			// 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 there is no message to process 
				{ 
					Render() ; 
				} 
			} 
		}
	} 

	UnregisterClass(winClass.lpszClassName, hInstance) ; 
	return 0; 
}