Archived

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

Sheep

strange Present(...) effect...

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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();
}

Share this post


Link to post
Share on other sites
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;

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Make sure renderstates are set up correctly (ie: lighting).
Make sure you actually are filling your vertexbuffers with something.
Make sure your view matrix allows you to see the vertices.
Make sure you are not culling your triangles. Set culling to none.
Make sure there are no warnings from D3D. Set debug output level to maximum.
Make sure your look from point is not in the plane of your geometry.
Try clearing the scene with a different color.
Make sure your projection matrix is set up correctly.
Try copying your vertex generation code in one of SDK samples, and see if their drawing code draws your data.
Alternatively, use their vertex generation code and your drawing code, and try setting their renderstates.

Share this post


Link to post
Share on other sites