strange Present(...) effect...

Started by
9 comments, last by Sheep 22 years, 2 months ago
Hello everone. So I am writing this little terrain generator and when I finally think it will work, when I run it, blocks of green and purplish/pinkish move up the screen. I dont know if this is what I am drawing or if Present(NULL, NULL, NULL, NULL) is doing it....any ideas? Thanks.
Advertisement
The pink and green is annoying, isn''t it?

This means that the call to DrawPrimitive has failed. Or at least one of your calls has failed.

I suggest you load up the Debug DirectX drivers and run the program through the MSVC debugger, and check the debug output. There''ll be some info in there somewhere
Your right! The debugger says this:
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.

Of course, I have no clue what this means. I am using this function to what should be the terrain:

  void CTerrain::Draw(LPDIRECT3DDEVICE8 m_pd3dDevice){	m_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,					   D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0);	if(SUCCEEDED(m_pd3dDevice->BeginScene()))	{		m_pd3dDevice->SetStreamSource(0, m_pVB, sizeof(CVertex));		m_pd3dDevice->SetVertexShader(D3DFVF_CVertex);		m_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 100);	}	m_pd3dDevice->EndScene();}  
Can you post the definition of D3DFVF_CVertex and your CVertex struct?
Sure...here is the CVertex class:
  class CVertex{public:	CVertex(float x, float y, float z, float tu, float tv, float r, float g, float b);	CVertex();	float m_x, m_y, m_z;			// x, y, and z coordinates	float m_tu, m_tv;				// texture coordinates	float m_r, m_g, m_b;			// color};  


The definition of D3DFVF_CVertex looks like
const DWORD D3DFVF_CVertex= D3DFVF_XYZ | D3DFVF_TEX1 | D3DFVF_DIFFUSE;
A diffuse color is a DWORD value, get rid of the 3 floats and replace with D3DCOLOR. Also, if you are specifying 100 as the number of primitives, that may mean up to 300 polygons, is that what you want? Finally, the order of vertex data should be XYZ, Diffuse, Texture coordinates:

float x, y, z;
D3DCOLOR Diffuse;
float u, v;


Jim Adams
Ahhh....a DWORD...very interesting...Im going to go try that. Also, I have no clue how many primitives to draw....is there same way of figuring out how? Also, if I pass in 3 different values for RGB color, how would I take all of it and store it in the D3DCOLOR? THanks.
Well, your suggestion worked Thanks alot. Now I just need to figure out why I cant see anything...If I used the code I showed and the vertex buffer was set up correctly, should I be able to see anything? THanks again.
Your ordering was also wrong in that vertex definition. For an untransformed, colored, textured vertex, the order should be like so:

float x, y, z;
D3DCOLOR clr;
float tu, tv;

Check the MSDN for the ordering rules between all the possible vertex component.
-- Eric
Anybody?

This topic is closed to new replies.

Advertisement