1 Replies - 4042 Views - Last Post: 23 June 2006 - 10:19 PM Rate Topic: -----

#1 -pete-  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 07-June 06

Beginners #define vertex buffer Direct3D problem

Posted 07 June 2006 - 08:31 PM

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
	WNDCLASS wcex;
	ZeroMemory(&wcex,sizeof(WNDCLASS));

[... more windows stuff going on here]



So thats the initial start up, moving on the vis_seup.h:

#include <d3dx9.h>		// D3DX helper functions

LPDIRECT3D9 gD3dObject=NULL;
LPDIRECT3DDEVICE9 gD3dDevice=NULL;
LPDIRECT3DVERTEXBUFFER9	gVertexBuffer=NULL;

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

#define MYVERTEX_FVF (D3DFVF_XYZ | D3DFVF_DIFFUSE)
class vis_setup
{
public:

	
	vis_setup(void);
	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?

Is This A Good Question/Topic? 0
  • +

Replies To: Beginners #define vertex buffer Direct3D problem

#2 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 818
  • Joined: 22-November 04

Re: Beginners #define vertex buffer Direct3D problem

Posted 23 June 2006 - 10:19 PM

Ok, I've never done Direct3D, but I know a little C++ and OpenGL. If my memory servers me best your vertex should probably have a value greater than null to have your object visible. Try changing this value:

TMyVertex* pVertices=NULL;


If that doesn't work try looking here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1