Jump to content
  • Advertisement
Sign in to follow this  
coolscene

two questions need help: recover from COLOROP, and SetTexture before rendering

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

hi. I have two questions need help. I use Direct3D to draw to graphics on the same surface. one is in the upper half, the other is in the lower half. the upper half one, before I render, I used two textures (g_pTexture1 ,g_pTexture2) to do color-op (which is what I needed), then when I render the lower half(g_pTexture3) , I found the graphics also color-op-ed, which is not what I wanted. How to disable the effectiveness cause by the color-op of the upper half graphics, so I can correctly draw out the lower half graphics? here is the code snippet:
Quote:
void MyClass::Color-Op() { g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,true); g_pd3dDevice->SetTexture( 0, g_pTexture1 ); g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,0x80000000); g_pd3dDevice->SetTextureStageState(0,D3DTSS_TEXCOORDINDEX,0); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG1); g_pd3dDevice->SetTexture( 1, g_pTexture2 ); g_pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,0x80000000); g_pd3dDevice->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,0); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG1,D3DTA_TEXTURE); g_pd3dDevice->SetTextureStageState(1,D3DTSS_COLORARG2,D3DTA_CURRENT); g_pd3dDevice->SetTextureStageSta(1,D3DTSS_COLOROP,D3DTOP_BLENDFACTORALPHA); g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE,false); }
here is the render function:
Quote:
void MyClass::InitializeVertex() { //...... Color-Op(); //...... } void MyClass::Render() g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,0), 1.0f, 0 ); if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // now draw the uppper graphics g_pd3dDevice->SetTexture(0,g_pTexture2); (1) g_pd3dDevice->SetStreamSource( 0, g_pVB_upper, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 ); Disable_Color_Op(); (2) g_pd3dDevice->SetTexture(0,m_pTexture3); g_pd3dDevice->SetStreamSource(0,g_pVB_lower,0,sizeof(SQUARE_CUSTOMVERTEX)); g_pd3dDevice->SetFVF(D3DFVF_SQUAREVERTEX); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2); g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
my two problems are: 1. my Color-Op() function is used in the vertex intialize phase. then when I used fixed pipeline to draw. I have to SetTexture to set texture for uppper graphics and lower graphics respectively before rendering. so I used (1) above. my hunch told me, this might not right, since I should get the color-op result of g_pTexture1 and g_pTexture2 to draw. but if not this (1); How to write one to achieve? 2. because I used Color-Op(), the second rendering come out a texture mixed with g_pTexture1 and g_pTexture2 , this is not right , I know this is caused by Color-Op() because if I delete this function, no mixed any more, but then the first rendering not right so I finger if I write a function to get rid of the effect by Color-Op(), i call it Disable_Color_Op(), then after both rendered, I can reuse Color-Op(). but How to write this Disable_Color_Op()? I know Color-Op() just set some states, but I don't know how to write. Conclude my questions: if (1) is right for me? if not how? How to write something in (2)? I am new to this directX thing. please help. thank you very much!

Share this post


Link to post
Share on other sites
Advertisement
First of all, it's important to remember to set the stage after the one you use to 'disable'. For example, in your Color-Op function, use

g_pd3dDevice->SetTextureStageState(2,D3DTSS_COLOROP,D3DTOP_DISABLE);

This way when you set texture stages, there won't be any leftover operations from higher stages.

The default operation is to modulate the texture and diffuse colour. You can restore these texture stages to "disable colour op".

Also remember to use

g_pd3dDevice->SetTextureStageState(1,D3DTSS_TEXCOORDINDEX,1);

to set the texcoord index back to its default value.

As for other problems in your code, relating to your question (1):

You should set the texture stages before you draw, and not only once (unless you always draw with the same stages). In Direct3D the last thing you set is what will remain from that point on. Since "disabling" your colour op is simply replacing it with other texture stages, you will need to set it again when you next want to use it.

As for line (1), why do you set g_pTexture2 there? In Color-Op you're setting g_pTexture1 to stage 0 and g_pTexture2 to stage 1, which would blend them. Then you're setting g_pTexture2 to stage 0, so when you're actually drawing, you're trying to blend g_pTexture2 with itself.

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!