Sign in to follow this  

C++ avoiding multiple declarations problem.

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, I've just joined the forum so apologies for starting with what's probably a dumb question, but repeated googleing hasn't supplied an answer. I'm still getting multiple declaration errors as soon as I include the header file in more than one cpp file, despite the ifndef structure. What am I doing wrong?

_______________________________
#ifndef MOD02
#define MOD02
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

// include the basic windows header files and the Direct3D header files
#include <windows.h>
#include <windowsx.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dx10.h>

// include the Direct3D Library file
#pragma comment (lib, "d3d11.lib")
#pragma comment (lib, "d3dx11.lib")
#pragma comment (lib, "d3dx10.lib")

// define the screen resolution
#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600

// global declarations
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
ID3D11RenderTargetView *backbuffer; // the pointer to our back buffer
ID3D11InputLayout *pLayout; // the pointer to the input layout
ID3D11VertexShader *pVS; // the pointer to the vertex shader
ID3D11PixelShader *pPS; // the pointer to the pixel shader
ID3D11Buffer *pVBuffer; // the pointer to the vertex buffer

// a struct to define a single vertex
struct VERTEX{FLOAT X, Y, Z; D3DXCOLOR Color;};

// function prototypes
void InitD3D(HWND hWnd); // sets up and initializes Direct3D
void RenderFrame(void); // renders a single frame
void CleanD3D(void); // closes Direct3D and releases memory
void InitGraphics(void); // creates the shape to render
void InitPipeline(void); // loads and prepares the shaders

// the WindowProc function prototype
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

#endif
_________________________
A couple of other questions:

How do I open a new shader file in visual studio 2010? I've got by so far by using the file provided in a microcsoft example.

What's the difference between a ".fx" and a ".hlsl" file?

yours gratefully Rich

Share this post


Link to post
Share on other sites
The problem are the global variables. This article explains why it's a problem and how to solve it.

BTW, you're defining the screen width and height twice, which is not an error but is unnecessary.

Share this post


Link to post
Share on other sites
Quote:
Original post by Gage64
The problem are the global variables. This article explains why it's a problem and how to solve it.

BTW, you're defining the screen width and height twice, which is not an error but is unnecessary.

Ah cheers, yes problem solved and a useful article. I noted it says that macro's have been depreciated from C. A good thing in my opinion as their main purpose seemed to be to make a programmer unsackable as they could so easily make code unfollowable.

Does anyone have an answer to my two other questions?

Share this post


Link to post
Share on other sites
Quote:
What's the difference between a ".fx" and a ".hlsl" file?

Being a bit pedantic, both are just file extensions. What those extensions may imply about the contents of the file may depend on the application you're using.

As far as I know, there's no "standard" that requires files with either extension to have a particular type of content.

Some common usages, however, are that "hlsl" files contain shader code only. "fx" files contain shader code and effect information such as techniques, passes, renderstate settings, etc.

Share this post


Link to post
Share on other sites

This topic is 2636 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this