Ok. I have decided to try my hand at DX11. I'm starting from scratch here because the "empty project" provided by the SDK has a butt-load of crap that I don't want to use right now (just want to learn the basics). Until now I've been using only one .cpp file and all others were .h files. Each class had 2 .h files, one for the header info and the other for the functions. I know this is bad practice, but it was the only way I could control the compile order. I WANT TO CORRECT THIS! So here is my project as it stands:
Main.cpp:
globals.h:
#ifndef GLOBALS_H
#define GLOBALS_H
#include <windows.h>
#include <windowsx.h>
void Init3D(HWND hWnd);
void GameLoop(void);
void RenderFrame(void);
void ExitProgram(void);
float SCREEN_WIDTH =float(GetSystemMetrics( SM_CXSCREEN ));
float SCREEN_HEIGHT = float(GetSystemMetrics( SM_CYSCREEN ));
#include "Graphics.h"
#endif
Graphics.h:
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>
#pragma comment (lib, "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86/d3d11.lib")
#pragma comment (lib, "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86/d3dx11.lib")
#pragma comment (lib, "C:/Program Files (x86)/Microsoft DirectX SDK (June 2010)/Lib/x86/d3dx10.lib")
IDXGISwapChain *swapchain; // the pointer to the swap chain interface
ID3D11Device *dev; // the pointer to our Direct3D device interface
ID3D11DeviceContext *devcon; // the pointer to our Direct3D device context
void InitD3D(HWND hWnd); // sets up and initializes Direct3D
void CleanD3D(void); // closes Direct3D and releases memory
Graphics.cpp:
#include "globals.h"
void InitD3D(HWND hWnd)
{
// create a struct to hold information about the swap chain
DXGI_SWAP_CHAIN_DESC scd;
// clear out the struct for use
ZeroMemory(&scd, sizeof(DXGI_SWAP_CHAIN_DESC));
// fill the swap chain description struct
scd.BufferCount = 1; // one back buffer
scd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; // use 32-bit color
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; // how swap chain is to be used
scd.OutputWindow = hWnd; // the window to be used
scd.SampleDesc.Count = 4; // how many multisamples
scd.Windowed = TRUE; // windowed/full-screen mode
// create a device, device context and swap chain using the information in the scd struct
D3D11CreateDeviceAndSwapChain(NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
NULL,
NULL,
NULL,
D3D11_SDK_VERSION,
&scd,
&swapchain,
&dev,
NULL,
&devcon);
}
void CleanD3D()
{
// close and release all existing COM objects
swapchain->Release();
dev->Release();
devcon->Release();
}
The problem is that the compiler says that the stuff in globals.h is already defined:
Error 1 error LNK2005: "float SCREEN_WIDTH" (?SCREEN_WIDTH@@3MA) already defined in Grapgics.obj C:\Empty DX11 Project1\main.obj Empty DX11 Project1
Error 2 error LNK2005: "struct ID3D11DeviceContext * devcon" (?devcon@@3PAUID3D11DeviceContext@@A) already defined in Grapgics.obj C:\Empty DX11 Project1\main.obj Empty DX11 Project1
Error 3 error LNK2005: "struct ID3D11Device * dev" (?dev@@3PAUID3D11Device@@A) already defined in Grapgics.obj C:\Empty DX11 Project1\main.obj Empty DX11 Project1
Error 4 error LNK2005: "struct IDXGISwapChain * swapchain" (?swapchain@@3PAUIDXGISwapChain@@A) already defined in Grapgics.obj C:\Empty DX11 Project1\main.obj Empty DX11 Project1
Error 5 error LNK2005: "float SCREEN_HEIGHT" (?SCREEN_HEIGHT@@3MA) already defined in Grapgics.obj C:\Empty DX11 Project1\main.obj Empty DX11 Project1
Error 6 error LNK1169: one or more multiply defined symbols found C:\Empty DX11 Project1\Release\DX11Test.exe Empty DX11 Project1
Doesn't the "#ifndef" stuff work? Am I using it wrong? HOW DO I GET IT TO "DEFINE" ONLY ONCE?