Jump to content
  • Advertisement
Sign in to follow this  
Calin

Changing textures with a switch statement *solved*

This topic is 4746 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 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]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster




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...

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!