Changing textures with a switch statement *solved*

Started by
1 comment, last by Calin 18 years, 6 months ago
I am trying to make some buttons for my app. Each button is a textured poly made out of 2 triangles. When the user clicks on the poly the texture should change (imitating a press of a button). I can`t make my code work right. Here is what I use:

        pDevice->SetStreamSource(0, MenuVB, 0, sizeof(SIMPLETEXMAPVERTEX));
	
	// Tell D3D we want to use our custom FVF define
	pDevice->SetFVF(FVF_SIMPLETEXMAPVERTEX);

	
//-----
	switch (Bt1.Down)
	{
	case 1: pDevice->SetTexture(0,Bt1.ButtonTxrB );
		break;
	case 0: pDevice->SetTexture(0,Bt1.ButtonTxrA );
	    break;
	}
	
	pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	
//-----
	switch (Bt2.Down)
	{
	case 1: pDevice->SetTexture(0,Bt2.ButtonTxrB );
		break;
	case 0: pDevice->SetTexture(0,Bt2.ButtonTxrA );
	    break;
	}
	pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 2, 2);
	
	
//-----
  
	switch (Bt3.Down)
	{
	case 1: pDevice->SetTexture(0,Bt3.ButtonTxrB );
		break;
	case 0: pDevice->SetTexture(0,Bt3.ButtonTxrA );
	    break;
	}
	pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2);
	  
	
	 
//-----
	switch (Bt4.Down)
	{
	case 1: pDevice->SetTexture(0,Bt4.ButtonTxrB );
		break;
	case 0: pDevice->SetTexture(0,Bt4.ButtonTxrA );
	    break;
	}
	pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 6, 2);





With this code I should have displayed four buttons that change their appearance when you click on them. Right now all I get is a button that changes it`s texture when I click on it and another that doesn`t change it`t texture. Can anyone help me with this code? [Edited by - Calin on September 23, 2005 5:18:15 AM]

My project`s facebook page is “DreamLand Page”

Advertisement




Check your vertice counts and vertex positions.

I forget how many D3DPT_TRIANGLESTRIP uses and Microsofts docs suck:


StartVertex
[in] Index of the first vertex to load. Beginning at StartVertex the correct number of vertices will be read out of the vertex buffer.

PrimitiveCount
[in] Number of primitives to render. The maximum number of primitives allowed is determined by checking the MaxPrimitiveCount member of the D3DCAPS9 structure. PrimitiveCount is the number of primitives as determined by the primitive type. If it is a line list, each primitive has two vertices. If it is a triangle list, each primitive has three vertices.


It doesnt say what count should be for triangleSTRIPS (I forget if it adds+2 automatically) and your StartVertex should probably be in groups of 4 instead of pairs like you have for the 4 buttons.

0 4 8 12...
Thank you for pointing out the mistake. For some reason I was counting the number of triangles instead that of the vertices. Everything works fine now.

My project`s facebook page is “DreamLand Page”

This topic is closed to new replies.

Advertisement