Archived

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

a small help with DrawIndexedPrimitive please ;-)

This topic is 5145 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, I've a problem with DrawIndexedPrimitive, but perhaps the cause is in the index buffer. I've made a vertex buffer of 32 vertices in this way:
1___3___5___7..........29___31
|\  |\  |\  |		|\  |
| \ | \ | \ |           | \ |
|__\|__\|__\|...........|__\|
0   2   4   6          28   30      
 
It is a trianglestrip, so I can render it with this function
void CTerrain::Render()
{
	m_pd3dDevice->SetStreamSource( 0, m_pTerrainVB,0, sizeof(CUSTOMVERTEX) );
	m_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
	m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP , 0, 32-2 );
}
so far so good.... this works fine. Then I've added an index buffer.... from here to the end, IMO there is the problem. This is my index buffer:
   
WORD	*pIndices;

// Create the Index Buffer

m_pd3dDevice->CreateIndexBuffer( 32*sizeof(WORD),D3DUSAGE_WRITEONLY, D3DFMT_INDEX16,
	                                        D3DPOOL_DEFAULT. &m_pTerrainIB, NULL )       

m_pTerrainIB->Lock(   0, 0,	(void**)&pIndices, 0 )

// vertex buffer is already sorted.. so I copy its order.(it's a test)

for( int x = 0; x < 32; x++ )	pIndices[x] = (WORD)x;

m_pTerrainIB->Unlock();
and I would like draw it with:
   
void CTerrain::Render()
{
	m_pd3dDevice->SetStreamSource( 0, m_pTerrainVB,0, sizeof(CUSTOMVERTEX) );
	m_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
        m_pd3dDevice->SetIndices( m_pTerrainIB); <----- set my index buffer

	m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP , 0, 0, 32,0, 32-2);
	// 32 are my vertices, 30 are my triangle because I use D3DPT_TRIANGLESTRIP flag.. is right?

}
I've do differents tests... with differents number of verticies but nothing is rendered... Can you help me? thanks very much =)[/source] [edited by - BlueChip on November 12, 2003 11:06:16 AM]

Share this post


Link to post
Share on other sites
Define "nothing is rendered." Do you mean blackness? Change the back buffer clear color to white, and see if black triangles are drawn. If so, turn off lighting, check that vertex colors are being set properly, etc. What's your FVF? Maybe you have it in the wrong order. Have you set up your camera to make sure you can see the terrain? etc. Why are you casting in "pIndices[x] = (WORD)x;"? Maybe that's messing up the memory.

edit: Sorry for the vagueness and lack of helpfulness, but I didn't see any posts and thought a crap post might be better than nothing.

[edited by - psykr on November 12, 2003 5:42:41 PM]

Share this post


Link to post
Share on other sites
psykr, your aid is appreciated

but with "nothing is rendered." I say that no triangles are rendered.

quote:

Why are you casting in "pIndices[x] = (WORD)x;"? Maybe that''s messing up the memory.


it is only a copy&paste, I''ve drop the cast, but nothing is change.


My FVF is simple:

struct CUSTOMVERTEX
{
float x, y, z;
DWORD color;
float tu, tv; // The texture coordinates.
};

// Custom FVF, which describes the custom vertex structure.
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1)


byezzz.. and thanks...

Other idea? ^__^

Share this post


Link to post
Share on other sites
Have you tried running your app with the D3D debug runtime and looked for debug messages that would indicate a problem?

Have you looked at the return values of each of the API calls you''re making to ensure that they have succeeded?

Could this be a driver problem? Have you tried to run your code using the reference rasterizer instead of the HAL device?

Share this post


Link to post
Share on other sites
hi...
quote:

Have you tried running your app with the D3D debug runtime and looked for debug messages that would indicate a problem?


there aren't error messages ....
quote:

Have you looked at the return values of each of the API calls you're making to ensure that they have succeeded?


yes... I've added

if( FAILED (m_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP , 0, 0, 32,0, 32-2)))
{
MessageBox( NULL, "DrawIndexedPrimitive error.", "error",MB_ICONERROR|MB_OK );
return;
}

but the message doen't appear .. so DrawIndexedPrimitive return D3D_OK...

quote:

Could this be a driver problem? Have you tried to run your code using the reference rasterizer instead of the HAL device?


mmmmmmmmm no.. about it, I'm enought sure...

Now.....
after many tests, my vertex buffer ( make like in the 1st topic) doesn't render nothing if I call

void CTerrain::Render(){ m_pd3dDevice->SetStreamSource( 0, m_pTerrainVB,0, sizeof(CUSTOMVERTEX) ); m_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); m_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP , 0, 32-2 );}


Why?!?! It's too much simple for to have errors...

I feel so bad...
help please

[edited by - BlueChip on November 13, 2003 2:04:13 PM]

Share this post


Link to post
Share on other sites
last clue......

In my render() method (with vertex buffer only), now I''ve added
m_pd3dDevice->SetTransform(D3DTS_WORLD, &m_WorldMatrix);
}

I had forgotten it and it works again...

then I''ve added the same line in render() method (with VB and Index Buffer) but It doesn''t work again... Why?

Is this a useful clue?

Share this post


Link to post
Share on other sites
You might consider using ProcessVertices as a debugging aid. That way you could transform and light the vertices and then look at the values in the destination vertex buffer to get a better idea of what is going on. That should be about 10 mins work and will certainly narrow things down.

From the last bit of info you posted, there''s nothing I can do to help you without looking at all of your code.

Share this post


Link to post
Share on other sites
quote:

You might consider using ProcessVertices as a debugging aid. That way you could transform and light the vertices and then look at the values in the destination vertex buffer to get a better idea of what is going on. That should be about 10 mins work and will certainly narrow things down.


I'll try ... thanks
quote:

From the last bit of info you posted, there's nothing I can do to help you without looking at all of your code.


If you want see my code, you can download it here... there is only the code that doesn't work... without other useless code..

indexbuffer.zip

[edited by - BlueChip on November 14, 2003 12:37:29 PM]

Share this post


Link to post
Share on other sites
You need to change the line:

WORD pIndices[32];
to
WORD *pIndices;

in your create function, then it works. It''s because when you lock a buffer, D3D allocates space for the buffer and tries to set the pointer to point to that space. But because you''ve defined the pointer as an array, it cannot set it to point to the new space.

Have fun

---------------------------------------

Let''s struggle for our dream of Game!

http://andrewporritt.4t.com

Share this post


Link to post
Share on other sites