• Draw material to screen and set it's aplha
    1 replies, posted
So, I need some help. Been trying for the past 2 hours to draw a material to the screen and set it's alpha through the program, as it has to change based on a set of conditions. I am using [CODE]surface.DrawTexturedRect()[/CODE] I tried setting it's color with [CODE]surface.SetDrawColor()[/CODE] but setting the alpha value to something doesn't help. I also tried modifying the material's "$alpha" flag, but that achieves nothing. Please help!
This isn't a very good solution, but you could have two separate materials (possibly as PNG files) - one with the transparency and one without. You could then layer the one with no transparency on top of the transparent one, and then change the opacity of it so it reveals the one underneath. I don't know of a better way to do this, but some more context may help. What I mean: [CODE] local opacity = 50 -- change this to whatever local img1 = Material( 'opaqueimage.png' ) -- image with no transparency local img2 = Material( 'transparentimage.png' ) -- image with transparency hook.Add( "HUDPaint", "bad solution", function() surface.SetDrawColor( 255, 255, 255, opacity ) surface.SetMaterial( img1 ) surface.DrawTexturedRect( 0, 0, 500, 500 ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( img2 ) surface.DrawTexturedRect( 0, 0, 500, 500 ) end ) [/CODE] [editline]17th May 2017[/editline] I may have misread your question. If you want to simply make an image transparent, then surface.SetDrawColor should work. If you want to change the actual alpha to be visible or invisible while keeping the transparency normal, the code above should work.
Sorry, you need to Log In to post a reply to this thread.