Jump to content
  • Advertisement
Sign in to follow this  

Beginners #define vertex problem

This topic is 4569 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 all, how are we all? I hope you guys might be able to help me out with this, I'm just starting out with direct3d programming and so I'm editing a bit of code from toymaker.info, I'm just trying to get a simple triangle showing on the screen splitting who bits of code so i have a dedicated direct3d initialisation sequence. Starting in the main.cpp:

#include <windows.h>
#include "vis_setup.h"

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

// The main entry point of our Windows program
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
	// Create and fill out a window class structure

[... more windows stuff going on here]
So thats the initial start up, moving on the vis_seup.h:
#include <d3dx9.h>		// D3DX helper functions


struct TMyVertex
D3DXVECTOR3 p;	// Vertex position	
D3DCOLOR c;	// Vertex colour

class vis_setup

	bool InitialiseDirect3D(HWND hWnd);
	bool CreateTriangle();
And when i want to use MYVERTEX_FVF i do it like this:
bool vis_setup::CreateTriangle()
	HRESULT hr=gD3dDevice->CreateVertexBuffer(3*sizeof(TMyVertex),D3DUSAGE_WRITEONLY, MYVERTEX_FVF,
			D3DPOOL_MANAGED, &gVertexBuffer, NULL );
	if (FAILED(hr))
		return false;

	// Lock and fill
	TMyVertex* pVertices=NULL;
This all looks alright to me but when i compile I get errors like this:
Triangle fatal error LNK1169: one or more multiply defined symbols found
Triangle error LNK2005: "struct IDirect3DVertexBuffer9 * gVertexBuffer" (?gVertexBuffer@@3PAUIDirect3DVertexBuffer9@@A) already defined in main.obj
I dunno whats up with it, I've never being exactly confident with #defines (My c++ skills need ALOT of work) but I can't really see whats wrong with this. Anyone know?

Share this post

Link to post
Share on other sites
First, make sure to use the source tags.

You are defining a global variable: which is getting included in multiple files. One way you might get around that is, putting your variables in a class/struct.


struct globals

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!