First Time using DirectX 10

Started by
31 comments, last by Nik02 14 years, 9 months ago
I also have a laptop with that chipset, and it too refused to work with D3D10, even with the latest updates from Windows update. After downloading the drivers from Intel it worked, so I would suggest you try that too!
http://www.intel.com/support/graphics/intelgm965/
Click on Get the latest drivers for Vista.

Also get the March 2009 SDK: http://msdn.microsoft.com/en-us/directx/default.aspx

This is the minimal test-program I used:
#include <windows.h>#include <D3D10_1.h>#include <D3DX10.h>#include <DXErr.h>#pragma comment (lib, "D3D10_1.lib")#pragma comment (lib, "D3DX10.lib")#pragma comment (lib, "DXErr.lib")LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);// Mainint WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {	// Register windowclass	WNDCLASSEX wc;	ZeroMemory(&wc, sizeof(wc));	wc.cbSize = sizeof(wc);	wc.lpszClassName = TEXT("MyClass");	wc.hInstance = hInstance;	wc.lpfnWndProc = WndProc;	wc.hCursor = LoadCursor(NULL, IDC_ARROW);	RegisterClassEx(&wc);		// Create window	HWND hWnd = CreateWindow(		wc.lpszClassName,		TEXT("My Window"),		WS_OVERLAPPEDWINDOW,		CW_USEDEFAULT,		CW_USEDEFAULT,		CW_USEDEFAULT,		CW_USEDEFAULT,		NULL,		NULL,		hInstance,		NULL	);		// Create swap chain and device	DXGI_SWAP_CHAIN_DESC sd;	IDXGISwapChain *pSwapChain;	ID3D10Device1 *pDevice;		ZeroMemory(&sd, sizeof(sd));	sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;	sd.SampleDesc.Count = 1;	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;	sd.BufferCount = 1;	sd.OutputWindow = hWnd;	sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;	sd.Windowed = TRUE;		HRESULT hResult = D3D10CreateDeviceAndSwapChain1(		NULL,		D3D10_DRIVER_TYPE_HARDWARE,//D3D10_DRIVER_TYPE_REFERENCE,		NULL,		0,//D3D10_CREATE_DEVICE_DEBUG,		D3D10_FEATURE_LEVEL_10_0,		D3D10_1_SDK_VERSION,		&sd,		&pSwapChain,		&pDevice	);	if(FAILED(hResult)) {		const TCHAR	*derr = DXGetErrorString(hResult);		const TCHAR	*ddesc = DXGetErrorDescription(hResult);		MessageBox(NULL, ddesc, derr, MB_OK);				return 0;	}		// Render target	ID3D10Texture2D *pBuffer;	ID3D10RenderTargetView *pRTV;		pSwapChain->GetBuffer(0, __uuidof(pBuffer), (void**)&pBuffer);	pDevice->CreateRenderTargetView(pBuffer, NULL, &pRTV);	pBuffer->Release();		pDevice->OMSetRenderTargets(1, &pRTV, NULL);		// Viewport	D3D10_TEXTURE2D_DESC bd;	pBuffer->GetDesc(&bd);		D3D10_VIEWPORT vp;	ZeroMemory(&vp, sizeof(vp));	vp.Width = bd.Width;	vp.Height = bd.Height;	vp.MinDepth = 0.0f;	vp.MaxDepth = 1.0f;	pDevice->RSSetViewports(1, &vp);		// Create a font to display text	LPD3DX10FONT pFont;	hResult = D3DX10CreateFont(		pDevice,		25,		1,		FW_BOLD,		1,		FALSE,		DEFAULT_CHARSET,		OUT_DEFAULT_PRECIS,		DEFAULT_QUALITY,		DEFAULT_PITCH |			FF_DONTCARE,		TEXT("Courier"),		&pFont	);		// Main loop	ShowWindow(hWnd, nCmdShow);	size_t frameNum = 0;	while(true) {		MSG msg;		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) != 0) {			if(msg.message == WM_QUIT)				break;			else {				TranslateMessage(&msg);				DispatchMessage(&msg);			}		}		else {			// Clear backbuffer			float color[4] = {0.7f, 0.0f, 0.7f, 1.0f};			pDevice->ClearRenderTargetView(pRTV, color);						// Handle game frame			frameNum++;						wchar_t str[255];			wsprintf(str, TEXT("Hello World!\nYou're watching frame number: %u"), frameNum);						RECT rect;			SetRect(&rect, 10, 10, 0, 0);						pFont->DrawText(NULL, str, -1, &rect, DT_NOCLIP, D3DXCOLOR(1.0f,1.0f,1.0f,1.0f));						// Present to screen			pSwapChain->Present(1, 0);		}	}		// Release	pDevice->ClearState();	pFont->Release();	pRTV->Release();	pDevice->Release();	pSwapChain->Release();		UnregisterClass(wc.lpszClassName, hInstance);		return 0;}// Window procedureLRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {	switch(msg) {		// Window destroyed.		case WM_DESTROY:			PostQuitMessage(0);		break;	}		return DefWindowProc(hWnd, msg, wParam, lParam);}
Advertisement
Woot!!! Success :D. All my problems are resolved. The screen now shows the colour I expected it to and now I can render using the hardware device!

As far as forgetting the Present function... what can I say? DirectX 10 makes anything that was obvious in DirectX 9 obsolete so... not my fault :P.

Thanks to everyone that helped!
D3D9 requires a Present call too if you want to actually draw stuff to the screen :)

Anyway, good that you got it to work.

Niko Suni

This topic is closed to new replies.

Advertisement