Advertisement Jump to content
Sign in to follow this  

Does order of "set..." calls to device matter?

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

Hello all, I have been having some very strange results when trying to draw a scene with both filled/textured triangle-composed objects together with objects composed of lines. For example, I'm trying to draw my bounding cube around my model. The cube is just a bunch of line-connected vertices which hold a color and a position, drawn by the "DrawIndexedPrimitve() command. But the cube only shows up in my second viewport( I have two viewports, split screen ). Everything else shows up in both viewports, including all of the textured meshes/terrain, and even the normals ( which I also draw with lines ). The only thing I've been able to figure out, is that it has something to do with the "SetTexture()" call in my Model's render section. If I REMOVE the SetTexture call in the Model's render section ( which is the last rendering done before the cube gets rendered ), then the cube doesn't show up in EITHER viewport. I'm thinking that maybe I'm making some device calls in a funny order, because since my intent is just to draw the cube's lines with the color values at the vertices, the texture shouldn't have anything to do with it. I'll post the cube's render section and the model's render section here. Please let me know if you have any ideas, or need more information. Cube:
//No texture has been set
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COL ORARG2, D3DTA_CURRENT);

	//Select vertex buffer
	m_pd3dDevice->SetStreamSource(0, m_pVertexBuffer, 0, sizeof(CRVertex));
	m_pd3dDevice->SetFVF( D3DFVF_CRVERTEX );
	//Select index buffer

	//Turn off lighting

	//Draw the primitives
	m_pd3dDevice->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, m_iVertTotalCount, 0, 12);
//A texture has been set. We want our texture to be shaded based
	//on the current light levels, so used D3DTOP_MODULATE.
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	m_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);

	//Turn on lighting

	for (DWORD i=0; i<numMaterials; i++)

		// Set the material and texture for this subset
		// Draw the mesh subset
		mesh->DrawSubset( i );

Share this post

Link to post
Share on other sites
Heh. In case anyone was wondering about this ( doubtful ;) ...

I figured it out. If you notice, I was using D3DTS_SELECTARG2 when drawing my cube made from lines. I was under the impression that when you set arg2 to D3DTS_CURRENT, it used whatever color value existed already. This is clearly not quite the case. What I needed to do was to use D3DTOP_DISABLE instead, and now the line-cube renders properly.

Is there a detailed site anywhere about where you would want to use all of the different kinds of values you can set in SetTextureStageState() ? The one at toymaker is OK, but I kinda had to figure this one out on my own...


Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!