// Initialize four vertices
CUSTOMTILEVERTEX vertices[] =
{
{ 0.0f, 0.0f, 0.0f, D3DCOLOR_XRGB(255, 0,255) }, // x, y, z, color
{ 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB( 0,255, 0) },
{ 3.0f, 3.0f, 0.0f, D3DCOLOR_XRGB( 0,255,255) },
{ 3.0f, 0.0f, 0.0f, D3DCOLOR_XRGB( 0,255, 0) }
};
// Create the vertex buffer. Here we are allocating enough memory
// (from the default pool) to hold all our 3 custom vertices. We also
// specify the FVF, so the vertex buffer knows what data it contains.
if( FAILED( m_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMTILEVERTEX),
D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMTILEVERTEX,
D3DPOOL_DEFAULT, &m_pVertexBuffer , NULL ) ) )
{
MessageBox(NULL, "Couldn't create vertex buffer!!", "ERROR initializing VertexBuffer", MB_ICONERROR);
return E_FAIL;
}
// Now we fill the vertex buffer. To do this, we need to Lock() the VB to
// gain access to the vertices. This mechanism is required because vertex
// buffers may be in device memory.
VOID* pVertices;
if( FAILED( m_pVertexBuffer->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) ){
MessageBox(NULL, "Couldn't lock vertex buffer!!", "ERROR working with VertexBuffer", MB_ICONERROR);
return E_FAIL;
}
memcpy( pVertices, vertices, sizeof(vertices) );
m_pVertexBuffer->Unlock();
// creating an indexbuffer
if (FAILED(m_pd3dDevice->CreateIndexBuffer(
6*sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&m_pIndexBuffer,
NULL))) {
MessageBox(NULL, "Couldn't create index buffer!!", "ERROR working with IndexBuffer", MB_ICONERROR);
return E_FAIL;
}
// specifying triangles
// 1-2
// |/|
// 0-3
// top-left
WORD indices[] = {
{0}, {1}, {2},
{0}, {2}, {3}
};
VOID* pIndex;
if(SUCCEEDED(m_pIndexBuffer->Lock(0, sizeof(indices), (void**)&pIndex, 0))){
memcpy( pIndex, indices, sizeof(indices) );
m_pIndexBuffer->Unlock();
return S_OK;
}
return E_FAIL;
if(SUCCEEDED(BeginRender())){
if(D3DERR_INVALIDCALL == (m_pd3dDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(CUSTOMTILEVERTEX)))){
MessageBox(NULL, "SetSteamSource failed!!!", "ERROR", MB_ICONERROR);
EndRender();
return E_FAIL;
}
if(D3DERR_INVALIDCALL == (m_pd3dDevice->SetFVF(D3DFVF_CUSTOMTILEVERTEX))){
MessageBox(NULL, "SetFVF failed!!!", "ERROR", MB_ICONERROR);
EndRender();
return E_FAIL;
}
if(D3DERR_INVALIDCALL == (m_pd3dDevice->SetIndices(m_pIndexBuffer))){
MessageBox(NULL, "SetIndices failed", "ERROR", MB_ICONERROR);
EndRender();
return E_FAIL;
}
if(D3DERR_INVALIDCALL == (m_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLESTRIP, 0, 0, 4, 0, 2))){
MessageBox(NULL, "DrawPrimitive failed!!!", "ERROR", MB_ICONERROR);
EndRender();
return E_FAIL;
}
}
[SOLVED]Index Buffer trouble
hi
I'm having some trouble rendering a quad composed of two triangles in a triangle strip. I have been looking on google after the error i get when debugging:
Direct3D9: (ERROR) :No valid index stream currently set. DrawIndexedPrimitive failed.
What does this mean? I have used the function SetIndices before I'm calling the DrawIndexedPrimitive method and it dosen't report any error. Neither does any other of the relevant function calls(what I believe is relevant - maybe tou can prove otherwise :) ).
I'll post the code
Can anybody spot what the problem can be?
regards
thallish
[Edited by - thallish on July 28, 2005 4:39:19 AM]
hi
I tried the managed memory and that didn't make any difference ;-). Also tried to draw the quad without using indices and that works like it should. It's only when i try to draw indexed primitives i get the problem unfortunately.
EDIT: The problem could be somewhere else i just havn't got the slightest idea where
regards
thallish
I tried the managed memory and that didn't make any difference ;-). Also tried to draw the quad without using indices and that works like it should. It's only when i try to draw indexed primitives i get the problem unfortunately.
EDIT: The problem could be somewhere else i just havn't got the slightest idea where
regards
thallish
I totally don't expect this to change anything, but perhaps you could use D3DLOCK_DISCARD when you lock your buffers, since you create them with D3DUSAGE_WRITEONLY. But if that were a problem (which I doubt), I'd expect it to fail to lock, and thus you'd have error results and stuff like that.
It almost sounds as if SetFVF(NULL) is being called, as if the FVF constant is 0. I don't know what that would do, but you could call SetFVF(NULL) and see if you get the same error, then chase down why the constant is 0...
EDIT: But you said it works for a DrawPrimitive call, so that shouldn't matter. Nevermind. Just for grins though, can you post your FVF define?
EDIT: But you said it works for a DrawPrimitive call, so that shouldn't matter. Nevermind. Just for grins though, can you post your FVF define?
yep here is my vertex struct and my FVF
Agony it did exactly what you said. Error with locking. Think that's because i'm using a static buffer
regards
thallish
// A structure for our custom vertex typestruct CUSTOMTILEVERTEX{ FLOAT x, y, z; // The transformed position for the vertex D3DCOLOR color; // The vertex color};// Our custom FVF, which describes our custom vertex structure#define D3DFVF_CUSTOMTILEVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)
Agony it did exactly what you said. Error with locking. Think that's because i'm using a static buffer
regards
thallish
Perhaps the problem is in BeginRender()? What does it do? I also can´t point any problem in the code you posted, and since you don´t seem to be getting an error with all that locking, memcpy and unlocking stuff, both buffers seem to be just fine. Did you try to test whether m_pIndexBuffer is NULL or not? The error message quite bluntly states you don´t have an index stream set, though I´d say you´d have if m_pIndexBuffer really points to one?
maybe this is all wrong, but shouldn't there be four indices to render a triangle strip and not 6?
Hi there
As I have understood, I need 6 indices and 4 vertices, Just for the fun of it I've tried to make it 4. Still no go.
My begin render simply contains the clear call and BeginScene(), if any of them fails, BeginRender() fails.
And i found out the freaking problem with the error. I got so worked up in looking at the methods that i totally forgot to check out where they get called and sure enough there the problem occured. Stupid me!! Sleeping on it helped.
this check : if(SUCCEEDED(render.InitVB()) && render.InitIB())
should have been: if(SUCCEEDED(render.InitVB()) && SUCCEEDED(render.InitIB()))
Ok now that's settled, there is only ONE TRIANGLE being drawn, the first on, with the order specified in the code.
Why is that? I believe it has something to do with the order of drawing. But the order i've specified dosen't work. I've tried to draw the last triangle in the order : 3, 0, 2 and 3, 0, 1 and the exact same triangle appears, which it shouldn't as i understand it.
Can someone shed some light on this matter?
regards
thallish
Quote:Original post by thehan
maybe this is all wrong, but shouldn't there be four indices to render a triangle strip and not 6?
As I have understood, I need 6 indices and 4 vertices, Just for the fun of it I've tried to make it 4. Still no go.
Quote:Original post by matches81
Perhaps the problem is in BeginRender()?
My begin render simply contains the clear call and BeginScene(), if any of them fails, BeginRender() fails.
And i found out the freaking problem with the error. I got so worked up in looking at the methods that i totally forgot to check out where they get called and sure enough there the problem occured. Stupid me!! Sleeping on it helped.
this check : if(SUCCEEDED(render.InitVB()) && render.InitIB())
should have been: if(SUCCEEDED(render.InitVB()) && SUCCEEDED(render.InitIB()))
Ok now that's settled, there is only ONE TRIANGLE being drawn, the first on, with the order specified in the code.
Why is that? I believe it has something to do with the order of drawing. But the order i've specified dosen't work. I've tried to draw the last triangle in the order : 3, 0, 2 and 3, 0, 1 and the exact same triangle appears, which it shouldn't as i understand it.
Can someone shed some light on this matter?
regards
thallish
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement