Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ACAC

Draw Primitive Failing ?

This topic is 5798 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

OK ive been trying to write a simple terrain generator, Ive got the basic class coded but there is a bug which makes DrawPrimative fail.... I have no idea why, Ive checked all the vertices data its fine i just dont know where to look next.
      

//a textured, 3d vertex

const DWORD FVF3D_TEX = (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);

class C3DTexVert 
{
public:
	float m_x,m_y,m_z;
	DWORD diffuse;
	float m_tu, m_tv;

	void set(float x, float y, float z, float u, float v, DWORD colour=0xFFFFFFFF)
	{
		m_x = x;
		m_y = y;
		m_z = z;
		
		m_tu = u;
		m_tv = v;
		
		diffuse = colour;
	}
};

//terrain code

CTerrain::CTerrain(int width, int depth)
{
	m_width = width;
	m_depth = depth;

	m_numPolys = ((m_width-1) * (m_depth-1))*2;
}

CTerrain::~CTerrain()
{
	delete pTextures;
	m_pVB->Release();
}

int CTerrain::GenerateTerrain(IDirect3DDevice8*pDevice)
{
	//first create the vertex buffer to

	//store the vertex data, this will

	//be used to render the terrain

	pDevice->CreateVertexBuffer(sizeof(C3DTexVert)*(m_width*m_depth),0,
												  FVF3D_TEX,
												  D3DPOOL_MANAGED,
												  &m_pVB);
	
	//create the array of vertices

	C3DTexVert *pVerts = new C3DTexVert[m_width * m_depth];

	int curIndex = 0;
	float stepX = 1.0f / 3.0f;
	float stepZ = 1.0f / 3.0f;
	//generate the vertices

	for(int z = 0; z < m_depth; z++)
	{
		for(int x = 0; x < m_width; x++)
		{
			//for each Z loop thru its X's

			//set the current vertex properties

			float XPos = x*1;
			float ZPos = z*1;
			float TexU = stepX * x;
			float TexV = stepZ * z;
			pVerts[curIndex].set(XPos,0,ZPos,TexU,TexV);

			curIndex++;
		}
	}

	VOID *pVertData;
	//copy the generated vertices over

	if(FAILED(m_pVB->Lock(0,sizeof(C3DTexVert)*(m_width * m_depth),(BYTE**)&pVertData,0))) 
	{
		MessageBox(NULL,"Lock Failed","Error",MB_OK);
	}
	memcpy(pVertData,pVerts, (m_width * m_depth)*sizeof(C3DTexVert));
	m_pVB->Unlock();

	pTextures = new CTextureCache();
	pTextures->LoadTexture("GalexLogo.jpg",10,pDevice);

	return 1;
}

void CTerrain::Render(IDirect3DDevice8*pDevice)
{
		if(pDevice->SetTexture(0,pTextures->GetTexture(10))!= D3D_OK)
		{
			MessageBox(NULL,"Set Texture Failed","Error",MB_OK);
		}
		if(pDevice->SetStreamSource(0,m_pVB,sizeof(C3DTexVert)!=D3D_OK))
		{
			MessageBox(NULL,"Set Stream Failed","Error",MB_OK);
		}
		if(pDevice->SetVertexShader(FVF3D_TEX)!=D3D_OK)
		{
			MessageBox(NULL,"Set Shader Failed","Error",MB_OK);
		}
		if(pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, m_numPolys)!=D3D_OK)
		{
			MessageBox(NULL,"Draw Primative Failed","Error",MB_OK);
		}
}
      
I have called it in between begin and end scene and presented it, and DrawPrimative is the only function that fails. Anyone? [edited by - ACAC on December 8, 2002 8:13:19 AM] [edited by - ACAC on December 8, 2002 8:17:40 AM]

Share this post


Link to post
Share on other sites
Advertisement
Well drawprimitive only returns two things, invalid param or d3d ok, and it certainly isnt d3d ok , so yup its INVALID PARAM

Share this post


Link to post
Share on other sites
Are you using the debug runtimes of D3D? And is the information level at maximum (in the DX control pannel thigny)?

DX usualy says what parameter is wrong when its an invalid parameter.

Share this post


Link to post
Share on other sites
I now see atleast 1 vertex =) i switched from debug to runtime and it worked fine! Thanks alot!

Share this post


Link to post
Share on other sites
No no no, you SHOULD use the Debug version of the runtime, then check the debug output of your application. D3D will put messages there telling you what you''re doing wrong.

You can Debug your project from Visual C++ by pressing F5.


Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

Share this post


Link to post
Share on other sites
It prints them to the debug output window in MSVC. Make sure you put the debug level at max for best effect.

The reason the the retail version works is that it doesn''t check if the parameters are correct. So if you e.g. pass an invalid range of vertices for a VB, it''ll happily draw areas that are outside the VB and crash the program, or at least mess up your screen. You''ll get different results on different 3D cards.

Share this post


Link to post
Share on other sites
OK i found it, this is what I get,

Direct3D8: (ERROR) :*** Exception in d:\builds\nt32_chk\multimedia\directx\dxg\d3d8\fe\vshader.cpp Line: 664

Direct3D8: (ERROR) :Stream 0 stride should match the stride, implied by the current vertex shader

Direct3D8: (ERROR) :DrawPrimitive failed.

First-chance exception in Libary.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.
Direct3D8: (ERROR) :*** Exception in d:\builds\nt32_chk\multimedia\directx\dxg\d3d8\fe\vshader.cpp Line: 664

Direct3D8: (ERROR) :Stream 0 stride should match the stride, implied by the current vertex shader

Direct3D8: (ERROR) :DrawPrimitive failed.


I kinda know what that means, but can somone please elabourate? because if you look at my code, the vertex shader I use is the same as the stride ( i think? )

Thanks

Share this post


Link to post
Share on other sites
Do you use MSVC ?

Is the code you''re trying to run EXACTLY as posted. i.e. does C3DTexVert have any virtual functions ?


Try logging "sizeof(C3DTexVert)" if it isn''t 24 (4+4+4+4+4+4), then there are extra bytes coming from _somewhere_ per vertex.

If the vertex class contained any other member data or virtual member functions, that would account for the extra data.

If you had RTTI enabled and it were being generated for your vertex class, that''d be another explanation.

As would compiler structure alignment, try wrapping the class definition in:

#pragma pack(push)
#pragma pack(1)
class C3dvertex... blah
#pragma pack(pop)

--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!