Jump to content
  • Advertisement


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


Indexed verts

This topic is 5583 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

I´m trying to use indexed verts to render my terrain. THis is the code I use to load the index with.
		p_iD3DDevice9->CreateIndexBuffer(128*6*128*sizeof(int), D3DUSAGE_WRITEONLY,

	short *p_Indices;
	p_iD3DIndexBuffer9->Lock( 0,                 //Fill from start of the buffer.

                      		     sizeof(short)*128*128, // Size of the data to load.

                      		     (VOID**)&p_Indices, // Returned index data.

                      		     0 );         // Send default flags to the lock.


	for(int y = 0;y < TERRAIN_Z;++y)
		for(int x = 0;x < TERRAIN_X;++x)
			*p_Indices++ = x + y * (TERRAIN_X + 1);					//v1

			*p_Indices++ = x + 1 + y * (TERRAIN_X + 1);					//v2

			*p_Indices++ = x + 1 + (y + 1) * (TERRAIN_X + 1);				//v4

			*p_Indices++ = x + y * (TERRAIN_X + 1);					//v1

			*p_Indices++ = x + 1 + (y + 1) * (TERRAIN_X + 1);				//v4

			*p_Indices++ = x + (y + 1) * (TERRAIN_X + 1);					//v3



And this is what I do when I render
	p_iD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255),1.0f,0);

	SetupMatrices(); //Setup camera 

	// Set the location source of our vertex input stream

	p_iD3DDevice9->SetStreamSource( 0, p_iD3DVertexBuffer9,0, sizeof(CUSTOMVERTEX));

	// Set the default vertex shader to our #defined vertex


	// Set the location of our index information to our Index Buffer

	if(FAILED(p_iD3DDevice9->SetIndices( p_iD3DIndexBuffer9 )))
		MessageBox(NULL,"Couldn´t set indices", "Error", MB_OK);
		return false;




	RECT rRect;
	rRect.left = 0;
	rRect.top  = 0;
	rRect.right = 480;
	rRect.bottom = 480;

	//Render only from and to the given rect

Sadly it doesn´t display my primitives at all. When I just use the vertexbuffer it displays them with no probs (using pointlist).

Share this post

Link to post
Share on other sites
You've created an index buffer that can contain 196608, 16 bit indices. You then locked and loaded the first 16384 indices in the buffer in your loops. Now you're trying to draw 131072 triangles, each of which takes 3 indices. What's wrong with this picture?

Have you upped the debug level via the DX Control Panel applet and looked for debug messages being output to the debugger when you run this app?

Have you tested the return value from DrawIndexedPrimitive when no triangles show up?

How many vertices are in your vertex buffer? According to the parameters you're passing to DrawIndexedPrimitive it would have to, at a minimum, contain 786432 vertices.

What are the values of TERRAIN_X and TERRAIN_Z?

Are you certain that the values you're stuffing into the index buffer will fit in 16 bits? From the MinIndex and NumVertices you're passing to DrawIndexedPrimitive (assuming those are correct), I'd doubt it. Also, you've typed p_Indices as a pointer to short data - it should be unsigned short.

You might want to check MaxVertexIndex and MaxPrimitiveCount in the caps bits to make certain you aren't asking your card to render something it cannot do.

Good luck!

To head off a lot of questions about DrawIndexedPrimitive parameters and what they mean, please read this: http://tomsdxfaq.blogspot.com/2002_05_01_tomsdxfaq_archive.html#77028718

[edited by - don on July 3, 2003 12:53:15 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!