Skip to main content
GameDev.net gamedev.net
🔒 Locked

DrawIndexedPrimitive Help !

Started by TalonSnow Feb 19, 2003 at 10:22 PM 1 replies 250+ views
Original Post
TalonSnow
TalonSnow
This is a repost, as Code has changed somewhat and didnt want to display whole class, just the relevant parts where the error could be coming from. Basically after creating a debug file filled with states of variables at the time it fails, I cannot see how it is failing and even hand checking the variables, seems it is perfect order and should work. Any Help would be appreciated! relative code: Setting up Vertex Array:
  
	// creatign the vertex's from array

	int	z		=	BitmapHeight/2;			// starting z position so the land will be centered at (0,0,0)

	float	TexX;							// texture coords

	float	TexY;							// texture coords

	int	ArrayIndex	=	0;				// index into the array


	for(int IndexY=0;IndexY<BitmapHeight;IndexY++)
	{
		TexY=(float)((float)IndexY/(float)BitmapHeight);						// gives us a range 0-1 for texture coords, y axis

		for(int IndexX=0;IndexX<BitmapWidth;IndexX++)
		{
			int x = IndexX-(BitmapWidth/2);								// centers map along the x axis at 0

			TexX=(float)((float)IndexX/(float)BitmapWidth);						// gives us a range 0-1 for texture coords, x axis

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].x=(float)x;					// records the x pos for vertex [y,x]

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].y=(float)HeightArray[IndexY][IndexX];		// records the y pos for vertex [y,x]

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].z=(float)z;					// records the z pos for vertex [y,x]

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].tu=TexX;					// records the texture x pos

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].tv=TexY;					// records the texture y pos

			int GreyScaleColor=HeightArray[IndexY][IndexX]*HeightMod;				// gives us initial height value (0-255) for [y,x]

			// sets diffuse color to lighten higher points and darken lower points, simulating fake lighting

			m_vTerrain[(IndexY*BitmapWidth)+IndexX].VColor=D3DCOLOR_ARGB(255, GreyScaleColor, GreyScaleColor, GreyScaleColor);
		}
		z--;							// de-incrementing z, to bring z axis from max z to min z

	}
  
Setting up Index Array
  
	for(int IndexY=0;IndexY<(BitmapHeight-1);IndexY++)
	{
		for(int IndexX=0;IndexX<(BitmapWidth-1);IndexX++)
		{
			IndexList[  ArrayIndex]=(IndexY*BitmapWidth)+IndexX;			// top left of 1st triangle

			IndexList[ArrayIndex+1]=((IndexY+1)*BitmapWidth)+(IndexX+1);		// bottom right of 1st triagle

			IndexList[ArrayIndex+2]=((IndexY+1)*BitmapWidth)+IndexX;		// bottom left of first triangle

			IndexList[ArrayIndex+3]=(IndexY*BitmapWidth)+IndexX;			// top left of 2nd triangle

			IndexList[ArrayIndex+4]=(IndexY*BitmapWidth)+(IndexX+1);		// top right of 2nd triangle

			IndexList[ArrayIndex+5]=((IndexY+1)*BitmapWidth)+(IndexX+1);		// bottom right of 2nd triangle

			ArrayIndex=ArrayIndex+6;						// increments 6 index's since we just used up 6

		}
	}
  
And Rendering the Primitives...
  

	for(int Count=0;Count<BitmapWidth;Count++) 
	{ 
		r = g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, BitmapWidth*2, Count*(6*(BitmapWidth-1)), (BitmapWidth-1)*2 ); 
		if(FAILED(r))
		{
			char	TempChar[5];
			fprintf(outfile, "\n");fprintf(outfile,"\n");
			fprintf(outfile,"Error Drawing Primitives, settings are: \n");
			fprintf(outfile,"NumVertices: ");_itoa(BitmapWidth*2, TempChar, 10);fprintf(outfile, TempChar);fprintf(outfile,"\n");
			fprintf(outfile,"Starting Index in list: ");_itoa(int(Count*(6*(BitmapWidth-1))),TempChar, 10);fprintf(outfile, TempChar);fprintf(outfile,"\n");
			fprintf(outfile,"NumPrimitives to draw: ");_itoa((BitmapWidth-1)*2,TempChar,10);fprintf(outfile, TempChar);fprintf(outfile, "\n");
		}
	} 
  
Finnally my output file with states of variables at runtime and at fail times.
Number of Vertices: 100 Number of Primitives: 162
Bitmap Width: 10 Bitmap Height: 10
Index Contents:
 0 11 10 0 1 11 1 12 11 1 2 12 2 13 12 2 3 13 3 14 13 3 4 14 4 15 14 4 5 15 5 16 15 5 6 16 6 17 16 6 7 17
 7 18 17 7 8 18 8 19 18 8 9 19 10 21 20 10 11 21 11 22 21 11 12 22 12 23 22 12 13 23 13 24 23 13 14 24 
 14 25 24 14 15 25 15 26 25 15 16 26 16 27 26 16 17 27 17 28 27 17 18 28 18 29 28 18 19 29 20 31 30 20 21 31
 21 32 31 21 22 32 22 33 32 22 23 33 23 34 33 23 24 34 24 35 34 24 25 35 25 36 35 25 26 36 26 37 36 26 27 37
 27 38 37 27 28 38 28 39 38 28 29 39 30 41 40 30 31 41 31 42 41 31 32 42 32 43 42 32 33 43 33 44 43 33 34 44
 34 45 44 34 35 45 35 46 45 35 36 46 36 47 46 36 37 47 37 48 47 37 38 48 38 49 48 38 39 49 40 51 50 40 41 51
 41 52 51 41 42 52 42 53 52 42 43 53 43 54 53 43 44 54 44 55 54 44 45 55 45 56 55 45 46 56 46 57 56 46 47 57
 47 58 57 47 48 58 48 59 58 48 49 59 50 61 60 50 51 61 51 62 61 51 52 62 52 63 62 52 53 63 53 64 63 53 54 64
 54 65 64 54 55 65 55 66 65 55 56 66 56 67 66 56 57 67 57 68 67 57 58 68 58 69 68 58 59 69 60 71 70 60 61 71
 61 72 71 61 62 72 62 73 72 62 63 73 63 74 73 63 64 74 64 75 74 64 65 75 65 76 75 65 66 76 66 77 76 66 67 77
 67 78 77 67 68 78 68 79 78 68 69 79 70 81 80 70 71 81 71 82 81 71 72 82 72 83 82 72 73 83 73 84 83 73 74 84
 74 85 84 74 75 85 75 86 85 75 76 86 76 87 86 76 77 87 77 88 87 77 78 88 78 89 88 78 79 89 80 91 90 80 81 91
 81 92 91 81 82 92 82 93 92 82 83 93 83 94 93 83 84 94 84 95 94 84 85 95 85 96 95 85 86 96 86 97 96 86 87 97
 87 98 97 87 88 98 88 99 98 88 89 99 
number of Indices = 486
Vertext Contents:
-5,0,5 -4,0,5 -3,0,5 -2,0,5 -1,0,5 0,0,5 1,0,5 2,0,5 3,0,5 4,0,5 -5,0,4 -4,0,4 -3,0,4 -2,0,4 -1,0,4 0,0,4 1,0,4 2,0,4 3,0,4
 4,0,4 -5,0,3 -4,0,3 -3,0,3 -2,0,3 -1,0,3 0,0,3 1,0,3 2,0,3 3,0,3 4,0,3 -5,0,2 -4,0,2 -3,0,2 -2,0,2 -1,0,2 0,0,2 1,0,2 2,0,2
 3,0,2 4,0,2 -5,0,1 -4,0,1 -3,0,1 -2,0,1 -1,0,1 0,0,1 1,0,1 2,0,1 3,0,1 4,0,1 -5,0,0 -4,0,0 -3,0,0 -2,0,0 -1,0,0 0,0,0 1,0,0
 2,0,0 3,0,0 4,0,0 -5,0,-1 -4,0,-1 -3,0,-1 -2,0,-1 -1,0,-1 0,0,-1 1,0,-1 2,0,-1 3,0,-1 4,0,-1 -5,0,-2 -4,0,-2 -3,0,-2 -2,0,-2
 -1,0,-2 0,0,-2 1,0,-2 2,0,-2 3,0,-2 4,0,-2 -5,0,-3 -4,0,-3 -3,0,-3 -2,0,-3 -1,0,-3 0,0,-3 1,0,-3 2,0,-3 3,0,-3 4,0,-3 -5,0,-4
 -4,0,-4 -3,0,-4 -2,0,-4 -1,0,-4 0,0,-4 1,0,-4 2,0,-4 3,0,-4 4,0,-4 
Number of Vert's = 100

Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 54
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 108
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 162
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 216
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 270
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 324
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 378
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 432
NumPrimitives to draw: 18


Error Drawing Primitives, settings are: 
NumVertices: 20
Starting Index in list: 486
NumPrimitives to draw: 18

Closing...
 
[edited by - TalonSnow on February 19, 2003 11:27:52 PM]
<=- Talon -=>
TalonSnow
TalonSnow
Ok, found one major problem that fixed some of the invalid index in index stream fails. It seems it was bad documentation, where the 2nd parameter in the DrawIndexedPrimitive is called Number of Vertices, and I thought it meant number of vertices being used, but it is acully the TOTAL AMOUNT of vertices being used (so number of indices really)
so.. I switch (BitmapWidth*2) to (BitmapWidth-1)*6

this took care of the first 3 error messages from starting index 54 up to 216.

So i still have errors from 216-432
not sure what changes from from 162 to 216 though

also... Took care of last error message at 486 as my for loop on my DrawIndexedPrimitive was suppose to loop BitmapHeight-1 times not BitmapHeight times.
<=- Talon -=>
TalonSnow
TalonSnow
ok, I thought NumVertices = Number of vertices being used that call, however this is wrong.

I got it working perfectly, by putting NumVertices = BitmapHeight * BitmapWidth until I try to put in an bitmap that put''s the vertex count to high, which then it freezes the application. Which is a bitmap around 256*256.

anyone shed some more light on how NumVertices specifically works?
<=- Talon -=>

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.