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

Drawing a decal

Started by Sfpiano Dec 31, 2003 at 7:26 PM 2 replies 550+ views
Original Post
Sfpiano
Sfpiano
I''m trying to add a decal texture on top of my terrain but am running into some difficulties. I tried simply using this code:
pDevice->SetTexture(1, p_BulletTex);
		pDevice->SetStreamSource(1, pBulletVB, 0, sizeof(TERRAINVERTEX));
		pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
 
but as you can imagine it didn''t work. I keep reading about multi-texturing, but everything I''ve come across involves blending two textures together, which isn''t what I want. //------------------------------------------------------------------------------------------------------ The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you''re the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
curtmax_0
curtmax_0
You don''t have to use modulate to blend textures together... you can use an add operation.... that would probably be better for a decal...
Sfpiano
Sfpiano
Hmm, ok I''ll look into that. But I''ve been thinking that the way I''ve conceived it, everytime I want to add a decal, or a different type of decal, I need a new vertex buffer, and a new stream source, and a new texture. There has to be a better way of doing this; can I avoid this using stencil buffers?
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."
Sfpiano
Sfpiano
From what I''ve read stencil buffers seem like a good way to render decals; the problem is I''m confused on how to set them up. The way I have it set up is this: turn off z, turn on stencil, then set up stencil buffer:

pDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS );
pDevice->SetRenderState( D3DRS_STENCILZFAIL, D3DSTENCILOP_KEEP );

// If ztest passes, inc/decrement stencil buffer value
pDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
pDevice->SetRenderState( D3DRS_STENCILMASK, 0xffffffff );
pDevice->SetRenderState( D3DRS_STENCILWRITEMASK, 0xffffffff );
pDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_INCR );


Then I render the data which contains the vertex coorinates for the decal. After that I set up texture stages and do this:

pDevice->SetRenderState( D3DRS_STENCILREF, 0x1 );
pDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_LESSEQUAL );
pDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );


and then render the decal data. I really haven''t found any good explanations of the code behind stencil buffering, and am basically just throwing SDK code around and crossing my fingers. :-|
//------------------------------------------------------------------------------------------------------The great logician Bertrand Russell once claimed that he could prove anything if given that 1+1=1. So one day, some fool asked him, "Ok. Prove that you're the Pope." He thought for a while and proclaimed, "I am one. The Pope is one. Therefore, the Pope and I are one."

Topic Locked

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

Sign in to reply to this topic.