# how to make it transparent?

This topic is 5470 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

in my project i cann see now landscape, objects and my menu. i have light and textures... i want to make my menu transparent to give it more quality... but i dont figured out how to.... here is the codesnippet of my rendering call:
public overridable sub render(device as Direct3D.Device )
dim Mat	as direct3d.Material
'---------------------------------------------
mat.Ambient=color.White
mat.Diffuse=color.White
mat.Specular=color.White
device.Material=mat

device.RenderState.AlphaBlendEnable = True
device.RenderState.SourceBlend =  Blend.SourceAlpha
device.RenderState.DestinationBlend = Blend.InvSourceAlpha

device.SetStreamSource(0, myVertexBuf, 0)
device.VertexFormat=CustomVertex.TransformedTextured.Format
device.SetTexture(0, myTex)

device.drawPrimitives(PrimitiveType.TriangleStrip, 0, 2)

End Sub


is it ok to define a material or is it of no need. how and where i can define a transparency level? with the sub like above it looks like this: screenie 130kb thx for all help

##### Share on other sites
Well, first off I would not use the predefined colors, IMHO. I'd use D3DColorMake or something similar.

That way, I could say something like:
mat.diffuse = D3DColorMake(r, g, b, a)

and specify the alpha value with a, to achieve a transparency; right now the material you're using has no alpha value = no transparency. So add an alpha value!

--Don't forget to disable alpha blending or testing when you're done with it.

For more information, search the SDK for "color" or "alpha blending", or post another question in this thread.

##### Share on other sites
yes, alpha value... i have tested this one:

mat.Diffuse=color.FromArgb(100,system.Drawing.Color.White)

but it makes no differenz.
i can do transparent objects, loaded from a .x file
when i try to create one "selfdefined" with .drawprimitives it dont work...
i must have forgotten some essential thing....

##### Share on other sites
why don't you try
mat.diffuse = D3DColorMake(50,50,50,50)

It will make it transparent if there is an alpha value, since its obviously set up right if it renders mesh transparencies fine. Ergo, you have no alpha value set. Use the above code, if that doesn't work, then gripe at me.

And you could always just set it through the vertex diffuse color if you think there's something wrong with the material. Print the alpha diffuse of the material with debug and post it. I'm curious to see what it is... :P

##### Share on other sites
ok i played with the params here is what i got

screenie

as you see it is transparent... but there seems to be no difference between setting material.diffuse.A(lpha) to zero or max

always the same transparency
here is the code:
	public overridable sub render(device as Direct3D.Device )	dim Mat	as direct3d.Material		'here i set the diffuse alpha and color----------------------------------		mat.Diffuse=color.FromArgb( 128,128,128,128)		device.Material=mat				'now the strange render and texture states---------------------------------		device.RenderState.SourceBlend = Blend.SourceColor		device.RenderState.DestinationBlend =  Blend.DestinationColor		device.RenderState.AlphaBlendEnable = True		device.TextureState(0).AlphaOperation =TextureOperation.MultiplyAdd		device.TextureState(0).AlphaArgument1=TextureArgument.TextureColor		device.TextureState(0).AlphaArgument2=TextureArgument.Diffuse				if me.Visible then			device.SetStreamSource(0, vb, 0)			device.VertexFormat = CustomVertex.TransformedTextured.Format			device.SetTexture(0, Tex1)			device.drawPrimitives(PrimitiveType.TriangleStrip, 0, 2)			'render Text after texture			drawingfont.DrawText( captionPos.X,captionPos.Y, System.Drawing.Color.Yellow,Caption,GraphicsFont.RenderFlags.Filtered)		end if				device.RenderState.AlphaBlendEnable = False	End Sub

i have tested a loop who scrolls through the sourceblend and destinationblend values. that makes some strange blendings but nothing i call "normal transparent" and.. the most interesting for me: why does the alphavalue no effect to this process?

@Mushu
i debuged the mat.diffuse.a value... it is as i set it: 128

there must be some importent i have dont set, because alpha is ignored.

device.VertexFormat = CustomVertex.TransformedTextured.Format
is this ok or should it be device.VertexFormat = CustomVertex.TransformedColoredTextured.Format??

[Edited by - Freakdesign on September 26, 2004 1:07:33 PM]

##### Share on other sites
I don't know much of the IDE you're using, but you said:

device.VertexFormat = CustomVertex.TransformedTextured.Format
is this ok or should it be device.VertexFormat = CustomVertex.TransformedColoredTextured.Format??

I think you are on to something there. The vertex format should have color and texture if you are going to modulate that in the texture stage. i.e. to set the alpha blend argument to DIFFUSE means that it will use the diffuse color argument from the vertex...therefore one must exist in the vertex declaration.

Chris

##### Share on other sites
Jaahooooo!!! Solved!!!
Thanks to all who posted.

for real transparency it is a MUST to declare:

CustomVertex.TransformedColoredTextured.Format

then.... the vertex color have to be white. other colors change the texturecolor. ALPHA value is for transparency:
dim a as ColorValue = new ColorValue(255,255,255,200)
dim col as Integer=a.ToArgb()

Renderstates have to be:
device.RenderState.SourceBlend=Blend.SourceAlpha
device.RenderState.DestinationBlend=Blend.InvSourceAlpha
device.RenderState.AlphaBlendEnable = True

device.TextureState(0).AlphaOperation=TextureOperation.Modulate
device.TextureState(0).AlphaArgument1=TextureArgument.TextureColor
device.TextureState(0).AlphaArgument2=TextureArgument.Diffuse

here is a screenie
clickme

dup di dudel dumm, dadel daaa dudidupidoo
*happy hacking*

PS: Gamedev is the only site i know where i really can get help
Thx to the GameDev Masters

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 15
• 22
• 16
• 13
• 14