Program from book is not working
I just began reading the book Beginning DirectX 10 Game Programming and when I tried to compile the program from the second chapter I get an array of error. Here are the first few
Code:
error: '__out' has not been declared
error: expected ',' or '...' before '*' token
error: '__in' has not been declared
I have included the library file to my project and don't know what the problem is. Here is my code.
Code:
//Include the Windows header file, needed for all windows application'
#include <windows.h>
#include <tchar.h>
#include <d3d10.h>
#include <d3dx10.h>
HINSTANCE hInst;
HWND wndHandle;
int width = 640;
int height = 480;
//Direct3D global variables
ID3D10Device* pD3DDevice = NULL;
IDXGISwapChain* pSwapChain = NULL;
ID3D10RenderTargetView* pRenderTargetView = NULL;
//Forward declarations
bool InitWindow(HINSTANCE hInstance, int width, int height);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
//InitDirect3D
bool InitDirect3D(HWND hWnd, int width, int height)
{
//Create and clear the DXGI_SWAP_CHAIN_DESC
DXGI_SWAP_CHAIN_DESC swapChainDesc;
ZeroMemory(&swapChainDesc, sizeof(swapChainDesc));
//Fill in the needed values
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Width = width;
swapChainDesc.BufferDesc.Height = height;
swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 1;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.OutputWindow = hWnd;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.Windowed = TRUE;
//Create the D3D device and the swap chain
HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION,
&swapChainDesc, &pSwapChain, &pD3DDevice);
//Error checking. Make sure the device context was created
if(hr != S_OK)
{
return false;
}
//Get the back buffer from the swap chain
ID3D10Texture2D *pBackBuffer;
hr = pSwapChain->GetBuffer(0, _uuidof(ID3D10Texture2D), (LPVOID*)&pBackBuffer);
if(hr != S_OK)
{
return false;
}
//Create the render target view
hr = pD3DDevice->CreateRenderTargetView(pBackBuffer, NULL, &pRenderTargetView);
//release the back buffer
pBackBuffer->Release();
//Make sure the render target view was created succesfuly
if(hr != S_OK)
{
return false;
}
//Set the render target
pD3DDevice->OMSetRenderTargets(1, &pRenderTargetView, NULL);
//Create and sett the viewport
D3D10_VIEWPORT viewPort;
viewPort.Width = width;
viewPort.Height = height;
viewPort.MinDepth = 0.0f;
viewPort.MaxDepth = 1.0f;
viewPort.TopLeftX = 0;
viewPort.TopLeftY = 0;
pD3DDevice->RSSetViewPort(1, &viewPort);
return true;
}
//Render
void Render()
{
if(pD3DDevice != NULL)
{
//Clear the target buffer
pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f));
//All the drawing will go here
//display the next item in the swap chain
pSwapChain->Present(0, 0);
}
}
//SutdownDirect3D
void ShutDownDirect3D()
{
//Release the renderTarget
if(pRenderTargetView)
{
pRenderTargetView->Release();
}
//Release the swapchain
if(pSwapChain)
{
pSwapChain->Release();
}
//Release the D3D Device
if(pD3DDevice)
{
pD3DDevice->Release();
}
}
//This si winmain, the main entry point for Windows Applications
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
//Initialize the window
if(!InitWindow(hInstance, width, height))
{
return false;
}
if(!InitDirect3D(mainhWnd, width, height))
{
return 0;
}
//Main message loop
MSG msg = {0};
while(WM_QUIT != msg.message)
{
while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) == TRUE)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
//Call the render function
Render();
}
ShutDownDirect3D();
return (int)msg.wParam;
}
//Init window
bool InitWindow(HINSTANCE hInstance, int width, int height)
{
WNDCLASSEX wcex;
//Fill in the WNDCLASSEX structure. This describes how the window will look to the system
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = (WNDPROC)WndProc;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = 0;
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = TEXT("DirectXExample");
wcex.hIconSm = 0;
RegisterClassEx(&wcex);
//Register the window
RECT rect = { 0, 0, width, height};
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE);
//Create the window from the class above
wndHandle = CreateWindow(TEXT("DirectXExample"), TEXT("DirectXExample"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT,
rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, hInstance, NULL);
if(!wndHandle)
{
return false;
}
//Displays the window on the screen
ShowWindow(wndHandle, SW_SHOW);
UpdateWindow(wndHandle);
return true;
}
//WndProc
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
//Check any available messages from the queue
switch(message)
{
case WM_KEYDOWN:
switch(wParam)
{
//Check if the user hit the Escape key
case VK_ESCAPE:
PostQuitMessage(0);
break;
}
//Always return the message to the default window procedure for further processing
return DefWindowProc(hWnd, message, wParam, lParam);
}
}
Thanks