DrawIndexedPrimitive error

Started by
2 comments, last by jollyjeffers 17 years, 4 months ago
I'm trying to switch to index primitives so i can do batched drawing but am have a hard time getting it to work, after solveing 176 odd errors im down to one, nothing is being drawn onto the screen. and the problem is DrawIndexedPrimitive() isn't working write. it keeps returning invalidcall. I'm sorry for the mess but heres what i have for the code that renders everything:

bool CZScene::Display()
{
	HRESULT result;

	VERTEX *vertices = NULL;

	// we keep running through the list until it's empty
	while (!m_buffer.empty())
	{

		// set the texture to be used for this pass
		m_texture = m_buffer.begin()->sprite->texture;

		// lock the buffer
		m_vertex_buffer->Lock (0, m_max_batch * sizeof(VERTEX),
                             (void **) &vertices, 0);

		// begin batching
		m_iterator = m_buffer.begin();
		while (m_iterator != m_buffer.end())
		{

			// make sure we don't go out of bounds of our buffer
			if (m_batch_size < m_max_batch)
			{
			// check if display object uses the same texture
			if (m_iterator->sprite->texture == m_texture)
			{
				// setup vertices 
				vertices[m_batch_size].colour = D3DCOLOR_ARGB(m_iterator->alpha,255,255,255);
				vertices[m_batch_size].pos    = D3DXVECTOR3(m_iterator->x, m_iterator->y, 0);
				vertices[m_batch_size].normal = D3DXVECTOR3(0,0,1);
				vertices[m_batch_size].u = m_iterator->sprite->tx1;
				vertices[m_batch_size].v = m_iterator->sprite->ty1;

				vertices[m_batch_size + 1].colour = D3DCOLOR_ARGB(m_iterator->alpha,255,255,255);
				vertices[m_batch_size + 1].pos    = D3DXVECTOR3(m_iterator->x + m_iterator->sprite->width, m_iterator->y, 0);
				vertices[m_batch_size + 1].normal = D3DXVECTOR3(0,0,1);
				vertices[m_batch_size + 1].u = m_iterator->sprite->tx2;
				vertices[m_batch_size + 1].v = m_iterator->sprite->ty1;

				vertices[m_batch_size + 2].colour = D3DCOLOR_ARGB(m_iterator->alpha,255,255,255);
				vertices[m_batch_size + 2].pos    = D3DXVECTOR3(m_iterator->x + m_iterator->sprite->width, m_iterator->y + m_iterator->sprite->height, 0);
				vertices[m_batch_size + 2].normal = D3DXVECTOR3(0,0,1);
				vertices[m_batch_size + 2].u = m_iterator->sprite->tx2;
				vertices[m_batch_size + 2].v = m_iterator->sprite->ty2;

				vertices[m_batch_size + 3].colour = D3DCOLOR_ARGB(m_iterator->alpha,255,255,255);
				vertices[m_batch_size + 3].pos    = D3DXVECTOR3(m_iterator->x, m_iterator->y + m_iterator->sprite->height, 0);
				vertices[m_batch_size + 3].normal = D3DXVECTOR3(0,0,1);
				vertices[m_batch_size + 3].u = m_iterator->sprite->tx1;
				vertices[m_batch_size + 3].v = m_iterator->sprite->ty2;

				// increased the amount of vertices that are batched
				m_batch_size += 4;

				// remove the display command
				m_iterator = m_buffer.erase(m_iterator);
			}
			else m_iterator++;
			}
			else m_iterator++;
		}

		// unlock the buffer
		m_vertex_buffer->Unlock();

		// set the texture to be used
		(*m_d3ddev)->SetTexture(0, m_texture->texture);
		
		// set stream source
		(*m_d3ddev)->SetStreamSource(0, m_vertex_buffer,

                (*m_d3ddev)->SetIndices(m_index_buffer);
												 0, sizeof(VERTEX));

		// draw what ever has been batched
		(*m_d3ddev)->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0,
                                      m_batch_size, 0, m_batch_size / 2); 
		if (result != D3D_OK)
			m_CError.Write("Error :: DrawIndexPrimitive()",true);

		m_CError.Write(m_batch_size,true);
		// reset batch size for next batch process
		m_batch_size = 0;
	}

	(*m_d3ddev)->Present(NULL, NULL, NULL, NULL);

	return true;
}



[Edited by - speedie on December 13, 2006 2:41:17 PM]
-----------------------------------------------The ZoloProject
Advertisement
Where is the index buffer? or the SetIndices call?

Also, why don't you enable the debug runtimes so it tells you what the problem is?
Sirob Yes.» - status: Work-O-Rama.
ok I added the SetIndices(m_index_buffer); right after the setstreamsource and i still have the same problem, And I don't know how to set the debug runtime, I just figure it was automatically there, cause that's what i installed.
-----------------------------------------------The ZoloProject
Quote:Original post by speedie
I don't know how to set the debug runtime, I just figure it was automatically there, cause that's what i installed.
The SDK will install it but you still need to enable it. Forum FAQ -> D3D #22: Using the debug runtimes.

The debug runtimes are usually very good at elaborating on error conditions. Once you've got a better description you can start to step through your code and inspect the individual variables and program state...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement